Skip to content

Commit d8933c5

Browse files
authored
Merge pull request pypa#4630 from pypa/bugfix/4615
Restore support for pathlib paths in build_base
2 parents 7ee29bd + a07de2b commit d8933c5

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

newsfragments/4615.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed TypeError in sdist filelist processing by adding support for pathlib Paths for the build_base.

setuptools/_distutils/_msvccompiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def _get_vc_env(plat_spec):
159159
stderr=subprocess.STDOUT,
160160
).decode('utf-16le', errors='replace')
161161
except subprocess.CalledProcessError as exc:
162-
log.error(exc.output)
162+
log.error(exc.output) # noqa: RUF100, TRY400
163163
raise DistutilsPlatformError(f"Error executing {exc.cmd}")
164164

165165
env = {

setuptools/_distutils/command/sdist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def prune_file_list(self):
391391
build = self.get_finalized_command('build')
392392
base_dir = self.distribution.get_fullname()
393393

394-
self.filelist.exclude_pattern(None, prefix=build.build_base)
394+
self.filelist.exclude_pattern(None, prefix=os.fspath(build.build_base))
395395
self.filelist.exclude_pattern(None, prefix=base_dir)
396396

397397
if sys.platform == 'win32':

setuptools/_distutils/tests/test_msvccompiler.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,19 @@
1414

1515

1616
class Testmsvccompiler(support.TempdirManager):
17-
def test_no_compiler(self):
17+
def test_no_compiler(self, monkeypatch):
1818
# makes sure query_vcvarsall raises
1919
# a DistutilsPlatformError if the compiler
2020
# is not found
2121
def _find_vcvarsall(plat_spec):
2222
return None, None
2323

24-
old_find_vcvarsall = _msvccompiler._find_vcvarsall
25-
_msvccompiler._find_vcvarsall = _find_vcvarsall
26-
try:
27-
with pytest.raises(DistutilsPlatformError):
28-
_msvccompiler._get_vc_env(
29-
'wont find this version',
30-
)
31-
finally:
32-
_msvccompiler._find_vcvarsall = old_find_vcvarsall
24+
monkeypatch.setattr(_msvccompiler, '_find_vcvarsall', _find_vcvarsall)
25+
26+
with pytest.raises(DistutilsPlatformError):
27+
_msvccompiler._get_vc_env(
28+
'wont find this version',
29+
)
3330

3431
@needs_winreg
3532
def test_get_vc_env_unicode(self):

setuptools/tests/test_sdist.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io
55
import logging
66
import os
7+
import pathlib
78
import sys
89
import tarfile
910
import tempfile
@@ -822,6 +823,21 @@ def get_source_files(self):
822823
manifest = cmd.filelist.files
823824
assert '.myfile~' in manifest
824825

826+
@pytest.mark.skipif("os.environ.get('SETUPTOOLS_USE_DISTUTILS') == 'stdlib'")
827+
def test_build_base_pathlib(self, source_dir):
828+
"""
829+
Ensure if build_base is a pathlib.Path, the build still succeeds.
830+
"""
831+
dist = Distribution({
832+
**SETUP_ATTRS,
833+
"script_name": "setup.py",
834+
"options": {"build": {"build_base": pathlib.Path('build')}},
835+
})
836+
cmd = sdist(dist)
837+
cmd.ensure_finalized()
838+
with quiet():
839+
cmd.run()
840+
825841

826842
def test_default_revctrl():
827843
"""

0 commit comments

Comments
 (0)