From 6864167a0f5cc95c258383314816046a2e877dfa Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 2 Sep 2024 18:21:47 -0400 Subject: [PATCH 1/7] Use monkeypatch to monkeypatch. --- distutils/tests/test_msvccompiler.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/distutils/tests/test_msvccompiler.py b/distutils/tests/test_msvccompiler.py index 23b6c732c3..71129cae27 100644 --- a/distutils/tests/test_msvccompiler.py +++ b/distutils/tests/test_msvccompiler.py @@ -14,22 +14,19 @@ class Testmsvccompiler(support.TempdirManager): - def test_no_compiler(self): + def test_no_compiler(self, monkeypatch): # makes sure query_vcvarsall raises # a DistutilsPlatformError if the compiler # is not found def _find_vcvarsall(plat_spec): return None, None - old_find_vcvarsall = _msvccompiler._find_vcvarsall - _msvccompiler._find_vcvarsall = _find_vcvarsall - try: - with pytest.raises(DistutilsPlatformError): - _msvccompiler._get_vc_env( - 'wont find this version', - ) - finally: - _msvccompiler._find_vcvarsall = old_find_vcvarsall + monkeypatch.setattr(_msvccompiler, '_find_vcvarsall', _find_vcvarsall) + + with pytest.raises(DistutilsPlatformError): + _msvccompiler._get_vc_env( + 'wont find this version', + ) @needs_winreg def test_get_vc_env_unicode(self): From 971074d4a2f6e222cdbc43ce881586412c7ab8a1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 2 Sep 2024 18:38:49 -0400 Subject: [PATCH 2/7] Disable TRY400 so it doesn't cause problems in other branches. Disable RUF100 to prevent it from failing in this branch. Ref pypa/distutils#292 --- distutils/_msvccompiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distutils/_msvccompiler.py b/distutils/_msvccompiler.py index e7652218d8..03653929a8 100644 --- a/distutils/_msvccompiler.py +++ b/distutils/_msvccompiler.py @@ -159,7 +159,7 @@ def _get_vc_env(plat_spec): stderr=subprocess.STDOUT, ).decode('utf-16le', errors='replace') except subprocess.CalledProcessError as exc: - log.error(exc.output) + log.error(exc.output) # noqa: RUF100, TRY400 raise DistutilsPlatformError(f"Error executing {exc.cmd}") env = { From 91bc99ac821731fc8b594d38c0b5500f8da0819f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 3 Sep 2024 09:18:27 -0400 Subject: [PATCH 3/7] In sdist.prune_file_list, support build.build_base as a pathlib.Path. Closes pypa/setuptools#4615 --- distutils/command/sdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distutils/command/sdist.py b/distutils/command/sdist.py index e8abb73920..eda6afe811 100644 --- a/distutils/command/sdist.py +++ b/distutils/command/sdist.py @@ -391,7 +391,7 @@ def prune_file_list(self): build = self.get_finalized_command('build') base_dir = self.distribution.get_fullname() - self.filelist.exclude_pattern(None, prefix=build.build_base) + self.filelist.exclude_pattern(None, prefix=os.fspath(build.build_base)) self.filelist.exclude_pattern(None, prefix=base_dir) if sys.platform == 'win32': From d901698dc01e18b4ebdb04e9a65df98883f7108b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 3 Sep 2024 09:11:37 -0400 Subject: [PATCH 4/7] Add test capturing missed expectation. Ref #4615 --- setuptools/tests/test_sdist.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index f628f3eb4a..d0db9c8d6f 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -4,6 +4,7 @@ import io import logging import os +import pathlib import sys import tarfile import tempfile @@ -822,6 +823,21 @@ def get_source_files(self): manifest = cmd.filelist.files assert '.myfile~' in manifest + @pytest.mark.xfail(reason="4615") + def test_build_base_pathlib(self, source_dir): + """ + Ensure if build_base is a pathlib.Path, the build still succeeds. + """ + dist = Distribution({ + **SETUP_ATTRS, + "script_name": "setup.py", + "options": {"build": {"build_base": pathlib.Path('build')}}, + }) + cmd = sdist(dist) + cmd.ensure_finalized() + with quiet(): + cmd.run() + def test_default_revctrl(): """ From 9d4b288a2643df4872036d06d6b14f933db8cebc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 3 Sep 2024 09:28:44 -0400 Subject: [PATCH 5/7] Enable the test --- setuptools/tests/test_sdist.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index d0db9c8d6f..be48ce2c7e 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -823,7 +823,6 @@ def get_source_files(self): manifest = cmd.filelist.files assert '.myfile~' in manifest - @pytest.mark.xfail(reason="4615") def test_build_base_pathlib(self, source_dir): """ Ensure if build_base is a pathlib.Path, the build still succeeds. From 6bf20d96aaeb3bce0d24a45198be4c9bf286a6b4 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 3 Sep 2024 09:30:04 -0400 Subject: [PATCH 6/7] Add news fragment. --- newsfragments/4615.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/4615.bugfix.rst diff --git a/newsfragments/4615.bugfix.rst b/newsfragments/4615.bugfix.rst new file mode 100644 index 0000000000..e121f2dbca --- /dev/null +++ b/newsfragments/4615.bugfix.rst @@ -0,0 +1 @@ +Fixed TypeError in sdist filelist processing by adding support for pathlib Paths for the build_base. \ No newline at end of file From a07de2b9364d5aa618c78c3ad60312963abfa7ba Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 3 Sep 2024 14:01:34 -0400 Subject: [PATCH 7/7] Skip test on stdlib distutils --- setuptools/tests/test_sdist.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index be48ce2c7e..30347190db 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -823,6 +823,7 @@ def get_source_files(self): manifest = cmd.filelist.files assert '.myfile~' in manifest + @pytest.mark.skipif("os.environ.get('SETUPTOOLS_USE_DISTUTILS') == 'stdlib'") def test_build_base_pathlib(self, source_dir): """ Ensure if build_base is a pathlib.Path, the build still succeeds.