Skip to content

Commit

Permalink
Avoid iterating over entry-points while an empty .egg-info exists i…
Browse files Browse the repository at this point in the history
…n `sys.path` (#4680)
  • Loading branch information
abravalheri authored Oct 15, 2024
2 parents f8a2825 + 28677ae commit edf39d4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
run: |
rm -rf dist
# workaround for pypa/setuptools#4333
pipx run --pip-args 'pyproject-hooks<1.1' build
pipx run --pip-args 'pyproject-hooks!=1.1' build
echo "PRE_BUILT_SETUPTOOLS_SDIST=$(ls dist/*.tar.gz)" >> $GITHUB_ENV
echo "PRE_BUILT_SETUPTOOLS_WHEEL=$(ls dist/*.whl)" >> $GITHUB_ENV
rm -rf setuptools.egg-info # Avoid interfering with the other tests
Expand Down
4 changes: 4 additions & 0 deletions newsfragments/4680.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Changed ``egg_info`` command to avoid adding an empty ``.egg-info`` while
iterating over entry-points is available in ``sys.path``.
This avoids triggering integration problems with ``importlib.metadata``/``importlib_metadata``
(reference: pypa/pyproject-hooks#206).
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test = [
"pytest-subprocess",

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

"jaraco.test",
]
Expand Down
6 changes: 5 additions & 1 deletion setuptools/command/egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,17 @@ def delete_file(self, filename):
os.unlink(filename)

def run(self):
# Pre-load to avoid iterating over entry-points while an empty .egg-info
# exists in sys.path. See pypa/pyproject-hooks#206
writers = list(metadata.entry_points(group='egg_info.writers'))

self.mkpath(self.egg_info)
try:
os.utime(self.egg_info, None)
except OSError as e:
msg = f"Cannot update time stamp of directory '{self.egg_info}'"
raise distutils.errors.DistutilsFileError(msg) from e
for ep in metadata.entry_points(group='egg_info.writers'):
for ep in writers:
writer = ep.load()
writer(self, ep.name, os.path.join(self.egg_info, ep.name))

Expand Down

0 comments on commit edf39d4

Please sign in to comment.