summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2022-08-12 19:41:13 +0100
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2022-08-12 19:41:13 +0100
commitd7f5704cbc8e739fe6144402a6c2ed45e38cd6c0 (patch)
tree78f7c93ef7dee574442adf3be3336fb1f854fd6a /setuptools
parente4dd4bdd923cfc2f69dd4cfbb119644bb46e5e9d (diff)
parentc380214475ebbd3e93d15ebcfc0bd691f6c2e5a0 (diff)
downloadpython-setuptools-git-d7f5704cbc8e739fe6144402a6c2ed45e38cd6c0.tar.gz
Fix other problems with editable installs (#3517)
1. Ensure commands are finalized, to ensure plat_name is set. 2. Filter out temporary source files and prevent setuptools for attempting to consider them as part of the data_files/package_data list
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/command/build_py.py33
-rw-r--r--setuptools/command/editable_wheel.py7
-rw-r--r--setuptools/tests/test_editable_install.py31
3 files changed, 55 insertions, 16 deletions
diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py
index 8b1a3320..ec062742 100644
--- a/setuptools/command/build_py.py
+++ b/setuptools/command/build_py.py
@@ -184,7 +184,7 @@ class build_py(orig.build_py):
files = ei_cmd.filelist.files
check = _IncludePackageDataAbuse()
- for path in _filter_absolute_egg_info(files, egg_info_dir):
+ for path in self._filter_build_files(files, egg_info_dir):
d, f = os.path.split(assert_relative(path))
prev = None
oldf = f
@@ -202,6 +202,25 @@ class build_py(orig.build_py):
check.warn(importable)
mf.setdefault(src_dirs[d], []).append(path)
+ def _filter_build_files(self, files: Iterable[str], egg_info: str) -> Iterator[str]:
+ """
+ ``build_meta`` may try to create egg_info outside of the project directory,
+ and this can be problematic for certain plugins (reported in issue #3500).
+
+ Extensions might also include between their sources files created on the
+ ``build_lib`` and ``build_temp`` directories.
+
+ This function should filter this case of invalid files out.
+ """
+ build = self.get_finalized_command("build")
+ build_dirs = (egg_info, self.build_lib, build.build_temp, build.build_base)
+ norm_dirs = [os.path.normpath(p) for p in build_dirs if p]
+
+ for file in files:
+ norm_path = os.path.normpath(file)
+ if not os.path.isabs(file) or all(d not in norm_path for d in norm_dirs):
+ yield file
+
def get_data_files(self):
pass # Lazily compute data files in _get_data_files() function.
@@ -347,15 +366,3 @@ class _IncludePackageDataAbuse:
msg = textwrap.dedent(self.MESSAGE).format(importable=importable)
warnings.warn(msg, SetuptoolsDeprecationWarning, stacklevel=2)
self._already_warned.add(importable)
-
-
-def _filter_absolute_egg_info(files: Iterable[str], egg_info: str) -> Iterator[str]:
- """
- ``build_meta`` may try to create egg_info outside of the project directory,
- and this can be problematic for certain plugins (reported in issue #3500).
- This function should filter this case of invalid files out.
- """
- egg_info_name = Path(egg_info).name
- for file in files:
- if not (egg_info_name in file and os.path.isabs(file)):
- yield file
diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py
index 2631a082..560efebd 100644
--- a/setuptools/command/editable_wheel.py
+++ b/setuptools/command/editable_wheel.py
@@ -133,7 +133,8 @@ class editable_wheel(Command):
self._ensure_dist_info()
# Add missing dist_info files
- bdist_wheel = self.reinitialize_command("bdist_wheel")
+ self.reinitialize_command("bdist_wheel")
+ bdist_wheel = self.get_finalized_command("bdist_wheel")
bdist_wheel.write_wheelfile(self.dist_info_dir)
self._create_wheel_file(bdist_wheel)
@@ -156,7 +157,7 @@ class editable_wheel(Command):
if self.dist_info_dir is None:
dist_info = self.reinitialize_command("dist_info")
dist_info.output_dir = self.dist_dir
- dist_info.finalize_options()
+ dist_info.ensure_finalized()
dist_info.run()
self.dist_info_dir = dist_info.dist_info_dir
else:
@@ -278,7 +279,7 @@ class editable_wheel(Command):
# Also remove _safely_run, TestCustomBuildPy. Suggested date: Aug/2023.
build: Command = self.get_finalized_command("build")
for name in build.get_sub_commands():
- cmd = self.distribution.get_command_obj(name)
+ cmd = self.get_finalized_command(name)
if name == "build_py" and type(cmd) != build_py_cls:
self._safely_run(name)
else:
diff --git a/setuptools/tests/test_editable_install.py b/setuptools/tests/test_editable_install.py
index 67d377ef..900ec1b3 100644
--- a/setuptools/tests/test_editable_install.py
+++ b/setuptools/tests/test_editable_install.py
@@ -25,6 +25,7 @@ from setuptools.command.editable_wheel import (
_find_namespaces,
_find_package_roots,
_finder_template,
+ editable_wheel,
)
from setuptools.dist import Distribution
@@ -846,6 +847,36 @@ class TestCustomBuildPy:
assert b"42" in out
+class TestCustomBuildWheel:
+ def install_custom_build_wheel(self, dist):
+ bdist_wheel_cls = dist.get_command_class("bdist_wheel")
+
+ class MyBdistWheel(bdist_wheel_cls):
+ def get_tag(self):
+ # In issue #3513, we can see that some extensions may try to access
+ # the `plat_name` property in bdist_wheel
+ if self.plat_name.startswith("macosx-"):
+ _ = "macOS platform"
+ return super().get_tag()
+
+ dist.cmdclass["bdist_wheel"] = MyBdistWheel
+
+ def test_access_plat_name(self, tmpdir_cwd):
+ # Even when a custom bdist_wheel tries to access plat_name the build should
+ # be successful
+ jaraco.path.build({"module.py": "x = 42"})
+ dist = Distribution()
+ dist.script_name = "setup.py"
+ dist.set_defaults()
+ self.install_custom_build_wheel(dist)
+ cmd = editable_wheel(dist)
+ cmd.ensure_finalized()
+ cmd.run()
+ wheel_file = str(next(Path().glob('dist/*')))
+ assert "editable" in wheel_file
+ assert wheel_file.endswith(".whl")
+
+
def install_project(name, venv, tmp_path, files, *opts):
project = tmp_path / name
project.mkdir()