Skip to content

Commit 59a6f10

Browse files
icemacCopilot
andauthored
Fix package lookup to use buildout working set instead of importlib.metadata (#14)
* Fix package lookup to use buildout working set instead of importlib.metadata importlib.metadata.distribution() only finds packages installed in sys.path, not eggs managed by buildout. This causes a PackageNotFoundError when the recipe tries to resolve packages that buildout has resolved but not yet installed into the environment. Revert to using the buildout working set and pkg_resources to find package distributions and their extras, which correctly resolves eggs through buildout's egg resolution mechanism. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 059ecc5 commit 59a6f10

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
4.2 (unreleased)
66
================
77

8-
- Nothing changed yet.
8+
- Revert replacement of ``pkg_resources`` with ``importlib.metadata`` in
9+
``recipe.py`` as ``importlib.metadata.distribution()`` cannot find packages
10+
managed by buildout.
911

1012

1113
4.1 (2026-04-17)

src/z3c/recipe/compattest/recipe.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import importlib.metadata
21
import os
32
import re
43

4+
import pkg_resources
5+
56
import zc.buildout.easy_install
67
import zc.recipe.egg
78
import zc.recipe.testrunner
@@ -52,16 +53,14 @@ def update(self):
5253
def _install_testrunners(self, wanted_packages):
5354
installed = []
5455
for package_name in wanted_packages:
55-
dist = importlib.metadata.distribution(package_name)
56+
ws = self._working_set(package_name)
57+
package = ws.find(pkg_resources.Requirement.parse(package_name))
5658
# Installing arbitrary extras here leads to problems in
5759
# reproducibility.
5860
# In particular, setuptools[tests] causes a huge dependency tree
5961
# to be brought in.
6062
extras = '[{}]'.format(
61-
','.join(
62-
ex for ex in
63-
(dist.metadata.get_all('Provides-Extra') or [])
64-
if ex in ['test']))
63+
','.join(ex for ex in package.extras if ex in ['test']))
6564
if package_name == 'zc.buildout':
6665
# Installing the test dependencies for zc.buildout is also a
6766
# problem, they don't all provide test extras

0 commit comments

Comments
 (0)