Skip to content

Commit bc68a60

Browse files
committed
Fix build_meta when metadata_directory=='.' (#3528)
2 parents b5b195a + 01b8529 commit bc68a60

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

changelog.d/3528.misc.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed ``buid_meta.prepare_metadata_for_build_wheel`` when
2+
given ``metadata_directory`` is ``"."``.

setuptools/build_meta.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import setuptools
4242
import distutils
43+
from . import errors
4344
from ._path import same_path
4445
from ._reqs import parse_strings
4546
from ._deprecation_warning import SetuptoolsDeprecationWarning
@@ -346,16 +347,23 @@ def _bubble_up_info_directory(self, metadata_directory: str, suffix: str) -> str
346347
347348
Returns the basename of the info directory, e.g. `proj-0.0.0.dist-info`.
348349
"""
349-
candidates = list(Path(metadata_directory).glob(f"**/*{suffix}/"))
350-
assert len(candidates) == 1, f"Exactly one {suffix} should have been produced"
351-
info_dir = candidates[0]
352-
350+
info_dir = self._find_info_directory(metadata_directory, suffix)
353351
if not same_path(info_dir.parent, metadata_directory):
354352
shutil.move(str(info_dir), metadata_directory)
355353
# PEP 517 allow other files and dirs to exist in metadata_directory
356-
357354
return info_dir.name
358355

356+
def _find_info_directory(self, metadata_directory: str, suffix: str) -> Path:
357+
for parent, dirs, _ in os.walk(metadata_directory):
358+
candidates = [f for f in dirs if f.endswith(suffix)]
359+
360+
if len(candidates) != 0 or len(dirs) != 1:
361+
assert len(candidates) == 1, f"Multiple {suffix} directories found"
362+
return Path(parent, candidates[0])
363+
364+
msg = f"No {suffix} directory found in {metadata_directory}"
365+
raise errors.InternalError(msg)
366+
359367
def prepare_metadata_for_build_wheel(self, metadata_directory,
360368
config_settings=None):
361369
sys.argv = [

setuptools/tests/test_build_meta.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,23 @@ def test_prepare_metadata_for_build_wheel(self, build_backend):
485485

486486
assert os.path.isfile(os.path.join(dist_dir, dist_info, 'METADATA'))
487487

488+
def test_prepare_metadata_inplace(self, build_backend):
489+
"""
490+
Some users might pass metadata_directory pre-populated with `.tox` or `.venv`.
491+
See issue #3523.
492+
"""
493+
for pre_existing in [
494+
".tox/python/lib/python3.10/site-packages/attrs-22.1.0.dist-info",
495+
".tox/python/lib/python3.10/site-packages/autocommand-2.2.1.dist-info",
496+
".nox/python/lib/python3.10/site-packages/build-0.8.0.dist-info",
497+
".venv/python3.10/site-packages/click-8.1.3.dist-info",
498+
"venv/python3.10/site-packages/distlib-0.3.5.dist-info",
499+
"env/python3.10/site-packages/docutils-0.19.dist-info",
500+
]:
501+
os.makedirs(pre_existing, exist_ok=True)
502+
dist_info = build_backend.prepare_metadata_for_build_wheel(".")
503+
assert os.path.isfile(os.path.join(dist_info, 'METADATA'))
504+
488505
def test_build_sdist_explicit_dist(self, build_backend):
489506
# explicitly specifying the dist folder should work
490507
# the folder sdist_directory and the ``--dist-dir`` can be the same

0 commit comments

Comments
 (0)