46
46
47
47
from distutils .errors import DistutilsOptionError
48
48
49
- from .._path import same_path as _same_path
49
+ from .._path import same_path as _same_path , StrPath
50
50
from ..warnings import SetuptoolsWarning
51
51
52
52
if TYPE_CHECKING :
55
55
from distutils .dist import DistributionMetadata # noqa
56
56
57
57
chain_iter = chain .from_iterable
58
- _Path = Union [str , os .PathLike ]
59
58
_K = TypeVar ("_K" )
60
59
_V = TypeVar ("_V" , covariant = True )
61
60
@@ -88,7 +87,7 @@ def __getattr__(self, attr):
88
87
89
88
90
89
def glob_relative (
91
- patterns : Iterable [str ], root_dir : Optional [_Path ] = None
90
+ patterns : Iterable [str ], root_dir : Optional [StrPath ] = None
92
91
) -> List [str ]:
93
92
"""Expand the list of glob patterns, but preserving relative paths.
94
93
@@ -120,7 +119,7 @@ def glob_relative(
120
119
return expanded_values
121
120
122
121
123
- def read_files (filepaths : Union [str , bytes , Iterable [_Path ]], root_dir = None ) -> str :
122
+ def read_files (filepaths : Union [str , bytes , Iterable [StrPath ]], root_dir = None ) -> str :
124
123
"""Return the content of the files concatenated using ``\n `` as str
125
124
126
125
This function is sandboxed and won't reach anything outside ``root_dir``
@@ -138,20 +137,20 @@ def read_files(filepaths: Union[str, bytes, Iterable[_Path]], root_dir=None) ->
138
137
)
139
138
140
139
141
- def _filter_existing_files (filepaths : Iterable [_Path ]) -> Iterator [_Path ]:
140
+ def _filter_existing_files (filepaths : Iterable [StrPath ]) -> Iterator [StrPath ]:
142
141
for path in filepaths :
143
142
if os .path .isfile (path ):
144
143
yield path
145
144
else :
146
145
SetuptoolsWarning .emit (f"File { path !r} cannot be found" )
147
146
148
147
149
- def _read_file (filepath : Union [bytes , _Path ]) -> str :
148
+ def _read_file (filepath : Union [bytes , StrPath ]) -> str :
150
149
with open (filepath , encoding = 'utf-8' ) as f :
151
150
return f .read ()
152
151
153
152
154
- def _assert_local (filepath : _Path , root_dir : str ):
153
+ def _assert_local (filepath : StrPath , root_dir : str ):
155
154
if Path (os .path .abspath (root_dir )) not in Path (os .path .abspath (filepath )).parents :
156
155
msg = f"Cannot access { filepath !r} (or anything outside { root_dir !r} )"
157
156
raise DistutilsOptionError (msg )
@@ -162,7 +161,7 @@ def _assert_local(filepath: _Path, root_dir: str):
162
161
def read_attr (
163
162
attr_desc : str ,
164
163
package_dir : Optional [Mapping [str , str ]] = None ,
165
- root_dir : Optional [_Path ] = None ,
164
+ root_dir : Optional [StrPath ] = None ,
166
165
):
167
166
"""Reads the value of an attribute from a module.
168
167
@@ -197,7 +196,7 @@ def read_attr(
197
196
return getattr (module , attr_name )
198
197
199
198
200
- def _find_spec (module_name : str , module_path : Optional [_Path ]) -> ModuleSpec :
199
+ def _find_spec (module_name : str , module_path : Optional [StrPath ]) -> ModuleSpec :
201
200
spec = importlib .util .spec_from_file_location (module_name , module_path )
202
201
spec = spec or importlib .util .find_spec (module_name )
203
202
@@ -218,8 +217,8 @@ def _load_spec(spec: ModuleSpec, module_name: str) -> ModuleType:
218
217
219
218
220
219
def _find_module (
221
- module_name : str , package_dir : Optional [Mapping [str , str ]], root_dir : _Path
222
- ) -> Tuple [_Path , Optional [str ], str ]:
220
+ module_name : str , package_dir : Optional [Mapping [str , str ]], root_dir : StrPath
221
+ ) -> Tuple [StrPath , Optional [str ], str ]:
223
222
"""Given a module (that could normally be imported by ``module_name``
224
223
after the build is complete), find the path to the parent directory where
225
224
it is contained and the canonical name that could be used to import it
@@ -254,7 +253,7 @@ def _find_module(
254
253
def resolve_class (
255
254
qualified_class_name : str ,
256
255
package_dir : Optional [Mapping [str , str ]] = None ,
257
- root_dir : Optional [_Path ] = None ,
256
+ root_dir : Optional [StrPath ] = None ,
258
257
) -> Callable :
259
258
"""Given a qualified class name, return the associated class object"""
260
259
root_dir = root_dir or os .getcwd ()
@@ -270,7 +269,7 @@ def resolve_class(
270
269
def cmdclass (
271
270
values : Dict [str , str ],
272
271
package_dir : Optional [Mapping [str , str ]] = None ,
273
- root_dir : Optional [_Path ] = None ,
272
+ root_dir : Optional [StrPath ] = None ,
274
273
) -> Dict [str , Callable ]:
275
274
"""Given a dictionary mapping command names to strings for qualified class
276
275
names, apply :func:`resolve_class` to the dict values.
@@ -282,7 +281,7 @@ def find_packages(
282
281
* ,
283
282
namespaces = True ,
284
283
fill_package_dir : Optional [Dict [str , str ]] = None ,
285
- root_dir : Optional [_Path ] = None ,
284
+ root_dir : Optional [StrPath ] = None ,
286
285
** kwargs ,
287
286
) -> List [str ]:
288
287
"""Works similarly to :func:`setuptools.find_packages`, but with all
@@ -331,7 +330,7 @@ def find_packages(
331
330
return packages
332
331
333
332
334
- def _nest_path (parent : _Path , path : _Path ) -> str :
333
+ def _nest_path (parent : StrPath , path : StrPath ) -> str :
335
334
path = parent if path in {"." , "" } else os .path .join (parent , path )
336
335
return os .path .normpath (path )
337
336
@@ -361,7 +360,7 @@ def canonic_package_data(package_data: dict) -> dict:
361
360
362
361
363
362
def canonic_data_files (
364
- data_files : Union [list , dict ], root_dir : Optional [_Path ] = None
363
+ data_files : Union [list , dict ], root_dir : Optional [StrPath ] = None
365
364
) -> List [Tuple [str , List [str ]]]:
366
365
"""For compatibility with ``setup.py``, ``data_files`` should be a list
367
366
of pairs instead of a dict.
0 commit comments