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 diff --git a/setuptools/_distutils/_msvccompiler.py b/setuptools/_distutils/_msvccompiler.py index e7652218d8..03653929a8 100644 --- a/setuptools/_distutils/_msvccompiler.py +++ b/setuptools/_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 = { diff --git a/setuptools/_distutils/command/sdist.py b/setuptools/_distutils/command/sdist.py index e8abb73920..eda6afe811 100644 --- a/setuptools/_distutils/command/sdist.py +++ b/setuptools/_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': diff --git a/setuptools/_distutils/tests/test_msvccompiler.py b/setuptools/_distutils/tests/test_msvccompiler.py index 23b6c732c3..71129cae27 100644 --- a/setuptools/_distutils/tests/test_msvccompiler.py +++ b/setuptools/_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): diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index f628f3eb4a..30347190db 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.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. + """ + 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(): """