Skip to content

Commit edf39d4

Browse files
authored
Avoid iterating over entry-points while an empty .egg-info exists in sys.path (#4680)
2 parents f8a2825 + 28677ae commit edf39d4

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
run: |
101101
rm -rf dist
102102
# workaround for pypa/setuptools#4333
103-
pipx run --pip-args 'pyproject-hooks<1.1' build
103+
pipx run --pip-args 'pyproject-hooks!=1.1' build
104104
echo "PRE_BUILT_SETUPTOOLS_SDIST=$(ls dist/*.tar.gz)" >> $GITHUB_ENV
105105
echo "PRE_BUILT_SETUPTOOLS_WHEEL=$(ls dist/*.whl)" >> $GITHUB_ENV
106106
rm -rf setuptools.egg-info # Avoid interfering with the other tests

newsfragments/4680.bugfix.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Changed ``egg_info`` command to avoid adding an empty ``.egg-info`` while
2+
iterating over entry-points is available in ``sys.path``.
3+
This avoids triggering integration problems with ``importlib.metadata``/``importlib_metadata``
4+
(reference: pypa/pyproject-hooks#206).

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test = [
5757
"pytest-subprocess",
5858

5959
# workaround for pypa/pyproject-hooks#206
60-
"pyproject-hooks<1.1", # TODO: fix problem with egg-info, see #4670
60+
"pyproject-hooks!=1.1",
6161

6262
"jaraco.test",
6363
]

setuptools/command/egg_info.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,17 @@ def delete_file(self, filename):
293293
os.unlink(filename)
294294

295295
def run(self):
296+
# Pre-load to avoid iterating over entry-points while an empty .egg-info
297+
# exists in sys.path. See pypa/pyproject-hooks#206
298+
writers = list(metadata.entry_points(group='egg_info.writers'))
299+
296300
self.mkpath(self.egg_info)
297301
try:
298302
os.utime(self.egg_info, None)
299303
except OSError as e:
300304
msg = f"Cannot update time stamp of directory '{self.egg_info}'"
301305
raise distutils.errors.DistutilsFileError(msg) from e
302-
for ep in metadata.entry_points(group='egg_info.writers'):
306+
for ep in writers:
303307
writer = ep.load()
304308
writer(self, ep.name, os.path.join(self.egg_info, ep.name))
305309

0 commit comments

Comments
 (0)