Skip to content

Commit a2ff878

Browse files
committed
ENH: Extension should be able to accept PathLike sources objects
1 parent e651e53 commit a2ff878

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

distutils/extension.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Extension:
2626
name : string
2727
the full name of the extension, including any packages -- ie.
2828
*not* a filename or pathname, but Python dotted name
29-
sources : [string]
29+
sources : [string | os.PathLike]
3030
list of source filenames, relative to the distribution root
3131
(where the setup script lives), in Unix form (slash-separated)
3232
for portability. Source files may be C, C++, SWIG (.i),
@@ -106,8 +106,13 @@ def __init__(
106106
):
107107
if not isinstance(name, str):
108108
raise AssertionError("'name' must be a string")
109-
if not (isinstance(sources, list) and all(isinstance(v, str) for v in sources)):
110-
raise AssertionError("'sources' must be a list of strings")
109+
if not (
110+
isinstance(sources, list)
111+
and all(isinstance(v, (str, os.PathLike)) for v in sources)
112+
):
113+
raise AssertionError(
114+
"'sources' must be a list of strings or PathLike objects."
115+
)
111116

112117
self.name = name
113118
self.sources = sources

distutils/tests/test_extension.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import warnings
5+
from pathlib import Path
56

67
from distutils.extension import read_setup_file, Extension
78

@@ -68,13 +69,15 @@ def test_extension_init(self):
6869
assert ext.name == 'name'
6970

7071
# the second argument, which is the list of files, must
71-
# be a list of strings
72+
# be a list of strings or PathLike objects
7273
with pytest.raises(AssertionError):
7374
Extension('name', 'file')
7475
with pytest.raises(AssertionError):
7576
Extension('name', ['file', 1])
7677
ext = Extension('name', ['file1', 'file2'])
7778
assert ext.sources == ['file1', 'file2']
79+
ext = Extension('name', [Path('file1'), Path('file2')])
80+
assert ext.sources == ['file1', 'file2']
7881

7982
# others arguments have defaults
8083
for attr in (

0 commit comments

Comments
 (0)