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/3] 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/3] 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/3] 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':