Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 659ce45

Browse filesBrowse files
committed
BLD: use patched bdist_wheel
bdist_wheel currently has a bug when it works with namespaced packages (e.g. all python packages are in lib). The replacement bdist_wheel.run() method implments the patch from https://bitbucket.org/pypa/wheel/issues/91/cannot-create-a-file-when-that-file
1 parent d53f902 commit 659ce45
Copy full SHA for 659ce45

File tree

Expand file treeCollapse file tree

2 files changed

+115
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+115
-0
lines changed

‎patched_bdist_wheel.py

Copy file name to clipboard
+103Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"""
2+
Workaround until https://bitbucket.org/pypa/wheel/issues/91/cannot-create-a-file-when-that-file
3+
is fixed...
4+
5+
Only one small patch in the os.name == nt case:
6+
- basedir_observed = os.path.join(self.data_dir, '..')
7+
+ basedir_observed = os.path.join(self.data_dir, '..', '.')
8+
"""
9+
10+
from wheel.bdist_wheel import bdist_wheel
11+
from distutils.sysconfig import get_python_version
12+
from distutils import log as logger
13+
from wheel.archive import archive_wheelfile
14+
import subprocess
15+
import os
16+
from shutil import rmtree
17+
18+
class patched_bdist_wheel(bdist_wheel):
19+
20+
def run(self):
21+
build_scripts = self.reinitialize_command('build_scripts')
22+
build_scripts.executable = 'python'
23+
24+
if not self.skip_build:
25+
self.run_command('build')
26+
27+
install = self.reinitialize_command('install',
28+
reinit_subcommands=True)
29+
install.root = self.bdist_dir
30+
install.compile = False
31+
install.skip_build = self.skip_build
32+
install.warn_dir = False
33+
34+
# A wheel without setuptools scripts is more cross-platform.
35+
# Use the (undocumented) `no_ep` option to setuptools'
36+
# install_scripts command to avoid creating entry point scripts.
37+
install_scripts = self.reinitialize_command('install_scripts')
38+
install_scripts.no_ep = True
39+
40+
# Use a custom scheme for the archive, because we have to decide
41+
# at installation time which scheme to use.
42+
for key in ('headers', 'scripts', 'data', 'purelib', 'platlib'):
43+
setattr(install,
44+
'install_' + key,
45+
os.path.join(self.data_dir, key))
46+
47+
basedir_observed = ''
48+
49+
if os.name == 'nt':
50+
# win32 barfs if any of these are ''; could be '.'?
51+
# (distutils.command.install:change_roots bug)
52+
# PATCHED...
53+
basedir_observed = os.path.join(self.data_dir, '..', '.')
54+
self.install_libbase = self.install_lib = basedir_observed
55+
56+
setattr(install,
57+
'install_purelib' if self.root_is_pure else 'install_platlib',
58+
basedir_observed)
59+
60+
logger.info("installing to %s", self.bdist_dir)
61+
62+
self.run_command('install')
63+
64+
archive_basename = self.get_archive_basename()
65+
66+
pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
67+
if not self.relative:
68+
archive_root = self.bdist_dir
69+
else:
70+
archive_root = os.path.join(
71+
self.bdist_dir,
72+
self._ensure_relative(install.install_base))
73+
74+
self.set_undefined_options(
75+
'install_egg_info', ('target', 'egginfo_dir'))
76+
self.distinfo_dir = os.path.join(self.bdist_dir,
77+
'%s.dist-info' % self.wheel_dist_name)
78+
self.egg2dist(self.egginfo_dir,
79+
self.distinfo_dir)
80+
81+
self.write_wheelfile(self.distinfo_dir)
82+
83+
self.write_record(self.bdist_dir, self.distinfo_dir)
84+
85+
# Make the archive
86+
if not os.path.exists(self.dist_dir):
87+
os.makedirs(self.dist_dir)
88+
wheel_name = archive_wheelfile(pseudoinstall_root, archive_root)
89+
90+
# Sign the archive
91+
if 'WHEEL_TOOL' in os.environ:
92+
subprocess.call([os.environ['WHEEL_TOOL'], 'sign', wheel_name])
93+
94+
# Add to 'Distribution.dist_files' so that the "upload" command works
95+
getattr(self.distribution, 'dist_files', []).append(
96+
('bdist_wheel', get_python_version(), wheel_name))
97+
98+
if not self.keep_temp:
99+
if self.dry_run:
100+
logger.info('removing %s', self.bdist_dir)
101+
else:
102+
rmtree(self.bdist_dir)
103+

‎setup.py

Copy file name to clipboardExpand all lines: setup.py
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,18 @@ def run(self):
253253
cmdclass['test'] = NoseTestCommand
254254
cmdclass['build_ext'] = BuildExtraLibraries
255255

256+
# patch bdist_wheel for a bug on windows
257+
# https://bitbucket.org/pypa/wheel/issues/91/cannot-create-a-file-when-that-file
258+
if os.name == 'nt':
259+
try:
260+
from wheel.bdist_wheel import bdist_wheel
261+
except ImportError:
262+
# No wheel installed, so we also can't run that command...
263+
pass
264+
else:
265+
# patched_bdist_wheel has a run() method, which works on windows
266+
from patched_bdist_wheel import patched_bdist_wheel
267+
cmdclass['bdist_wheel'] = patched_bdist_wheel
256268

257269
# One doesn't normally see `if __name__ == '__main__'` blocks in a setup.py,
258270
# however, this is needed on Windows to avoid creating infinite subprocesses

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.