Better diagnose when setup.py/cfg cannot be found

This adds a check before invoking 'egg_info' to make sure either setup.py or
setup.cfg actually exists, and emit a clearer error message when neither can
be found and the egg_info command can never succeed.
This commit is contained in:
Tzu-ping Chung 2021-05-04 16:50:52 +08:00 committed by Stéphane Bidoul
parent 5b5288435b
commit 06d65a0327
No known key found for this signature in database
GPG Key ID: BCAB2555446B5B92
2 changed files with 21 additions and 0 deletions

2
news/9944.bugfix.rst Normal file
View File

@ -0,0 +1,2 @@
Emit clearer error message when a project root does not contain either
``pyproject.toml``, ``setup.py`` or ``setup.cfg``.

View File

@ -509,6 +509,19 @@ class InstallRequirement:
self.unpacked_source_directory, backend, backend_path=backend_path,
)
def _check_setup_py_or_cfg_exists(self) -> bool:
"""Check if the requirement actually has a setuptools build file.
If setup.py does not exist, we also check setup.cfg in the same
directory and allow the directory if that exists.
"""
if os.path.exists(self.setup_py_path):
return True
stem, ext = os.path.splitext(self.setup_py_path)
if ext == ".py" and os.path.exists(f"{stem}.cfg"):
return True
return False
def _generate_metadata(self):
# type: () -> str
"""Invokes metadata generator functions, with the required arguments.
@ -516,6 +529,12 @@ class InstallRequirement:
if not self.use_pep517:
assert self.unpacked_source_directory
if not self._check_setup_py_or_cfg_exists():
raise InstallationError(
f'File "setup.py" or "setup.cfg" not found for legacy '
f'project {self}.'
)
return generate_metadata_legacy(
build_env=self.build_env,
setup_py_path=self.setup_py_path,