Skip to content

Commit 23f2d12

Browse files
KOLANICHuranusjr
andcommitted
Fixed --editable install for setuptools projects without setup.py.
Co-Authored-By: Tzu-ping Chung <[email protected]>
1 parent 743d8fd commit 23f2d12

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

Diff for: news/9547.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed the bug preventing the use of --editable installs for setup.cfg-only setuptools-based projects.

Diff for: src/pip/_internal/req/constructors.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,19 @@ def parse_editable(editable_req):
7777
url_no_extras, extras = _strip_extras(url)
7878

7979
if os.path.isdir(url_no_extras):
80-
if not os.path.exists(os.path.join(url_no_extras, 'setup.py')):
80+
setup_py = os.path.join(url_no_extras, 'setup.py')
81+
setup_cfg = os.path.join(url_no_extras, 'setup.cfg')
82+
if not os.path.exists(setup_py) and not os.path.exists(setup_cfg):
8183
msg = (
82-
'File "setup.py" not found. Directory cannot be installed '
83-
'in editable mode: {}'.format(os.path.abspath(url_no_extras))
84+
'File "setup.py" or "setup.cfg" not found. Directory cannot be '
85+
'installed in editable mode: {}'
86+
.format(os.path.abspath(url_no_extras))
8487
)
8588
pyproject_path = make_pyproject_path(url_no_extras)
8689
if os.path.isfile(pyproject_path):
8790
msg += (
8891
'\n(A "pyproject.toml" file was found, but editable '
89-
'mode currently requires a setup.py based build.)'
92+
'mode currently requires a setuptools-based build.)'
9093
)
9194
raise InstallationError(msg)
9295

Diff for: src/pip/_internal/utils/setuptools_build.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
# invoking via the shim. This avoids e.g. the following manifest_maker
99
# warning: "warning: manifest_maker: standard file '-c' not found".
1010
_SETUPTOOLS_SHIM = (
11-
"import sys, setuptools, tokenize; sys.argv[0] = {0!r}; __file__={0!r};"
12-
"f=getattr(tokenize, 'open', open)(__file__);"
13-
"code=f.read().replace('\\r\\n', '\\n');"
11+
"import io, os, sys, setuptools, tokenize; sys.argv[0] = {0!r}; __file__={0!r};"
12+
"f = getattr(tokenize, 'open', open)(__file__) "
13+
"if os.path.exists(__file__) "
14+
"else io.StringIO('from setuptools import setup; setup()');"
15+
"code = f.read().replace('\\r\\n', '\\n');"
1416
"f.close();"
1517
"exec(compile(code, __file__, 'exec'))"
1618
)

Diff for: tests/functional/test_install.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -1034,15 +1034,13 @@ def test_install_package_with_prefix(script, data):
10341034
result.did_create(install_path)
10351035

10361036

1037-
def test_install_editable_with_prefix(script):
1037+
def _test_install_editable_with_prefix(script, files):
10381038
# make a dummy project
10391039
pkga_path = script.scratch_path / 'pkga'
10401040
pkga_path.mkdir()
1041-
pkga_path.joinpath("setup.py").write_text(textwrap.dedent("""
1042-
from setuptools import setup
1043-
setup(name='pkga',
1044-
version='0.1')
1045-
"""))
1041+
1042+
for fn, contents in files.items():
1043+
pkga_path.joinpath(fn).write_text(textwrap.dedent(contents))
10461044

10471045
if hasattr(sys, "pypy_version_info"):
10481046
site_packages = os.path.join(
@@ -1065,6 +1063,28 @@ def test_install_editable_with_prefix(script):
10651063
result.did_create(install_path)
10661064

10671065

1066+
def test_install_editable_with_prefix_setup_py(script):
1067+
setup_py = """
1068+
from setuptools import setup
1069+
setup(name='pkga', version='0.1')
1070+
"""
1071+
_test_install_editable_with_prefix(script, {"setup.py": setup_py})
1072+
1073+
1074+
def test_install_editable_with_prefix_setup_cfg(script):
1075+
setup_cfg = """[metadata]
1076+
name = pkga
1077+
version = 0.1
1078+
"""
1079+
pyproject_toml = """[build-system]
1080+
requires = ["setuptools", "wheel"]
1081+
build-backend = "setuptools.build_meta"
1082+
"""
1083+
_test_install_editable_with_prefix(
1084+
script, {"setup.cfg": setup_cfg, "pyproject.toml": pyproject_toml}
1085+
)
1086+
1087+
10681088
def test_install_package_conflict_prefix_and_user(script, data):
10691089
"""
10701090
Test installing a package using pip install --prefix --user errors out

0 commit comments

Comments
 (0)