Skip to content

Commit

Permalink
Reject project that have neither a pyproject.toml nor a setup.py
Browse files Browse the repository at this point in the history
Before it sometimes errored out.
  • Loading branch information
sbidoul committed Oct 3, 2021
1 parent 413f20a commit 1ce9fba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/pip/_internal/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ def load_pyproject_toml(
has_pyproject = os.path.isfile(pyproject_toml)
has_setup = os.path.isfile(setup_py)

if not has_pyproject and not has_setup:
raise InstallationError(
f"{req_name} does not appear to be a Python project: "
f"no pyproject.toml or setup.py"
)

if has_pyproject:
with open(pyproject_toml, encoding="utf-8") as f:
pp_toml = tomli.load(f)
Expand Down
8 changes: 1 addition & 7 deletions src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from pip._internal.req.req_file import ParsedRequirement
from pip._internal.req.req_install import InstallRequirement
from pip._internal.utils.filetypes import is_archive_file
from pip._internal.utils.misc import is_installable_dir
from pip._internal.utils.urls import path_to_url
from pip._internal.vcs import is_url, vcs

Expand Down Expand Up @@ -232,12 +231,7 @@ def _get_url_from_path(path: str, name: str) -> Optional[str]:
an @, it will treat it as a PEP 440 URL requirement and return the path.
"""
if _looks_like_path(name) and os.path.isdir(path):
if is_installable_dir(path):
return path_to_url(path)
raise InstallationError(
f"Directory {name!r} is not installable. Neither 'setup.py' "
"nor 'pyproject.toml' found."
)
return path_to_url(path)
if not is_archive_file(path):
return None
if os.path.isfile(path):
Expand Down

0 comments on commit 1ce9fba

Please sign in to comment.