Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better diagnose when setup.py/cfg cannot be found #9945

Merged
merged 2 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/9944.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Emit clearer error message when a project root does not contain either
``pyproject.toml``, ``setup.py`` or ``setup.cfg``.
19 changes: 19 additions & 0 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,32 @@ def load_pyproject_toml(self):
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.
"""
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,
Expand Down
16 changes: 6 additions & 10 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,14 @@ def tabulate(rows):
return table, sizes


def is_installable_dir(path):
# type: (str) -> bool
"""Is path is a directory containing setup.py or pyproject.toml?"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't allow setup.cfg only before.

def is_installable_dir(path: str) -> bool:
"""Is path is a directory containing pyproject.toml, setup.cfg or setup.py?"""
if not os.path.isdir(path):
return False
setup_py = os.path.join(path, "setup.py")
if os.path.isfile(setup_py):
return True
pyproject_toml = os.path.join(path, "pyproject.toml")
if os.path.isfile(pyproject_toml):
return True
return False
return any(
os.path.isfile(os.path.join(path, signifier))
for signifier in ("pyproject.toml", "setup.cfg", "setup.py")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a logic change! before setup.cfg only didn't pass this check, now it does.

)


def read_chunks(file, size=io.DEFAULT_BUFFER_SIZE):
Expand Down