Skip to content

Commit 1983ef0

Browse files
committed
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.
1 parent e6414d6 commit 1983ef0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

news/9944.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Emit clearer error message when a project root does not contain either
2+
``pyproject.toml``, ``setup.py`` or ``setup.cfg``.

src/pip/_internal/req/req_install.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,32 @@ def load_pyproject_toml(self):
509509
self.unpacked_source_directory, backend, backend_path=backend_path,
510510
)
511511

512+
def _check_setup_py_or_cfg_exists(self) -> bool:
513+
"""Check if the requirement actually has a setuptools build file.
514+
515+
If setup.py does not exist, we also check setup.cfg in the same
516+
directory and allow the directory if that exists.
517+
"""
518+
if os.path.exists(self.setup_py_path):
519+
return True
520+
stem, ext = os.path.splitext(self.setup_py_path)
521+
if ext == ".py" and os.path.exists(f"{stem}.cfg"):
522+
return True
523+
return False
524+
512525
def _generate_metadata(self):
513526
# type: () -> str
514527
"""Invokes metadata generator functions, with the required arguments.
515528
"""
516529
if not self.use_pep517:
517530
assert self.unpacked_source_directory
518531

532+
if not self._check_setup_py_or_cfg_exists():
533+
raise InstallationError(
534+
f'File "setup.py" or "setup.cfg" not found for legacy '
535+
f'project {self}.'
536+
)
537+
519538
return generate_metadata_legacy(
520539
build_env=self.build_env,
521540
setup_py_path=self.setup_py_path,

0 commit comments

Comments
 (0)