Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 9, 2025
2 parents 0cffd61 + 5589d75 commit c7e97a0
Show file tree
Hide file tree
Showing 32 changed files with 1,009 additions and 513 deletions.
30 changes: 26 additions & 4 deletions setuptools/_distutils/_modified.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
"""Timestamp comparison of files and groups of files."""

from __future__ import annotations

import functools
import os.path
from collections.abc import Callable, Iterable
from typing import Literal, TypeVar

from jaraco.functools import splat

from .compat.py39 import zip_strict
from .errors import DistutilsFileError

_SourcesT = TypeVar(
"_SourcesT", bound="str | bytes | os.PathLike[str] | os.PathLike[bytes]"
)
_TargetsT = TypeVar(
"_TargetsT", bound="str | bytes | os.PathLike[str] | os.PathLike[bytes]"
)


def _newer(source, target):
return not os.path.exists(target) or (
os.path.getmtime(source) > os.path.getmtime(target)
)


def newer(source, target):
def newer(
source: str | bytes | os.PathLike[str] | os.PathLike[bytes],
target: str | bytes | os.PathLike[str] | os.PathLike[bytes],
) -> bool:
"""
Is source modified more recently than target.
Expand All @@ -25,12 +39,16 @@ def newer(source, target):
Raises DistutilsFileError if 'source' does not exist.
"""
if not os.path.exists(source):
raise DistutilsFileError(f"file '{os.path.abspath(source)}' does not exist")
raise DistutilsFileError(f"file {os.path.abspath(source)!r} does not exist")

return _newer(source, target)


def newer_pairwise(sources, targets, newer=newer):
def newer_pairwise(
sources: Iterable[_SourcesT],
targets: Iterable[_TargetsT],
newer: Callable[[_SourcesT, _TargetsT], bool] = newer,
) -> tuple[list[_SourcesT], list[_TargetsT]]:
"""
Filter filenames where sources are newer than targets.
Expand All @@ -43,7 +61,11 @@ def newer_pairwise(sources, targets, newer=newer):
return tuple(map(list, zip(*newer_pairs))) or ([], [])


def newer_group(sources, target, missing='error'):
def newer_group(
sources: Iterable[str | bytes | os.PathLike[str] | os.PathLike[bytes]],
target: str | bytes | os.PathLike[str] | os.PathLike[bytes],
missing: Literal["error", "ignore", "newer"] = "error",
) -> bool:
"""
Is target out-of-date with respect to any file in sources.
Expand Down
66 changes: 48 additions & 18 deletions setuptools/_distutils/archive_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
Utility functions for creating archive files (tarballs, zip files,
that sort of thing)."""

from __future__ import annotations

import os
from typing import Literal, overload

try:
import zipfile
Expand Down Expand Up @@ -54,14 +57,14 @@ def _get_uid(name):


def make_tarball(
base_name,
base_dir,
compress="gzip",
verbose=False,
dry_run=False,
owner=None,
group=None,
):
base_name: str,
base_dir: str | os.PathLike[str],
compress: Literal["gzip", "bzip2", "xz"] | None = "gzip",
verbose: bool = False,
dry_run: bool = False,
owner: str | None = None,
group: str | None = None,
) -> str:
"""Create a (possibly compressed) tar file from all the files under
'base_dir'.
Expand Down Expand Up @@ -122,7 +125,12 @@ def _set_uid_gid(tarinfo):
return archive_name


def make_zipfile(base_name, base_dir, verbose=False, dry_run=False): # noqa: C901
def make_zipfile( # noqa: C901
base_name: str,
base_dir: str | os.PathLike[str],
verbose: bool = False,
dry_run: bool = False,
) -> str:
"""Create a zip file from all the files under 'base_dir'.
The output zip file will be named 'base_name' + ".zip". Uses either the
Expand Down Expand Up @@ -204,16 +212,38 @@ def check_archive_formats(formats):
return None


@overload
def make_archive(
base_name: str,
format: str,
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
base_dir: str | None = None,
verbose: bool = False,
dry_run: bool = False,
owner: str | None = None,
group: str | None = None,
) -> str: ...
@overload
def make_archive(
base_name: str | os.PathLike[str],
format: str,
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes],
base_dir: str | None = None,
verbose: bool = False,
dry_run: bool = False,
owner: str | None = None,
group: str | None = None,
) -> str: ...
def make_archive(
base_name,
format,
root_dir=None,
base_dir=None,
verbose=False,
dry_run=False,
owner=None,
group=None,
):
base_name: str | os.PathLike[str],
format: str,
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
base_dir: str | None = None,
verbose: bool = False,
dry_run: bool = False,
owner: str | None = None,
group: str | None = None,
) -> str:
"""Create an archive file (eg. zip or tar).
'base_name' is the name of the file to create, minus any format-specific
Expand Down
Loading

0 comments on commit c7e97a0

Please sign in to comment.