Skip to content

Commit

Permalink
Problem: running with different pythons fails C extensions
Browse files Browse the repository at this point in the history
This happens when installing packages with C extensions that do not have
the proper binary wheel available.

Solution: append platform to the name of egg directories
to work around a bug in pkg_resources that fails to parse
python version if platform is missing
  • Loading branch information
gotcha committed Sep 29, 2021
1 parent 063acbe commit 479ee91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions news/574.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix confusion when using multiple Python versions and
installing packages with C extensions
without proper binary wheel available.
14 changes: 9 additions & 5 deletions src/zc/buildout/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,17 +1745,21 @@ def make_egg_after_pip_install(dest, distinfo_dir):

# Make properly named new egg dir
distro = list(pkg_resources.find_distributions(dest))[0]
egg_name = distro.egg_name() + '.egg'
base = "{}-{}".format(
distro.egg_name(), pkg_resources.get_supported_platform()
)
egg_name = base + '.egg'
new_distinfo_dir = base + '.dist-info'
egg_dir = os.path.join(dest, egg_name)
os.mkdir(egg_dir)

# Move ".dist-info" dir into new egg dir
os.rename(
os.path.join(dest, distinfo_dir),
os.path.join(egg_dir, distinfo_dir)
os.path.join(egg_dir, new_distinfo_dir)
)

with open(os.path.join(egg_dir, distinfo_dir, 'top_level.txt')) as f:
with open(os.path.join(egg_dir, new_distinfo_dir, 'top_level.txt')) as f:
top_levels = filter(
(lambda x: len(x) != 0),
[line.strip() for line in f.readlines()]
Expand All @@ -1778,10 +1782,10 @@ def make_egg_after_pip_install(dest, distinfo_dir):
continue

if PY3:
with open(os.path.join(egg_dir, distinfo_dir, 'RECORD'), newline='') as f:
with open(os.path.join(egg_dir, new_distinfo_dir, 'RECORD'), newline='') as f:
all_files = [row[0] for row in csv.reader(f)]
else:
with open(os.path.join(egg_dir, distinfo_dir, 'RECORD'), 'rb') as f:
with open(os.path.join(egg_dir, new_distinfo_dir, 'RECORD'), 'rb') as f:
all_files = [row[0] for row in csv.reader(f)]

# There might be some c extensions left over
Expand Down
2 changes: 1 addition & 1 deletion src/zc/buildout/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def _normalize_path(match):
re.compile(r'(\n?)- \S+\.pyc\n'), '\\1')

normalize_egg_py = (
re.compile(r'-py\d[.]\d+(-\S+)?.egg'),
re.compile(r'-py\d[.]\d+(-\S+)?\.egg'),
'-pyN.N.egg',
)

Expand Down

0 comments on commit 479ee91

Please sign in to comment.