Skip to content

Commit

Permalink
Merge pull request #4630 from pypa/bugfix/4615
Browse files Browse the repository at this point in the history
Restore support for pathlib paths in build_base
  • Loading branch information
jaraco committed Sep 3, 2024
2 parents 7ee29bd + a07de2b commit d8933c5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions newsfragments/4615.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed TypeError in sdist filelist processing by adding support for pathlib Paths for the build_base.
2 changes: 1 addition & 1 deletion setuptools/_distutils/_msvccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion setuptools/_distutils/command/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
17 changes: 7 additions & 10 deletions setuptools/_distutils/tests/test_msvccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 16 additions & 0 deletions setuptools/tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io
import logging
import os
import pathlib
import sys
import tarfile
import tempfile
Expand Down Expand Up @@ -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():
"""
Expand Down

0 comments on commit d8933c5

Please sign in to comment.