distutils: improve boolean parameters with int defaults (#11928)

This commit is contained in:
Avasam
2024-05-17 02:33:18 -04:00
committed by GitHub
parent 240114ac1a
commit c99adf4b85
26 changed files with 228 additions and 141 deletions

View File

@@ -1,7 +1,7 @@
from _typeshed import StrPath
from abc import abstractmethod
from collections.abc import Iterable, Mapping, Sequence
from typing import Any
from typing import Any, Literal
from ._distutils.cmd import Command as _Command
from .depends import Require as Require
@@ -76,7 +76,9 @@ class Command(_Command):
distribution: Distribution
def __init__(self, dist: Distribution, **kw: Any) -> None: ...
def ensure_string_list(self, option: str | list[str]) -> None: ...
def reinitialize_command(self, command: _Command | str, reinit_subcommands: int = 0, **kw: Any) -> _Command: ...
def reinitialize_command(
self, command: _Command | str, reinit_subcommands: bool | Literal[0, 1] = 0, **kw: Any
) -> _Command: ...
@abstractmethod
def initialize_options(self) -> None: ...
@abstractmethod

View File

@@ -1,10 +1,12 @@
from typing import Literal
def make_archive(
base_name: str,
format: str,
root_dir: str | None = ...,
base_dir: str | None = ...,
verbose: int = ...,
dry_run: int = ...,
verbose: bool | Literal[0, 1] = 0,
dry_run: bool | Literal[0, 1] = 0,
owner: str | None = ...,
group: str | None = ...,
) -> str: ...
@@ -12,9 +14,9 @@ def make_tarball(
base_name: str,
base_dir: str,
compress: str | None = ...,
verbose: int = ...,
dry_run: int = ...,
verbose: bool | Literal[0, 1] = 0,
dry_run: bool | Literal[0, 1] = 0,
owner: str | None = ...,
group: str | None = ...,
) -> str: ...
def make_zipfile(base_name: str, base_dir: str, verbose: int = ..., dry_run: int = ...) -> str: ...
def make_zipfile(base_name: str, base_dir: str, verbose: bool | Literal[0, 1] = 0, dry_run: bool | Literal[0, 1] = 0) -> str: ...

View File

@@ -1,5 +1,5 @@
from collections.abc import Callable
from typing import Any, ClassVar
from typing import Any, ClassVar, Literal
from typing_extensions import TypeAlias
_Macro: TypeAlias = tuple[str] | tuple[str, str | None]
@@ -10,7 +10,11 @@ def gen_lib_options(
def gen_preprocess_options(macros: list[_Macro], include_dirs: list[str]) -> list[str]: ...
def get_default_compiler(osname: str | None = ..., platform: str | None = ...) -> str: ...
def new_compiler(
plat: str | None = ..., compiler: str | None = ..., verbose: int = ..., dry_run: int = ..., force: int = ...
plat: str | None = ...,
compiler: str | None = ...,
verbose: bool | Literal[0, 1] = 0,
dry_run: bool | Literal[0, 1] = 0,
force: bool | Literal[0, 1] = 0,
) -> CCompiler: ...
def show_compilers() -> None: ...
@@ -34,7 +38,9 @@ class CCompiler:
library_dirs: list[str]
runtime_library_dirs: list[str]
objects: list[str]
def __init__(self, verbose: int = ..., dry_run: int = ..., force: int = ...) -> None: ...
def __init__(
self, verbose: bool | Literal[0, 1] = 0, dry_run: bool | Literal[0, 1] = 0, force: bool | Literal[0, 1] = 0
) -> None: ...
def add_include_dir(self, dir: str) -> None: ...
def set_include_dirs(self, dirs: list[str]) -> None: ...
def add_library(self, libname: str) -> None: ...
@@ -48,7 +54,7 @@ class CCompiler:
def add_link_object(self, object: str) -> None: ...
def set_link_objects(self, objects: list[str]) -> None: ...
def detect_language(self, sources: str | list[str]) -> str | None: ...
def find_library_file(self, dirs: list[str], lib: str, debug: bool = ...) -> str | None: ...
def find_library_file(self, dirs: list[str], lib: str, debug: bool | Literal[0, 1] = 0) -> str | None: ...
def has_function(
self,
funcname: str,
@@ -67,7 +73,7 @@ class CCompiler:
output_dir: str | None = ...,
macros: list[_Macro] | None = ...,
include_dirs: list[str] | None = ...,
debug: bool = ...,
debug: bool | Literal[0, 1] = 0,
extra_preargs: list[str] | None = ...,
extra_postargs: list[str] | None = ...,
depends: list[str] | None = ...,
@@ -77,7 +83,7 @@ class CCompiler:
objects: list[str],
output_libname: str,
output_dir: str | None = ...,
debug: bool = ...,
debug: bool | Literal[0, 1] = 0,
target_lang: str | None = ...,
) -> None: ...
def link(
@@ -90,7 +96,7 @@ class CCompiler:
library_dirs: list[str] | None = ...,
runtime_library_dirs: list[str] | None = ...,
export_symbols: list[str] | None = ...,
debug: bool = ...,
debug: bool | Literal[0, 1] = 0,
extra_preargs: list[str] | None = ...,
extra_postargs: list[str] | None = ...,
build_temp: str | None = ...,
@@ -104,7 +110,7 @@ class CCompiler:
libraries: list[str] | None = ...,
library_dirs: list[str] | None = ...,
runtime_library_dirs: list[str] | None = ...,
debug: bool = ...,
debug: bool | Literal[0, 1] = 0,
extra_preargs: list[str] | None = ...,
extra_postargs: list[str] | None = ...,
target_lang: str | None = ...,
@@ -118,7 +124,7 @@ class CCompiler:
library_dirs: list[str] | None = ...,
runtime_library_dirs: list[str] | None = ...,
export_symbols: list[str] | None = ...,
debug: bool = ...,
debug: bool | Literal[0, 1] = 0,
extra_preargs: list[str] | None = ...,
extra_postargs: list[str] | None = ...,
build_temp: str | None = ...,
@@ -133,7 +139,7 @@ class CCompiler:
library_dirs: list[str] | None = ...,
runtime_library_dirs: list[str] | None = ...,
export_symbols: list[str] | None = ...,
debug: bool = ...,
debug: bool | Literal[0, 1] = 0,
extra_preargs: list[str] | None = ...,
extra_postargs: list[str] | None = ...,
build_temp: str | None = ...,
@@ -148,10 +154,14 @@ class CCompiler:
extra_preargs: list[str] | None = ...,
extra_postargs: list[str] | None = ...,
) -> None: ...
def executable_filename(self, basename: str, strip_dir: int = ..., output_dir: str = ...) -> str: ...
def library_filename(self, libname: str, lib_type: str = "static", strip_dir: int = 0, output_dir: str = "") -> str: ...
def object_filenames(self, source_filenames: list[str], strip_dir: int = ..., output_dir: str = ...) -> list[str]: ...
def shared_object_filename(self, basename: str, strip_dir: int = ..., output_dir: str = ...) -> str: ...
def executable_filename(self, basename: str, strip_dir: bool | Literal[0, 1] = 0, output_dir: str = ...) -> str: ...
def library_filename(
self, libname: str, lib_type: str = "static", strip_dir: bool | Literal[0, 1] = 0, output_dir: str = ""
) -> str: ...
def object_filenames(
self, source_filenames: list[str], strip_dir: bool | Literal[0, 1] = 0, output_dir: str = ...
) -> list[str]: ...
def shared_object_filename(self, basename: str, strip_dir: bool | Literal[0, 1] = 0, output_dir: str = ...) -> str: ...
def execute(self, func: Callable[..., object], args: tuple[Any, ...], msg: str | None = ..., level: int = ...) -> None: ...
def spawn(self, cmd: list[str]) -> None: ...
def mkpath(self, name: str, mode: int = ...) -> None: ...

View File

@@ -1,7 +1,7 @@
from _typeshed import Incomplete
from _typeshed import Incomplete, Unused
from abc import abstractmethod
from collections.abc import Callable, Iterable
from typing import ClassVar
from typing import ClassVar, Literal
from typing_extensions import Self
from .dist import Distribution
@@ -25,8 +25,8 @@ class Command:
def ensure_dirname(self, option: str) -> None: ...
def get_command_name(self) -> str: ...
def set_undefined_options(self, src_cmd: str, *option_pairs: tuple[str, str]) -> None: ...
def get_finalized_command(self, command: str, create: int = ...) -> Command: ...
def reinitialize_command(self, command: Command | str, reinit_subcommands: int = ...) -> Command: ...
def get_finalized_command(self, command: str, create: bool | Literal[0, 1] = 1) -> Command: ...
def reinitialize_command(self, command: Command | str, reinit_subcommands: bool | Literal[0, 1] = 0) -> Command: ...
def run_command(self, command: str) -> None: ...
def get_sub_commands(self) -> list[str]: ...
def warn(self, msg: str) -> None: ...
@@ -38,30 +38,30 @@ class Command:
self,
infile: str,
outfile: str,
preserve_mode: int = ...,
preserve_times: int = ...,
link: str | None = ...,
level: int = ...,
) -> tuple[str, bool]: ... # level is not used
preserve_mode: bool | Literal[0, 1] = 1,
preserve_times: bool | Literal[0, 1] = 1,
link: str | None = None,
level: Unused = 1,
) -> tuple[str, bool]: ...
def copy_tree(
self,
infile: str,
outfile: str,
preserve_mode: int = ...,
preserve_times: int = ...,
preserve_symlinks: int = ...,
level: int = ...,
) -> list[str]: ... # level is not used
def move_file(self, src: str, dst: str, level: int = ...) -> str: ... # level is not used
def spawn(self, cmd: Iterable[str], search_path: int = ..., level: int = ...) -> None: ... # level is not used
preserve_mode: bool | Literal[0, 1] = 1,
preserve_times: bool | Literal[0, 1] = 1,
preserve_symlinks: bool | Literal[0, 1] = 0,
level: Unused = 1,
) -> list[str]: ...
def move_file(self, src: str, dst: str, level: Unused = 1) -> str: ...
def spawn(self, cmd: Iterable[str], search_path: bool | Literal[0, 1] = 1, level: Unused = 1) -> None: ...
def make_archive(
self,
base_name: str,
format: str,
root_dir: str | None = ...,
base_dir: str | None = ...,
owner: str | None = ...,
group: str | None = ...,
root_dir: str | None = None,
base_dir: str | None = None,
owner: str | None = None,
group: str | None = None,
) -> str: ...
def make_file(
self,
@@ -69,7 +69,7 @@ class Command:
outfile: str,
func: Callable[..., object],
args: list[Incomplete],
exec_msg: str | None = ...,
skip_msg: str | None = ...,
level: int = ...,
) -> None: ... # level is not used
exec_msg: str | None = None,
skip_msg: str | None = None,
level: Unused = 1,
) -> None: ...

