Skip to content

Commit 427babb

Browse files
authored
Merge pull request #4865 from pypa/feature/distutils-5589d7527
Merge with distutils @ 5589d75
2 parents 7530d69 + 5cc2927 commit 427babb

33 files changed

+1010
-513
lines changed

newsfragments/4865.removal.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Synced with pypa/distutils@5589d7527 including a simplified shebang generation when building scripts (#4863).

setuptools/_distutils/_modified.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
"""Timestamp comparison of files and groups of files."""
22

3+
from __future__ import annotations
4+
35
import functools
46
import os.path
7+
from collections.abc import Callable, Iterable
8+
from typing import Literal, TypeVar
59

610
from jaraco.functools import splat
711

812
from .compat.py39 import zip_strict
913
from .errors import DistutilsFileError
1014

15+
_SourcesT = TypeVar(
16+
"_SourcesT", bound="str | bytes | os.PathLike[str] | os.PathLike[bytes]"
17+
)
18+
_TargetsT = TypeVar(
19+
"_TargetsT", bound="str | bytes | os.PathLike[str] | os.PathLike[bytes]"
20+
)
21+
1122

1223
def _newer(source, target):
1324
return not os.path.exists(target) or (
1425
os.path.getmtime(source) > os.path.getmtime(target)
1526
)
1627

1728

18-
def newer(source, target):
29+
def newer(
30+
source: str | bytes | os.PathLike[str] | os.PathLike[bytes],
31+
target: str | bytes | os.PathLike[str] | os.PathLike[bytes],
32+
) -> bool:
1933
"""
2034
Is source modified more recently than target.
2135
@@ -25,12 +39,16 @@ def newer(source, target):
2539
Raises DistutilsFileError if 'source' does not exist.
2640
"""
2741
if not os.path.exists(source):
28-
raise DistutilsFileError(f"file '{os.path.abspath(source)}' does not exist")
42+
raise DistutilsFileError(f"file {os.path.abspath(source)!r} does not exist")
2943

3044
return _newer(source, target)
3145

3246

33-
def newer_pairwise(sources, targets, newer=newer):
47+
def newer_pairwise(
48+
sources: Iterable[_SourcesT],
49+
targets: Iterable[_TargetsT],
50+
newer: Callable[[_SourcesT, _TargetsT], bool] = newer,
51+
) -> tuple[list[_SourcesT], list[_TargetsT]]:
3452
"""
3553
Filter filenames where sources are newer than targets.
3654
@@ -43,7 +61,11 @@ def newer_pairwise(sources, targets, newer=newer):
4361
return tuple(map(list, zip(*newer_pairs))) or ([], [])
4462

4563

46-
def newer_group(sources, target, missing='error'):
64+
def newer_group(
65+
sources: Iterable[str | bytes | os.PathLike[str] | os.PathLike[bytes]],
66+
target: str | bytes | os.PathLike[str] | os.PathLike[bytes],
67+
missing: Literal["error", "ignore", "newer"] = "error",
68+
) -> bool:
4769
"""
4870
Is target out-of-date with respect to any file in sources.
4971

setuptools/_distutils/archive_util.py

+48-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
Utility functions for creating archive files (tarballs, zip files,
44
that sort of thing)."""
55

6+
from __future__ import annotations
7+
68
import os
9+
from typing import Literal, overload
710

811
try:
912
import zipfile
@@ -54,14 +57,14 @@ def _get_uid(name):
5457

5558

5659
def make_tarball(
57-
base_name,
58-
base_dir,
59-
compress="gzip",
60-
verbose=False,
61-
dry_run=False,
62-
owner=None,
63-
group=None,
64-
):
60+
base_name: str,
61+
base_dir: str | os.PathLike[str],
62+
compress: Literal["gzip", "bzip2", "xz"] | None = "gzip",
63+
verbose: bool = False,
64+
dry_run: bool = False,
65+
owner: str | None = None,
66+
group: str | None = None,
67+
) -> str:
6568
"""Create a (possibly compressed) tar file from all the files under
6669
'base_dir'.
6770
@@ -122,7 +125,12 @@ def _set_uid_gid(tarinfo):
122125
return archive_name
123126

124127

125-
def make_zipfile(base_name, base_dir, verbose=False, dry_run=False): # noqa: C901
128+
def make_zipfile( # noqa: C901
129+
base_name: str,
130+
base_dir: str | os.PathLike[str],
131+
verbose: bool = False,
132+
dry_run: bool = False,
133+
) -> str:
126134
"""Create a zip file from all the files under 'base_dir'.
127135
128136
The output zip file will be named 'base_name' + ".zip". Uses either the
@@ -204,16 +212,38 @@ def check_archive_formats(formats):
204212
return None
205213

206214

215+
@overload
216+
def make_archive(
217+
base_name: str,
218+
format: str,
219+
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
220+
base_dir: str | None = None,
221+
verbose: bool = False,
222+
dry_run: bool = False,
223+
owner: str | None = None,
224+
group: str | None = None,
225+
) -> str: ...
226+
@overload
227+
def make_archive(
228+
base_name: str | os.PathLike[str],
229+
format: str,
230+
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes],
231+
base_dir: str | None = None,
232+
verbose: bool = False,
233+
dry_run: bool = False,
234+
owner: str | None = None,
235+
group: str | None = None,
236+
) -> str: ...
207237
def make_archive(
208-
base_name,
209-
format,
210-
root_dir=None,
211-
base_dir=None,
212-
verbose=False,
213-
dry_run=False,
214-
owner=None,
215-
group=None,
216-
):
238+
base_name: str | os.PathLike[str],
239+
format: str,
240+
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
241+
base_dir: str | None = None,
242+
verbose: bool = False,
243+
dry_run: bool = False,
244+
owner: str | None = None,
245+
group: str | None = None,
246+
) -> str:
217247
"""Create an archive file (eg. zip or tar).
218248
219249
'base_name' is the name of the file to create, minus any format-specific

0 commit comments

Comments
 (0)