Skip to content

Commit 10e5cb2

Browse files
committed
Better detection of invalid __legacy__ PEP 517 projects
This errors out on PEP 517 projects using the `setuptools.build_meta:__legacy__` backend but don't have a `setup.py`. This now errors out on: - `pip install file://$PWD` of an empty directory - `pip install file://$PWD` of directory with a pyproject.toml but no - `pip install file://$PWD` of directory with a pyproject.toml but no build-system table and no setup.py
1 parent 0fed2fd commit 10e5cb2

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/pip/_internal/pyproject.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,12 @@ def load_pyproject_toml(
174174
backend = "setuptools.build_meta:__legacy__"
175175
check = ["setuptools>=40.8.0", "wheel"]
176176

177+
if (
178+
build_system["build-backend"] == "setuptools.build_meta:__legacy__"
179+
and not has_setup
180+
):
181+
raise InstallationError(
182+
f"File 'setup.py' not found for legacy project {req_name}."
183+
)
184+
177185
return BuildSystemDetails(requires, backend, check, backend_path)

src/pip/_internal/req/constructors.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from pip._internal.req.req_file import ParsedRequirement
2626
from pip._internal.req.req_install import InstallRequirement
2727
from pip._internal.utils.filetypes import is_archive_file
28-
from pip._internal.utils.misc import is_installable_dir
2928
from pip._internal.utils.urls import path_to_url
3029
from pip._internal.vcs import is_url, vcs
3130

@@ -232,12 +231,7 @@ def _get_url_from_path(path: str, name: str) -> Optional[str]:
232231
an @, it will treat it as a PEP 440 URL requirement and return the path.
233232
"""
234233
if _looks_like_path(name) and os.path.isdir(path):
235-
if is_installable_dir(path):
236-
return path_to_url(path)
237-
raise InstallationError(
238-
f"Directory {name!r} is not installable. Neither 'setup.py' "
239-
"nor 'pyproject.toml' found."
240-
)
234+
return path_to_url(path)
241235
if not is_archive_file(path):
242236
return None
243237
if os.path.isfile(path):

0 commit comments

Comments
 (0)