View File

@@ -1,4 +1,5 @@
from _typeshed import Incomplete
from typing import Literal
from ..cmd import Command
@@ -31,7 +32,7 @@ class build_py(Command):
def find_all_modules(self): ...
def get_source_files(self): ...
def get_module_outfile(self, build_dir, package, module): ...
def get_outputs(self, include_bytecode: int = ...): ...
def get_outputs(self, include_bytecode: bool | Literal[0, 1] = 1): ...
def build_module(self, module, module_file, package): ...
def build_modules(self) -> None: ...
def build_packages(self) -> None: ...

View File

@@ -17,21 +17,29 @@ class FileList:
def process_template_line(self, line: str) -> None: ...
@overload
def include_pattern(
self, pattern: str, anchor: bool | Literal[0, 1] = ..., prefix: str | None = ..., is_regex: Literal[0, False] = ...
self, pattern: str, anchor: bool | Literal[0, 1] = 1, prefix: str | None = ..., is_regex: Literal[0, False] = 0
) -> bool: ...
@overload
def include_pattern(self, pattern: str | Pattern[str], *, is_regex: Literal[True, 1] = ...) -> bool: ...
def include_pattern(self, pattern: str | Pattern[str], *, is_regex: Literal[True, 1]) -> bool: ...
@overload
def include_pattern(
self, pattern: str | Pattern[str], anchor: bool | Literal[0, 1] = ..., prefix: str | None = ..., is_regex: int = ...
self,
pattern: str | Pattern[str],
anchor: bool | Literal[0, 1] = 1,
prefix: str | None = ...,
is_regex: bool | Literal[0, 1] = 0,
) -> bool: ...
@overload
def exclude_pattern(
self, pattern: str, anchor: bool | Literal[0, 1] = ..., prefix: str | None = ..., is_regex: Literal[0, False] = ...
self, pattern: str, anchor: bool | Literal[0, 1] = 1, prefix: str | None = ..., is_regex: Literal[0, False] = 0
) -> bool: ...
@overload
def exclude_pattern(self, pattern: str | Pattern[str], *, is_regex: Literal[True, 1] = ...) -> bool: ...
def exclude_pattern(self, pattern: str | Pattern[str], *, is_regex: Literal[True, 1]) -> bool: ...
@overload
def exclude_pattern(
self, pattern: str | Pattern[str], anchor: bool | Literal[0, 1] = ..., prefix: str | None = ..., is_regex: int = ...
self,
pattern: str | Pattern[str],
anchor: bool | Literal[0, 1] = 1,
prefix: str | None = ...,
is_regex: bool | Literal[0, 1] = 0,
) -> bool: ...

