Skip to content

Commit b5b195a

Browse files
committed
Fix editable compatibility with distutils' build_ext (#3526)
2 parents e6b9117 + 1772f6c commit b5b195a

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

changelog.d/3526.misc.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix backward compatibility of editable installs and custom ``build_ext``
2+
commands inheriting directly from ``distutils``.

setuptools/command/editable_wheel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ def _set_editable_mode(self):
237237
cmd = dist.get_command_obj(cmd_name)
238238
if hasattr(cmd, "editable_mode"):
239239
cmd.editable_mode = True
240+
elif hasattr(cmd, "inplace"):
241+
cmd.inplace = True # backward compatibility with distutils
240242

241243
def _collect_build_outputs(self) -> Tuple[List[str], Dict[str, str]]:
242244
files: List[str] = []

setuptools/tests/test_editable_install.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import platform
66
from copy import deepcopy
77
from importlib import import_module
8+
from importlib.machinery import EXTENSION_SUFFIXES
89
from pathlib import Path
910
from textwrap import dedent
1011
from unittest.mock import Mock
@@ -28,6 +29,7 @@
2829
editable_wheel,
2930
)
3031
from setuptools.dist import Distribution
32+
from setuptools.extension import Extension
3133

3234

3335
@pytest.fixture(params=["strict", "lenient"])
@@ -872,9 +874,40 @@ def test_access_plat_name(self, tmpdir_cwd):
872874
cmd = editable_wheel(dist)
873875
cmd.ensure_finalized()
874876
cmd.run()
875-
wheel_file = str(next(Path().glob('dist/*')))
877+
wheel_file = str(next(Path().glob('dist/*.whl')))
876878
assert "editable" in wheel_file
877-
assert wheel_file.endswith(".whl")
879+
880+
881+
class TestCustomBuildExt:
882+
def install_custom_build_ext_distutils(self, dist):
883+
from distutils.command.build_ext import build_ext as build_ext_cls
884+
885+
class MyBuildExt(build_ext_cls):
886+
pass
887+
888+
dist.cmdclass["build_ext"] = MyBuildExt
889+
890+
@pytest.mark.skipif(
891+
sys.platform != "linux", reason="compilers may fail without correct setup",
892+
)
893+
def test_distutils_leave_inplace_files(self, tmpdir_cwd):
894+
jaraco.path.build({"module.c": ""})
895+
attrs = {
896+
"ext_modules": [Extension("module", ["module.c"])],
897+
}
898+
dist = Distribution(attrs)
899+
dist.script_name = "setup.py"
900+
dist.set_defaults()
901+
self.install_custom_build_ext_distutils(dist)
902+
cmd = editable_wheel(dist)
903+
cmd.ensure_finalized()
904+
cmd.run()
905+
wheel_file = str(next(Path().glob('dist/*.whl')))
906+
assert "editable" in wheel_file
907+
files = [p for p in Path().glob("module.*") if p.suffix != ".c"]
908+
assert len(files) == 1
909+
name = files[0].name
910+
assert any(name.endswith(ext) for ext in EXTENSION_SUFFIXES)
878911

879912

880913
def install_project(name, venv, tmp_path, files, *opts):

0 commit comments

Comments
 (0)