Allow for pathlib objects in some sources.
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 62d2fee..852064f 100644 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py
@@ -14,6 +14,7 @@ import sys import time import collections +import pathlib from .._importlib import metadata from .. import _entry_points, _normalization @@ -414,7 +415,7 @@ """ found = False for i in range(len(self.files) - 1, -1, -1): - if predicate(self.files[i]): + if predicate(str(self.files[i])): self.debug_print(" removing " + self.files[i]) del self.files[i] found = True @@ -503,6 +504,9 @@ self.files = list(filter(self._safe_path, self.files)) def _safe_path(self, path): + if isinstance(path, pathlib.Path): + return self._safe_path_pathlib(path) + enc_warn = "'%s' not %s encodable -- skipping" # To avoid accidental trans-codings errors, first to unicode @@ -529,6 +533,12 @@ except UnicodeEncodeError: log.warn(enc_warn, path, sys.getfilesystemencoding()) + def _safe_path_pathlib(self, path): + is_egg_info = str(path).endswith('.egg-info') + if self.ignore_egg_info_dir and is_egg_info: + return False + return path.exists() + class manifest_maker(sdist): template = "MANIFEST.in"
diff --git a/setuptools/extension.py b/setuptools/extension.py index 58c023f..a151807 100644 --- a/setuptools/extension.py +++ b/setuptools/extension.py
@@ -1,5 +1,7 @@ import re import functools +import pathlib + import distutils.core import distutils.errors import distutils.extension @@ -141,7 +143,7 @@ lang = self.language or '' target_ext = '.cpp' if lang.lower() == 'c++' else '.c' sub = functools.partial(re.sub, '.pyx$', target_ext) - self.sources = list(map(sub, self.sources)) + self.sources = list(map(pathlib.Path, map(sub, map(str, self.sources)))) class Library(Extension):
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 5d59770..e23feda 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py
@@ -254,7 +254,7 @@ self.assert_package_data_in_manifest(cmd) manifest = cmd.filelist.files for path in EXTENSION_SOURCES: - assert path in manifest + assert str(path) in manifest for path in symlinked: assert path not in manifest
diff --git a/setuptools/unicode_utils.py b/setuptools/unicode_utils.py index d43dcc1..3ae2551 100644 --- a/setuptools/unicode_utils.py +++ b/setuptools/unicode_utils.py
@@ -1,3 +1,4 @@ +import pathlib import unicodedata import sys @@ -21,7 +22,7 @@ ``None`` when no expected encoding works """ - if isinstance(path, str): + if isinstance(path, (str, pathlib.Path)): return path fs_enc = sys.getfilesystemencoding() or 'utf-8'