View File

@@ -17,6 +17,8 @@ def get_config_vars() -> dict[str, str | int]: ...
def get_config_vars(arg: str, /, *args: str) -> list[str | int]: ...
def get_config_h_filename() -> str: ...
def get_makefile_filename() -> str: ...
def get_python_inc(plat_specific: bool = ..., prefix: str | None = ...) -> str: ...
def get_python_lib(plat_specific: bool = ..., standard_lib: bool = ..., prefix: str | None = ...) -> str: ...
def get_python_inc(plat_specific: bool | Literal[0, 1] = 0, prefix: str | None = ...) -> str: ...
def get_python_lib(
plat_specific: bool | Literal[0, 1] = 0, standard_lib: bool | Literal[0, 1] = 0, prefix: str | None = ...
) -> str: ...
def customize_compiler(compiler: CCompiler) -> None: ...

View File

@@ -13,17 +13,21 @@ def subst_vars(s: str, local_vars: Mapping[str, str]) -> None: ...
def grok_environment_error(exc: object, prefix: str = ...) -> str: ...
def split_quoted(s: str) -> list[str]: ...
def execute(
func: Callable[..., object], args: tuple[Any, ...], msg: str | None = ..., verbose: bool = ..., dry_run: bool = ...
func: Callable[..., object],
args: tuple[Any, ...],
msg: str | None = ...,
verbose: bool | Literal[0, 1] = 0,
dry_run: bool | Literal[0, 1] = 0,
) -> None: ...
def strtobool(val: str) -> Literal[0, 1]: ...
def byte_compile(
py_files: list[str],
optimize: int = ...,
force: bool = ...,
force: bool | Literal[0, 1] = 0,
prefix: str | None = ...,
base_dir: str | None = ...,
verbose: bool = ...,
dry_run: bool = ...,
verbose: bool | Literal[0, 1] = 1,
dry_run: bool | Literal[0, 1] = 0,
direct: bool | None = ...,
) -> None: ...
def rfc822_escape(header: str) -> str: ...

View File

@@ -1,5 +1,6 @@
from _typeshed import Incomplete
from collections.abc import Generator
from typing import Literal
from .. import Command
@@ -46,4 +47,11 @@ def can_scan(): ...
INSTALL_DIRECTORY_ATTRS: Incomplete
def make_zipfile(zip_filename, base_dir, verbose: int = 0, dry_run: int = 0, compress: bool = True, mode: str = "w"): ...
def make_zipfile(
zip_filename,
base_dir,
verbose: bool | Literal[0, 1] = 0,
dry_run: bool | Literal[0, 1] = 0,
compress: bool = True,
mode: str = "w",
): ...

View File

@@ -1,5 +1,5 @@
from _typeshed import Incomplete
from typing import Any, ClassVar
from typing import Any, ClassVar, Literal
from .._distutils.command.build_ext import build_ext as _build_ext
@@ -40,7 +40,7 @@ def link_shared_object(
library_dirs: Incomplete | None = None,
runtime_library_dirs: Incomplete | None = None,
export_symbols: Incomplete | None = None,
debug: int = 0,
debug: bool | Literal[0, 1] = 0,
extra_preargs: Incomplete | None = None,
extra_postargs: Incomplete | None = None,
build_temp: Incomplete | None = None,

View File

@@ -1,9 +1,18 @@
from _typeshed import Unused
from typing import Literal
from .._distutils.command import install_lib as orig
class install_lib(orig.install_lib):
def run(self) -> None: ...
def get_exclusions(self): ...
def copy_tree(
self, infile, outfile, preserve_mode: int = 1, preserve_times: int = 1, preserve_symlinks: int = 0, level: int = 1
self,
infile,
outfile,
preserve_mode: bool | Literal[0, 1] = 1,
preserve_times: bool | Literal[0, 1] = 1,
preserve_symlinks: bool | Literal[0, 1] = 0,
level: Unused = 1,
): ...
def get_outputs(self): ...