diff --git a/lib/ts_utils/metadata.py b/lib/ts_utils/metadata.py index 793b3b7a6d1e..6ce5be807bbc 100644 --- a/lib/ts_utils/metadata.py +++ b/lib/ts_utils/metadata.py @@ -166,6 +166,7 @@ def is_obsolete(self) -> bool: "tool", "partial_stub", "requires_python", + "mypy-tests", } ) _KNOWN_METADATA_TOOL_FIELDS: Final = { diff --git a/lib/ts_utils/mypy.py b/lib/ts_utils/mypy.py new file mode 100644 index 000000000000..28e7adc851c8 --- /dev/null +++ b/lib/ts_utils/mypy.py @@ -0,0 +1,80 @@ +from __future__ import annotations + +import os +import sys +import tempfile +from collections.abc import Generator, Iterable +from contextlib import contextmanager +from enum import Enum +from typing import Any, NamedTuple + +import tomli + +from ts_utils.metadata import metadata_path + + +class MypyDistConf(NamedTuple): + module_name: str + values: dict[str, dict[str, Any]] + + +class MypyResult(Enum): + SUCCESS = 0 + FAILURE = 1 + CRASH = 2 + + +# The configuration section in the metadata file looks like the following, with multiple module sections possible +# [mypy-tests] +# [mypy-tests.yaml] +# module_name = "yaml" +# [mypy-tests.yaml.values] +# disallow_incomplete_defs = true +# disallow_untyped_defs = true + + +def mypy_configuration_from_distribution(distribution: str) -> list[MypyDistConf]: + with metadata_path(distribution).open("rb") as f: + data = tomli.load(f) + + # TODO: This could be added to ts_utils.metadata + mypy_tests_conf: dict[str, dict[str, Any]] = data.get("mypy-tests", {}) + if not mypy_tests_conf: + return [] + + def validate_configuration(section_name: str, mypy_section: dict[str, Any]) -> MypyDistConf: + assert isinstance(mypy_section, dict), f"{section_name} should be a section" + module_name = mypy_section.get("module_name") + + assert module_name is not None, f"{section_name} should have a module_name key" + assert isinstance(module_name, str), f"{section_name} should be a key-value pair" + + assert "values" in mypy_section, f"{section_name} should have a values section" + values: dict[str, dict[str, Any]] = mypy_section["values"] + assert isinstance(values, dict), "values should be a section" + return MypyDistConf(module_name, values.copy()) + + assert isinstance(mypy_tests_conf, dict), "mypy-tests should be a section" + return [validate_configuration(section_name, mypy_section) for section_name, mypy_section in mypy_tests_conf.items()] + + +@contextmanager +def temporary_mypy_config_file( + configurations: Iterable[MypyDistConf], +) -> Generator[tempfile._TemporaryFileWrapper[str]]: # pyright: ignore[reportPrivateUsage] + # We need to work around a limitation of tempfile.NamedTemporaryFile on Windows + # For details, see https://github.com/python/typeshed/pull/13620#discussion_r1990185997 + # Python 3.12 added a workaround with `tempfile.NamedTemporaryFile("w+", delete_on_close=False)` + temp = tempfile.NamedTemporaryFile("w+", delete=sys.platform != "win32") # noqa: SIM115 + try: + for dist_conf in configurations: + temp.write(f"[mypy-{dist_conf.module_name}]\n") + for k, v in dist_conf.values.items(): + temp.write(f"{k} = {v}\n") + temp.write("[mypy]\n") + temp.flush() + yield temp + finally: + temp.close() + if sys.platform == "win32": + os.remove(temp.name) diff --git a/pyrightconfig.json b/pyrightconfig.json index 5e63976c9eab..d45b973a5796 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -47,4 +47,6 @@ "reportSelfClsParameterName": "none", // Not actionable in typeshed "reportDeprecated": "none", + // DO NOT MERGE! Temporary workaround until https://github.com/pypa/distutils/pull/338 is merged upstream + "reportMissingTypeStubs": "none", } diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 9f20ff2c9c93..5b9ad21f7d56 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -130,4 +130,6 @@ "reportSelfClsParameterName": "none", // Not actionable in typeshed "reportDeprecated": "none", + // DO NOT MERGE! Temporary workaround until https://github.com/pypa/distutils/pull/338 is merged upstream + "reportMissingTypeStubs": "none", } diff --git a/pyrightconfig.testcases.json b/pyrightconfig.testcases.json index a957cc694f18..e8d85efec2b7 100644 --- a/pyrightconfig.testcases.json +++ b/pyrightconfig.testcases.json @@ -29,4 +29,6 @@ "reportUnnecessaryIsInstance": "none", // The name of the self/cls parameter is out of typeshed's control. "reportSelfClsParameterName": "none", + // DO NOT MERGE! Temporary workaround until https://github.com/pypa/distutils/pull/338 is merged upstream + "reportMissingTypeStubs": "none", } diff --git a/stubs/cffi/METADATA.toml b/stubs/cffi/METADATA.toml index f1607a4d9f2a..2ab5d216d426 100644 --- a/stubs/cffi/METADATA.toml +++ b/stubs/cffi/METADATA.toml @@ -2,6 +2,12 @@ version = "1.16.*" upstream_repository = "https://foss.heptapod.net/pypy/cffi" requires = ["types-setuptools"] +# When ran directly on our stubs, mypy won't understand that they are partial +# This is not an issue with pyright because it understands per-module py.typed (setuptools/_distutils/py.typed) +[mypy-tests.distutils] +module_name = "setuptools._distutils.*" +values = { "follow_untyped_imports" = true } + [tool.stubtest] # linux and darwin are mostly equivalent, except for a single `RTLD_DEEPBIND` variable platforms = ["linux", "win32"] diff --git a/stubs/fanstatic/METADATA.toml b/stubs/fanstatic/METADATA.toml index 563c927555fc..39c4276f7079 100644 --- a/stubs/fanstatic/METADATA.toml +++ b/stubs/fanstatic/METADATA.toml @@ -1,3 +1,9 @@ version = "1.5.*" upstream_repository = "https://github.com/zopefoundation/fanstatic" -requires = ["types-setuptools", "types-WebOb"] +requires = ["types-WebOb", "types-setuptools"] + +# When ran directly on our stubs, mypy won't understand that they are partial +# This is not an issue with pyright because it understands per-module py.typed (setuptools/_distutils/py.typed) +[mypy-tests.distutils] +module_name = "setuptools._distutils.*" +values = { "follow_untyped_imports" = true } diff --git a/stubs/libsass/METADATA.toml b/stubs/libsass/METADATA.toml index 77f836f94edb..4a9d9c4dd94f 100644 --- a/stubs/libsass/METADATA.toml +++ b/stubs/libsass/METADATA.toml @@ -2,6 +2,12 @@ version = "0.23.*" requires = ["types-setuptools"] upstream_repository = "https://github.com/sass/libsass-python" +# When ran directly on our stubs, mypy won't understand that they are partial +# This is not an issue with pyright because it understands per-module py.typed (setuptools/_distutils/py.typed) +[mypy-tests.distutils] +module_name = "setuptools._distutils.*" +values = { "follow_untyped_imports" = true } + [tool.stubtest] # The runtime package has an undeclared dependency on setuptools stubtest_requirements = ["setuptools"] diff --git a/stubs/pygit2/METADATA.toml b/stubs/pygit2/METADATA.toml index 13eec7dc9537..c4b5a1ab7e0e 100644 --- a/stubs/pygit2/METADATA.toml +++ b/stubs/pygit2/METADATA.toml @@ -3,5 +3,11 @@ upstream_repository = "https://github.com/libgit2/pygit2" requires = ["types-cffi"] obsolete_since = "1.16.0" # Released on 2024-10-11 +# When ran directly on our stubs, mypy won't understand that they are partial +# This is not an issue with pyright because it understands per-module py.typed (setuptools/_distutils/py.typed) +[mypy-tests.distutils] +module_name = "setuptools._distutils.*" +values = { "follow_untyped_imports" = true } + [tool.stubtest] platforms = ["darwin", "linux", "win32"] diff --git a/stubs/setuptools/@tests/stubtest_allowlist.txt b/stubs/setuptools/@tests/stubtest_allowlist.txt index ef8af309865d..d90770b86e42 100644 --- a/stubs/setuptools/@tests/stubtest_allowlist.txt +++ b/stubs/setuptools/@tests/stubtest_allowlist.txt @@ -1,99 +1,27 @@ -# Is a functools.partial, so stubtest says "is not a function" -setuptools.modified.newer_pairwise_group -setuptools._distutils._modified.newer_pairwise_group - -# Runtime initializes to None, but this really should never be None when used -setuptools._distutils.compilers.C.base.Compiler.compiler_type - -# Dynamically created in __init__ -setuptools._distutils.dist.Distribution.get_name -setuptools._distutils.dist.Distribution.get_version -setuptools._distutils.dist.Distribution.get_fullname -setuptools._distutils.dist.Distribution.get_author -setuptools._distutils.dist.Distribution.get_author_email -setuptools._distutils.dist.Distribution.get_maintainer -setuptools._distutils.dist.Distribution.get_maintainer_email -setuptools._distutils.dist.Distribution.get_contact -setuptools._distutils.dist.Distribution.get_contact_email -setuptools._distutils.dist.Distribution.get_url -setuptools._distutils.dist.Distribution.get_license -setuptools._distutils.dist.Distribution.get_licence -setuptools._distutils.dist.Distribution.get_description -setuptools._distutils.dist.Distribution.get_long_description -setuptools._distutils.dist.Distribution.get_keywords -setuptools._distutils.dist.Distribution.get_platforms -setuptools._distutils.dist.Distribution.get_classifiers -setuptools._distutils.dist.Distribution.get_download_url -setuptools._distutils.dist.Distribution.get_requires -setuptools._distutils.dist.Distribution.get_provides -setuptools._distutils.dist.Distribution.get_obsoletes - -# Missing objects from setuptools._distutils -setuptools._distutils.archive_util.ARCHIVE_FORMATS -setuptools._distutils.archive_util.check_archive_formats -setuptools._distutils.cmd.Command.dump_options -setuptools._distutils.command.build_clib.show_compilers -setuptools._distutils.command.build_ext.extension_name_re -setuptools._distutils.command.build_ext.show_compilers -setuptools._distutils.command.build_scripts -setuptools._distutils.command.check -setuptools._distutils.command.clean -setuptools._distutils.command.install_data -setuptools._distutils.command.install_headers -setuptools._distutils.command.install.HAS_USER_SITE -setuptools._distutils.command.install.INSTALL_SCHEMES -setuptools._distutils.command.install.SCHEME_KEYS -setuptools._distutils.command.install.WINDOWS_SCHEME -setuptools._distutils.command.install_lib.PYTHON_SOURCE_EXTENSION -setuptools._distutils.dist.fix_help_options -setuptools._distutils.extension.read_setup_file -setuptools._distutils.filelist.findall -setuptools._distutils.filelist.glob_to_re -setuptools._distutils.filelist.translate_pattern -setuptools._distutils.sysconfig.BASE_EXEC_PREFIX -setuptools._distutils.sysconfig.BASE_PREFIX -setuptools._distutils.sysconfig.IS_PYPY -setuptools._distutils.sysconfig.build_flags -setuptools._distutils.sysconfig.expand_makefile_vars -setuptools._distutils.sysconfig.get_python_version -setuptools._distutils.sysconfig.parse_config_h -setuptools._distutils.sysconfig.parse_makefile -setuptools._distutils.sysconfig.project_base -setuptools._distutils.sysconfig.python_build -setuptools._distutils.util.is_freethreaded -setuptools._distutils.util.MACOSX_VERSION_VAR - -# Missing submodules from setuptools._distutils -# (Many of these may be implementation details, -# but they can be added if people ask for them) -setuptools._distutils.command.__all__ -setuptools._distutils.command.bdist_dumb -setuptools._distutils.command.build_scripts -setuptools._distutils.command.check -setuptools._distutils.command.clean -setuptools._distutils.command.config -setuptools._distutils.command.install_data -setuptools._distutils.command.install_egg_info -setuptools._distutils.command.install_headers -setuptools._distutils.compat.py39 -setuptools._distutils.core -setuptools._distutils.cygwinccompiler -setuptools._distutils.debug -setuptools._distutils.dir_util -setuptools._distutils.fancy_getopt -setuptools._distutils.file_util -setuptools._distutils.log -setuptools._distutils.text_file -setuptools._distutils.unixccompiler -setuptools._distutils.version -setuptools._distutils.versionpredicate -setuptools._distutils.zosccompiler - -# Reexported from setuptools._distutils; problems should be fixed there +# Reexported from https://github.com/pypa/distutils; problems should be fixed there distutils\..+ +setuptools._distutils\..+ # Private APIs, tests and other vendored code setuptools.config._validate_pyproject.* setuptools.compat.* -setuptools.command.build_py.build_py.existing_egg_info_dir .+?\.tests.* + +# DO NOT MERGE! Temporary workaround until https://github.com/pypa/distutils/pull/345 is merged upstream +# stubtest fails on implicit submodule imports for __all__ (in setuptools/_distutils/command/__init__.py) +setuptools.command.bdist_rpm +setuptools.command.bdist_wheel +setuptools.command.build_clib +setuptools.command.build_py +setuptools.command.develop +setuptools.command.dist_info +setuptools.command.easy_install +setuptools.command.editable_wheel +setuptools.command.egg_info +setuptools.command.install +setuptools.command.install_lib +setuptools.command.install_scripts +setuptools.command.sdist +setuptools.installer +setuptools.package_index +setuptools.wheel diff --git a/stubs/setuptools/METADATA.toml b/stubs/setuptools/METADATA.toml index f8c0ecb7c936..ea36df4b71c6 100644 --- a/stubs/setuptools/METADATA.toml +++ b/stubs/setuptools/METADATA.toml @@ -4,7 +4,15 @@ extra_description = """\ Given that `pkg_resources` is typed since `setuptools >= 71.1`, \ it is no longer included with `types-setuptools`. """ -requires = ["setuptools"] # For pkg_resources +requires = ["setuptools"] # For pkg_resources and setuptools._distutils +# setuptools/_distutils is a vendor of pypa's distutils. Which is now as typed as typeshed. +partial_stub = true + +# When ran directly on our stubs, mypy won't understand that they are partial +# This is not an issue with pyright because it understands per-module py.typed (setuptools/_distutils/py.typed) +[mypy-tests.distutils] +module_name = "setuptools._distutils.*" +values = { "follow_untyped_imports" = true } [tool.stubtest] # darwin is equivalent to linux for OS-specific methods diff --git a/stubs/setuptools/distutils/command/bdist_dumb.pyi b/stubs/setuptools/distutils/command/bdist_dumb.pyi new file mode 100644 index 000000000000..b6f3e0cde009 --- /dev/null +++ b/stubs/setuptools/distutils/command/bdist_dumb.pyi @@ -0,0 +1 @@ +from setuptools._distutils.command.bdist_dumb import * diff --git a/stubs/setuptools/distutils/command/build_scripts.pyi b/stubs/setuptools/distutils/command/build_scripts.pyi new file mode 100644 index 000000000000..1b17f2d7f9e8 --- /dev/null +++ b/stubs/setuptools/distutils/command/build_scripts.pyi @@ -0,0 +1 @@ +from setuptools._distutils.command.build_scripts import * diff --git a/stubs/setuptools/distutils/command/check.pyi b/stubs/setuptools/distutils/command/check.pyi new file mode 100644 index 000000000000..327533ac3774 --- /dev/null +++ b/stubs/setuptools/distutils/command/check.pyi @@ -0,0 +1 @@ +from setuptools._distutils.command.check import * diff --git a/stubs/setuptools/distutils/command/clean.pyi b/stubs/setuptools/distutils/command/clean.pyi new file mode 100644 index 000000000000..30df3d0c2352 --- /dev/null +++ b/stubs/setuptools/distutils/command/clean.pyi @@ -0,0 +1 @@ +from setuptools._distutils.command.clean import * diff --git a/stubs/setuptools/distutils/command/config.pyi b/stubs/setuptools/distutils/command/config.pyi new file mode 100644 index 000000000000..ba2478249c58 --- /dev/null +++ b/stubs/setuptools/distutils/command/config.pyi @@ -0,0 +1 @@ +from setuptools._distutils.command.config import * diff --git a/stubs/setuptools/distutils/command/install_egg_info.pyi b/stubs/setuptools/distutils/command/install_egg_info.pyi new file mode 100644 index 000000000000..691c9e13986b --- /dev/null +++ b/stubs/setuptools/distutils/command/install_egg_info.pyi @@ -0,0 +1 @@ +from setuptools._distutils.command.install_egg_info import * diff --git a/stubs/setuptools/distutils/command/install_headers.pyi b/stubs/setuptools/distutils/command/install_headers.pyi new file mode 100644 index 000000000000..a5802710b068 --- /dev/null +++ b/stubs/setuptools/distutils/command/install_headers.pyi @@ -0,0 +1 @@ +from setuptools._distutils.command.install_headers import * diff --git a/stubs/setuptools/distutils/compilers/C/cygwin.pyi b/stubs/setuptools/distutils/compilers/C/cygwin.pyi new file mode 100644 index 000000000000..9b7a9d9e0ca0 --- /dev/null +++ b/stubs/setuptools/distutils/compilers/C/cygwin.pyi @@ -0,0 +1 @@ +from setuptools._distutils.compilers.C.cygwin import * diff --git a/stubs/setuptools/distutils/compilers/C/unix.pyi b/stubs/setuptools/distutils/compilers/C/unix.pyi new file mode 100644 index 000000000000..d4dbeff6b110 --- /dev/null +++ b/stubs/setuptools/distutils/compilers/C/unix.pyi @@ -0,0 +1 @@ +from setuptools._distutils.compilers.C.unix import * diff --git a/stubs/setuptools/distutils/compilers/C/zos.pyi b/stubs/setuptools/distutils/compilers/C/zos.pyi new file mode 100644 index 000000000000..921cd46b47ef --- /dev/null +++ b/stubs/setuptools/distutils/compilers/C/zos.pyi @@ -0,0 +1 @@ +from setuptools._distutils.compilers.C.zos import * diff --git a/stubs/setuptools/distutils/core.pyi b/stubs/setuptools/distutils/core.pyi new file mode 100644 index 000000000000..2efbd52e1c75 --- /dev/null +++ b/stubs/setuptools/distutils/core.pyi @@ -0,0 +1 @@ +from setuptools._distutils.core import * diff --git a/stubs/setuptools/distutils/cygwinccompiler.pyi b/stubs/setuptools/distutils/cygwinccompiler.pyi new file mode 100644 index 000000000000..1784f31d60fc --- /dev/null +++ b/stubs/setuptools/distutils/cygwinccompiler.pyi @@ -0,0 +1 @@ +from setuptools._distutils.cygwinccompiler import * diff --git a/stubs/setuptools/distutils/debug.pyi b/stubs/setuptools/distutils/debug.pyi new file mode 100644 index 000000000000..859405e8cbba --- /dev/null +++ b/stubs/setuptools/distutils/debug.pyi @@ -0,0 +1 @@ +from setuptools._distutils.debug import * diff --git a/stubs/setuptools/distutils/dir_util.pyi b/stubs/setuptools/distutils/dir_util.pyi new file mode 100644 index 000000000000..cfa954497574 --- /dev/null +++ b/stubs/setuptools/distutils/dir_util.pyi @@ -0,0 +1 @@ +from setuptools._distutils.dir_util import * diff --git a/stubs/setuptools/distutils/fancy_getopt.pyi b/stubs/setuptools/distutils/fancy_getopt.pyi new file mode 100644 index 000000000000..80b723b5e53f --- /dev/null +++ b/stubs/setuptools/distutils/fancy_getopt.pyi @@ -0,0 +1 @@ +from setuptools._distutils.fancy_getopt import * diff --git a/stubs/setuptools/distutils/file_util.pyi b/stubs/setuptools/distutils/file_util.pyi new file mode 100644 index 000000000000..b8213261f9f3 --- /dev/null +++ b/stubs/setuptools/distutils/file_util.pyi @@ -0,0 +1 @@ +from setuptools._distutils.file_util import * diff --git a/stubs/setuptools/distutils/log.pyi b/stubs/setuptools/distutils/log.pyi new file mode 100644 index 000000000000..c2da037722e4 --- /dev/null +++ b/stubs/setuptools/distutils/log.pyi @@ -0,0 +1 @@ +from setuptools._distutils.log import * diff --git a/stubs/setuptools/distutils/text_file.pyi b/stubs/setuptools/distutils/text_file.pyi new file mode 100644 index 000000000000..783363c1b911 --- /dev/null +++ b/stubs/setuptools/distutils/text_file.pyi @@ -0,0 +1 @@ +from setuptools._distutils.text_file import * diff --git a/stubs/setuptools/distutils/unixccompiler.pyi b/stubs/setuptools/distutils/unixccompiler.pyi new file mode 100644 index 000000000000..fcbf9e199041 --- /dev/null +++ b/stubs/setuptools/distutils/unixccompiler.pyi @@ -0,0 +1 @@ +from setuptools._distutils.unixccompiler import * diff --git a/stubs/setuptools/distutils/version.pyi b/stubs/setuptools/distutils/version.pyi new file mode 100644 index 000000000000..1cac35f20653 --- /dev/null +++ b/stubs/setuptools/distutils/version.pyi @@ -0,0 +1 @@ +from setuptools._distutils.version import * diff --git a/stubs/setuptools/distutils/versionpredicate.pyi b/stubs/setuptools/distutils/versionpredicate.pyi new file mode 100644 index 000000000000..325f30a966ea --- /dev/null +++ b/stubs/setuptools/distutils/versionpredicate.pyi @@ -0,0 +1 @@ +from setuptools._distutils.versionpredicate import * diff --git a/stubs/setuptools/distutils/zosccompiler.pyi b/stubs/setuptools/distutils/zosccompiler.pyi new file mode 100644 index 000000000000..b69c6320e43b --- /dev/null +++ b/stubs/setuptools/distutils/zosccompiler.pyi @@ -0,0 +1 @@ +from setuptools._distutils.zosccompiler import * diff --git a/stubs/setuptools/setuptools/__init__.pyi b/stubs/setuptools/setuptools/__init__.pyi index 815e1336ce50..6ac4b7e0c45d 100644 --- a/stubs/setuptools/setuptools/__init__.pyi +++ b/stubs/setuptools/setuptools/__init__.pyi @@ -4,7 +4,8 @@ from collections.abc import Mapping, Sequence from typing import Any, Literal, TypedDict, TypeVar, overload, type_check_only from typing_extensions import NotRequired -from ._distutils.cmd import Command as _Command +from setuptools._distutils.cmd import Command as _Command + from .command.alias import alias from .command.bdist_egg import bdist_egg from .command.bdist_rpm import bdist_rpm diff --git a/stubs/setuptools/setuptools/_distutils/__init__.pyi b/stubs/setuptools/setuptools/_distutils/__init__.pyi deleted file mode 100644 index c5dd95466063..000000000000 --- a/stubs/setuptools/setuptools/_distutils/__init__.pyi +++ /dev/null @@ -1,3 +0,0 @@ -from typing import Final - -__version__: Final[str] diff --git a/stubs/setuptools/setuptools/_distutils/_modified.pyi b/stubs/setuptools/setuptools/_distutils/_modified.pyi deleted file mode 100644 index b64061d5c4b2..000000000000 --- a/stubs/setuptools/setuptools/_distutils/_modified.pyi +++ /dev/null @@ -1,17 +0,0 @@ -from _typeshed import StrOrBytesPath -from collections.abc import Callable, Iterable -from typing import Literal, TypeVar - -_SourcesT = TypeVar("_SourcesT", bound=StrOrBytesPath) -_TargetsT = TypeVar("_TargetsT", bound=StrOrBytesPath) - -def newer(source: StrOrBytesPath, target: StrOrBytesPath) -> bool: ... -def newer_pairwise( - sources: Iterable[_SourcesT], targets: Iterable[_TargetsT], newer: Callable[[_SourcesT, _TargetsT], bool] = ... -) -> tuple[list[_SourcesT], list[_TargetsT]]: ... -def newer_group( - sources: Iterable[StrOrBytesPath], target: StrOrBytesPath, missing: Literal["error", "ignore", "newer"] = "error" -) -> bool: ... -def newer_pairwise_group( - sources: Iterable[_SourcesT], targets: Iterable[_TargetsT], *, newer: Callable[[_SourcesT, _TargetsT], bool] = ... -) -> tuple[list[_SourcesT], list[_TargetsT]]: ... diff --git a/stubs/setuptools/setuptools/_distutils/_msvccompiler.pyi b/stubs/setuptools/setuptools/_distutils/_msvccompiler.pyi deleted file mode 100644 index 34d9735b0614..000000000000 --- a/stubs/setuptools/setuptools/_distutils/_msvccompiler.pyi +++ /dev/null @@ -1,3 +0,0 @@ -from .compilers.C import msvc - -MSVCCompiler = msvc.Compiler diff --git a/stubs/setuptools/setuptools/_distutils/archive_util.pyi b/stubs/setuptools/setuptools/_distutils/archive_util.pyi deleted file mode 100644 index b866451a6bef..000000000000 --- a/stubs/setuptools/setuptools/_distutils/archive_util.pyi +++ /dev/null @@ -1,35 +0,0 @@ -from _typeshed import StrOrBytesPath, StrPath -from typing import Literal, overload - -@overload -def make_archive( - base_name: str, - format: str, - root_dir: StrOrBytesPath | 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: StrPath, - format: str, - root_dir: StrOrBytesPath, - base_dir: str | None = None, - verbose: bool = False, - dry_run: bool = False, - owner: str | None = None, - group: str | None = None, -) -> str: ... -def make_tarball( - base_name: str, - base_dir: StrPath, - compress: Literal["gzip", "bzip2", "xz"] | None = "gzip", - verbose: bool = False, - dry_run: bool = False, - owner: str | None = None, - group: str | None = None, -) -> str: ... -def make_zipfile(base_name: str, base_dir: StrPath, verbose: bool = False, dry_run: bool = False) -> str: ... diff --git a/stubs/setuptools/setuptools/_distutils/ccompiler.pyi b/stubs/setuptools/setuptools/_distutils/ccompiler.pyi deleted file mode 100644 index cbb794e101a0..000000000000 --- a/stubs/setuptools/setuptools/_distutils/ccompiler.pyi +++ /dev/null @@ -1,15 +0,0 @@ -from .compilers.C import base -from .compilers.C.base import gen_lib_options, gen_preprocess_options, get_default_compiler, new_compiler, show_compilers -from .compilers.C.errors import CompileError, LinkError - -__all__ = [ - "CompileError", - "LinkError", - "gen_lib_options", - "gen_preprocess_options", - "get_default_compiler", - "new_compiler", - "show_compilers", -] - -CCompiler = base.Compiler diff --git a/stubs/setuptools/setuptools/_distutils/cmd.pyi b/stubs/setuptools/setuptools/_distutils/cmd.pyi deleted file mode 100644 index 2c22e460989c..000000000000 --- a/stubs/setuptools/setuptools/_distutils/cmd.pyi +++ /dev/null @@ -1,117 +0,0 @@ -from _typeshed import BytesPath, StrOrBytesPath, StrPath, Unused -from abc import abstractmethod -from collections.abc import Callable, MutableSequence -from typing import Any, ClassVar, TypeVar, overload -from typing_extensions import TypeVarTuple, Unpack - -from .dist import Distribution - -_StrPathT = TypeVar("_StrPathT", bound=StrPath) -_BytesPathT = TypeVar("_BytesPathT", bound=BytesPath) -_CommandT = TypeVar("_CommandT", bound=Command) -_Ts = TypeVarTuple("_Ts") - -class Command: - dry_run: bool # Exposed from __getattr_. Same as Distribution.dry_run - distribution: Distribution - # Any to work around variance issues - sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] - user_options: ClassVar[ - # Specifying both because list is invariant. Avoids mypy override assignment issues - list[tuple[str, str, str]] - | list[tuple[str, str | None, str]] - ] - def __init__(self, dist: Distribution) -> None: ... - def ensure_finalized(self) -> None: ... - @abstractmethod - def initialize_options(self) -> None: ... - @abstractmethod - def finalize_options(self) -> None: ... - @abstractmethod - def run(self) -> None: ... - def announce(self, msg: str, level: int = 10) -> None: ... - def debug_print(self, msg: str) -> None: ... - def ensure_string(self, option: str, default: str | None = None) -> None: ... - def ensure_string_list(self, option: str) -> None: ... - def ensure_filename(self, option: str) -> None: ... - 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: ... - # NOTE: Because this is private setuptools implementation and we don't re-expose all commands here, - # we're not overloading each and every command possibility. - def get_finalized_command(self, command: str, create: bool = True) -> Command: ... - @overload - def reinitialize_command(self, command: str, reinit_subcommands: bool = False) -> Command: ... - @overload - def reinitialize_command(self, command: _CommandT, reinit_subcommands: bool = False) -> _CommandT: ... - def run_command(self, command: str) -> None: ... - def get_sub_commands(self) -> list[str]: ... - def warn(self, msg: str) -> None: ... - def execute( - self, func: Callable[[Unpack[_Ts]], Unused], args: tuple[Unpack[_Ts]], msg: str | None = None, level: int = 1 - ) -> None: ... - def mkpath(self, name: str, mode: int = 0o777) -> None: ... - @overload - def copy_file( - self, - infile: StrPath, - outfile: _StrPathT, - preserve_mode: bool = True, - preserve_times: bool = True, - link: str | None = None, - level: Unused = 1, - ) -> tuple[_StrPathT | str, bool]: ... - @overload - def copy_file( - self, - infile: BytesPath, - outfile: _BytesPathT, - preserve_mode: bool = True, - preserve_times: bool = True, - link: str | None = None, - level: Unused = 1, - ) -> tuple[_BytesPathT | bytes, bool]: ... - def copy_tree( - self, - infile: StrPath, - outfile: str, - preserve_mode: bool = True, - preserve_times: bool = True, - preserve_symlinks: bool = False, - level: Unused = 1, - ) -> list[str]: ... - @overload - def move_file(self, src: StrPath, dst: _StrPathT, level: Unused = 1) -> _StrPathT | str: ... - @overload - def move_file(self, src: BytesPath, dst: _BytesPathT, level: Unused = 1) -> _BytesPathT | bytes: ... - def spawn(self, cmd: MutableSequence[str], search_path: bool = True, level: Unused = 1) -> None: ... - @overload - def make_archive( - self, - base_name: str, - format: str, - root_dir: StrOrBytesPath | None = None, - base_dir: str | None = None, - owner: str | None = None, - group: str | None = None, - ) -> str: ... - @overload - def make_archive( - self, - base_name: StrPath, - format: str, - root_dir: StrOrBytesPath, - base_dir: str | None = None, - owner: str | None = None, - group: str | None = None, - ) -> str: ... - def make_file( - self, - infiles: str | list[str] | tuple[str, ...], - outfile: StrOrBytesPath, - func: Callable[[Unpack[_Ts]], Unused], - args: tuple[Unpack[_Ts]], - exec_msg: str | None = None, - skip_msg: str | None = None, - level: Unused = 1, - ) -> None: ... diff --git a/stubs/setuptools/setuptools/_distutils/command/__init__.pyi b/stubs/setuptools/setuptools/_distutils/command/__init__.pyi deleted file mode 100644 index adeb472a515f..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/__init__.pyi +++ /dev/null @@ -1,39 +0,0 @@ -from . import ( - bdist as bdist, - bdist_rpm as bdist_rpm, - build as build, - build_clib as build_clib, - build_ext as build_ext, - build_py as build_py, - # build_scripts as build_scripts, - # check as check, - # clean as clean, - install as install, - # install_data as install_data, - # install_headers as install_headers, - install_lib as install_lib, - install_scripts as install_scripts, - sdist as sdist, -) - -# Commented out commands are not stubbed. -# (Many of these may be implementation details, -# but they can be added if people ask for them) -__all__ = [ - "build", - "build_py", - "build_ext", - "build_clib", - # "build_scripts", - # "clean", - "install", - "install_lib", - # "install_headers", - "install_scripts", - # "install_data", - "sdist", - "bdist", - # "bdist_dumb", - "bdist_rpm", - # "check", -] diff --git a/stubs/setuptools/setuptools/_distutils/command/bdist.pyi b/stubs/setuptools/setuptools/_distutils/command/bdist.pyi deleted file mode 100644 index 95944c0c9750..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/bdist.pyi +++ /dev/null @@ -1,26 +0,0 @@ -from _typeshed import Unused -from collections.abc import Callable -from typing import ClassVar -from typing_extensions import deprecated - -from ..cmd import Command - -def show_formats() -> None: ... - -class ListCompat(dict[str, tuple[str, str]]): - @deprecated("format_commands is now a dict. append is deprecated") - def append(self, item: Unused) -> None: ... - -class bdist(Command): - description: ClassVar[str] - user_options: ClassVar[list[tuple[str, str | None, str]]] - boolean_options: ClassVar[list[str]] - help_options: ClassVar[list[tuple[str, str | None, str, Callable[[], Unused]]]] - no_format_option: ClassVar[tuple[str, ...]] - default_format: ClassVar[dict[str, str]] - format_commands: ClassVar[ListCompat] - format_command = format_commands - - def initialize_options(self) -> None: ... - def finalize_options(self) -> None: ... - def run(self) -> None: ... diff --git a/stubs/setuptools/setuptools/_distutils/command/bdist_rpm.pyi b/stubs/setuptools/setuptools/_distutils/command/bdist_rpm.pyi deleted file mode 100644 index fed7833ed5e9..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/bdist_rpm.pyi +++ /dev/null @@ -1,53 +0,0 @@ -from _typeshed import Incomplete -from typing import ClassVar - -from ..cmd import Command - -class bdist_rpm(Command): - description: ClassVar[str] - user_options: ClassVar[list[tuple[str, str | None, str]]] - boolean_options: ClassVar[list[str]] - negative_opt: ClassVar[dict[str, str]] - bdist_base: Incomplete - rpm_base: Incomplete - dist_dir: Incomplete - python: Incomplete - fix_python: Incomplete - spec_only: Incomplete - binary_only: Incomplete - source_only: Incomplete - use_bzip2: Incomplete - distribution_name: Incomplete - group: Incomplete - release: Incomplete - serial: Incomplete - vendor: Incomplete - packager: Incomplete - doc_files: Incomplete - changelog: Incomplete - icon: Incomplete - prep_script: Incomplete - build_script: Incomplete - install_script: Incomplete - clean_script: Incomplete - verify_script: Incomplete - pre_install: Incomplete - post_install: Incomplete - pre_uninstall: Incomplete - post_uninstall: Incomplete - prep: Incomplete - provides: Incomplete - requires: Incomplete - conflicts: Incomplete - build_requires: Incomplete - obsoletes: Incomplete - keep_temp: bool - use_rpm_opt_flags: bool - rpm3_mode: bool - no_autoreq: bool - force_arch: Incomplete - quiet: bool - def initialize_options(self) -> None: ... - def finalize_options(self) -> None: ... - def finalize_package_data(self) -> None: ... - def run(self) -> None: ... diff --git a/stubs/setuptools/setuptools/_distutils/command/build.pyi b/stubs/setuptools/setuptools/_distutils/command/build.pyi deleted file mode 100644 index c8a8bca6e61e..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/build.pyi +++ /dev/null @@ -1,32 +0,0 @@ -from _typeshed import Incomplete, Unused -from collections.abc import Callable -from typing import ClassVar - -from ..cmd import Command - -def show_compilers() -> None: ... - -class build(Command): - description: ClassVar[str] - user_options: ClassVar[list[tuple[str, str | None, str]]] - boolean_options: ClassVar[list[str]] - help_options: ClassVar[list[tuple[str, str | None, str, Callable[[], Unused]]]] - build_base: str - build_purelib: Incomplete - build_platlib: Incomplete - build_lib: Incomplete - build_temp: Incomplete - build_scripts: Incomplete - compiler: Incomplete - plat_name: Incomplete - debug: Incomplete - force: bool - executable: Incomplete - parallel: Incomplete - def initialize_options(self) -> None: ... - def finalize_options(self) -> None: ... - def run(self) -> None: ... - def has_pure_modules(self): ... - def has_c_libraries(self): ... - def has_ext_modules(self): ... - def has_scripts(self): ... diff --git a/stubs/setuptools/setuptools/_distutils/command/build_clib.pyi b/stubs/setuptools/setuptools/_distutils/command/build_clib.pyi deleted file mode 100644 index e416a6dfe44d..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/build_clib.pyi +++ /dev/null @@ -1,27 +0,0 @@ -from _typeshed import Incomplete, Unused -from collections.abc import Callable -from typing import ClassVar - -from ..cmd import Command - -class build_clib(Command): - description: ClassVar[str] - user_options: ClassVar[list[tuple[str, str, str]]] - boolean_options: ClassVar[list[str]] - help_options: ClassVar[list[tuple[str, str | None, str, Callable[[], Unused]]]] - build_clib: Incomplete - build_temp: Incomplete - libraries: Incomplete - include_dirs: Incomplete - define: Incomplete - undef: Incomplete - debug: Incomplete - force: bool - compiler: Incomplete - def initialize_options(self) -> None: ... - def finalize_options(self) -> None: ... - def run(self) -> None: ... - def check_library_list(self, libraries) -> None: ... - def get_library_names(self): ... - def get_source_files(self): ... - def build_libraries(self, libraries) -> None: ... diff --git a/stubs/setuptools/setuptools/_distutils/command/build_ext.pyi b/stubs/setuptools/setuptools/_distutils/command/build_ext.pyi deleted file mode 100644 index a37eb6d17c55..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/build_ext.pyi +++ /dev/null @@ -1,49 +0,0 @@ -from _typeshed import Incomplete, Unused -from collections.abc import Callable -from typing import ClassVar - -from ..cmd import Command -from ..extension import Extension - -class build_ext(Command): - description: ClassVar[str] - sep_by: Incomplete - user_options: ClassVar[list[tuple[str, str | None, str]]] - boolean_options: ClassVar[list[str]] - help_options: ClassVar[list[tuple[str, str | None, str, Callable[[], Unused]]]] - extensions: Incomplete - build_lib: Incomplete - plat_name: Incomplete - build_temp: Incomplete - inplace: bool - package: Incomplete - include_dirs: Incomplete - define: Incomplete - undef: Incomplete - libraries: Incomplete - library_dirs: Incomplete - rpath: Incomplete - link_objects: Incomplete - debug: Incomplete - force: Incomplete - compiler: Incomplete - swig: Incomplete - swig_cpp: Incomplete - swig_opts: Incomplete - user: Incomplete - parallel: Incomplete - def initialize_options(self) -> None: ... - def finalize_options(self) -> None: ... - def run(self) -> None: ... - def check_extensions_list(self, extensions) -> None: ... - def get_source_files(self): ... - def get_outputs(self): ... - def build_extensions(self) -> None: ... - def build_extension(self, ext) -> None: ... - def swig_sources(self, sources, extension): ... - def find_swig(self): ... - def get_ext_fullpath(self, ext_name: str) -> str: ... - def get_ext_fullname(self, ext_name: str) -> str: ... - def get_ext_filename(self, ext_name: str) -> str: ... - def get_export_symbols(self, ext: Extension) -> list[str]: ... - def get_libraries(self, ext: Extension) -> list[str]: ... diff --git a/stubs/setuptools/setuptools/_distutils/command/build_py.pyi b/stubs/setuptools/setuptools/_distutils/command/build_py.pyi deleted file mode 100644 index 967e27a32236..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/build_py.pyi +++ /dev/null @@ -1,39 +0,0 @@ -from _typeshed import Incomplete -from typing import ClassVar - -from ..cmd import Command - -class build_py(Command): - description: ClassVar[str] - user_options: ClassVar[list[tuple[str, str | None, str]]] - boolean_options: ClassVar[list[str]] - negative_opt: ClassVar[dict[str, str]] - build_lib: Incomplete - py_modules: Incomplete - package: Incomplete - package_data: Incomplete - package_dir: Incomplete - compile: bool - optimize: bool - force: Incomplete - def initialize_options(self) -> None: ... - packages: Incomplete - data_files: Incomplete - def finalize_options(self) -> None: ... - def run(self) -> None: ... - def get_data_files(self): ... - def find_data_files(self, package, src_dir): ... - def build_package_data(self) -> None: ... - def get_package_dir(self, package): ... - def check_package(self, package, package_dir): ... - def check_module(self, module, module_file): ... - def find_package_modules(self, package, package_dir): ... - def find_modules(self): ... - 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: bool = True) -> list[str]: ... - def build_module(self, module, module_file, package): ... - def build_modules(self) -> None: ... - def build_packages(self) -> None: ... - def byte_compile(self, files) -> None: ... diff --git a/stubs/setuptools/setuptools/_distutils/command/install.pyi b/stubs/setuptools/setuptools/_distutils/command/install.pyi deleted file mode 100644 index 059116834927..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/install.pyi +++ /dev/null @@ -1,59 +0,0 @@ -from _typeshed import Incomplete -from typing import ClassVar - -from ..cmd import Command - -class install(Command): - description: ClassVar[str] - user_options: ClassVar[list[tuple[str, str | None, str]]] - boolean_options: ClassVar[list[str]] - negative_opt: ClassVar[dict[str, str]] - prefix: str | None - exec_prefix: Incomplete - home: str | None - user: bool - install_base: Incomplete - install_platbase: Incomplete - root: str | None - install_purelib: Incomplete - install_platlib: Incomplete - install_headers: Incomplete - install_lib: str | None - install_scripts: Incomplete - install_data: Incomplete - install_userbase: Incomplete - install_usersite: Incomplete - compile: Incomplete - optimize: Incomplete - extra_path: Incomplete - install_path_file: bool - force: bool - skip_build: bool - warn_dir: bool - build_base: Incomplete - build_lib: Incomplete - record: Incomplete - def initialize_options(self) -> None: ... - config_vars: Incomplete - install_libbase: Incomplete - def finalize_options(self) -> None: ... - def dump_dirs(self, msg) -> None: ... - def finalize_unix(self) -> None: ... - def finalize_other(self) -> None: ... - def select_scheme(self, name) -> None: ... - def expand_basedirs(self) -> None: ... - def expand_dirs(self) -> None: ... - def convert_paths(self, *names) -> None: ... - path_file: Incomplete - extra_dirs: Incomplete - def handle_extra_path(self) -> None: ... - def change_roots(self, *names) -> None: ... - def create_home_path(self) -> None: ... - def run(self) -> None: ... - def create_path_file(self) -> None: ... - def get_outputs(self): ... - def get_inputs(self): ... - def has_lib(self): ... - def has_headers(self): ... - def has_scripts(self): ... - def has_data(self): ... diff --git a/stubs/setuptools/setuptools/_distutils/command/install_data.pyi b/stubs/setuptools/setuptools/_distutils/command/install_data.pyi deleted file mode 100644 index 777e28428fe6..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/install_data.pyi +++ /dev/null @@ -1,20 +0,0 @@ -from _typeshed import Incomplete -from typing import ClassVar - -from ..cmd import Command - -class install_data(Command): - description: ClassVar[str] - user_options: ClassVar[list[tuple[str, str | None, str]]] - boolean_options: Incomplete - install_dir: Incomplete - outfiles: Incomplete - root: Incomplete - force: bool - data_files: Incomplete - warn_dir: bool - def initialize_options(self) -> None: ... - def finalize_options(self) -> None: ... - def run(self) -> None: ... - def get_inputs(self): ... - def get_outputs(self): ... diff --git a/stubs/setuptools/setuptools/_distutils/command/install_lib.pyi b/stubs/setuptools/setuptools/_distutils/command/install_lib.pyi deleted file mode 100644 index 2494af393e19..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/install_lib.pyi +++ /dev/null @@ -1,24 +0,0 @@ -from _typeshed import Incomplete, MaybeNone -from typing import ClassVar - -from ..cmd import Command - -class install_lib(Command): - description: ClassVar[str] - user_options: ClassVar[list[tuple[str, str | None, str]]] - boolean_options: ClassVar[list[str]] - negative_opt: ClassVar[dict[str, str]] - install_dir: Incomplete - build_dir: Incomplete - force: bool - compile: Incomplete - optimize: Incomplete - skip_build: Incomplete - def initialize_options(self) -> None: ... - def finalize_options(self) -> None: ... - def run(self) -> None: ... - def build(self) -> None: ... - def install(self) -> list[str] | MaybeNone: ... - def byte_compile(self, files) -> None: ... - def get_outputs(self): ... - def get_inputs(self): ... diff --git a/stubs/setuptools/setuptools/_distutils/command/install_scripts.pyi b/stubs/setuptools/setuptools/_distutils/command/install_scripts.pyi deleted file mode 100644 index 356e8621ee10..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/install_scripts.pyi +++ /dev/null @@ -1,19 +0,0 @@ -from _typeshed import Incomplete -from typing import ClassVar - -from ..cmd import Command - -class install_scripts(Command): - description: ClassVar[str] - user_options: ClassVar[list[tuple[str, str | None, str]]] - boolean_options: ClassVar[list[str]] - install_dir: Incomplete - force: bool - build_dir: Incomplete - skip_build: Incomplete - def initialize_options(self) -> None: ... - def finalize_options(self) -> None: ... - outfiles: list[str] - def run(self) -> None: ... - def get_inputs(self): ... - def get_outputs(self): ... diff --git a/stubs/setuptools/setuptools/_distutils/command/sdist.pyi b/stubs/setuptools/setuptools/_distutils/command/sdist.pyi deleted file mode 100644 index 4dc38b055cc6..000000000000 --- a/stubs/setuptools/setuptools/_distutils/command/sdist.pyi +++ /dev/null @@ -1,46 +0,0 @@ -from _typeshed import Incomplete, Unused -from collections.abc import Callable -from typing import ClassVar - -from ..cmd import Command - -def show_formats() -> None: ... - -class sdist(Command): - description: ClassVar[str] - - def checking_metadata(self): ... - - user_options: ClassVar[list[tuple[str, str | None, str]]] - boolean_options: ClassVar[list[str]] - help_options: ClassVar[list[tuple[str, str | None, str, Callable[[], Unused]]]] - negative_opt: ClassVar[dict[str, str]] - READMES: ClassVar[tuple[str, ...]] - template: Incomplete - manifest: Incomplete - use_defaults: bool - prune: bool - manifest_only: bool - force_manifest: bool - formats: Incomplete - keep_temp: bool - dist_dir: Incomplete - archive_files: Incomplete - metadata_check: int # Soon to be updated to boolean upstream - owner: Incomplete - group: Incomplete - def initialize_options(self) -> None: ... - def finalize_options(self) -> None: ... - filelist: Incomplete - def run(self) -> None: ... - def get_file_list(self) -> None: ... - def add_defaults(self) -> None: ... - def read_template(self) -> None: ... - def prune_file_list(self) -> None: ... - def write_manifest(self) -> None: ... - def read_manifest(self) -> None: ... - def make_release_tree(self, base_dir, files) -> None: ... - def make_distribution(self) -> None: ... - def get_archive_files(self): ... - -def is_comment(line: str) -> bool: ... diff --git a/stubs/setuptools/setuptools/_distutils/compat/__init__.pyi b/stubs/setuptools/setuptools/_distutils/compat/__init__.pyi deleted file mode 100644 index 7325c194f699..000000000000 --- a/stubs/setuptools/setuptools/_distutils/compat/__init__.pyi +++ /dev/null @@ -1,6 +0,0 @@ -from collections.abc import Iterable -from typing import TypeVar - -_IterableT = TypeVar("_IterableT", bound=Iterable[str]) - -def consolidate_linker_args(args: _IterableT) -> _IterableT | str: ... diff --git a/stubs/setuptools/setuptools/_distutils/compilers/C/base.pyi b/stubs/setuptools/setuptools/_distutils/compilers/C/base.pyi deleted file mode 100644 index f33e86e6ba9f..000000000000 --- a/stubs/setuptools/setuptools/_distutils/compilers/C/base.pyi +++ /dev/null @@ -1,196 +0,0 @@ -from _typeshed import BytesPath, Incomplete, StrPath, Unused -from collections.abc import Callable, Iterable, MutableSequence, Sequence -from typing import ClassVar, Final, Literal, TypeVar, overload -from typing_extensions import TypeAlias, TypeVarTuple, Unpack - -_Macro: TypeAlias = tuple[str] | tuple[str, str | None] -_StrPathT = TypeVar("_StrPathT", bound=StrPath) -_BytesPathT = TypeVar("_BytesPathT", bound=BytesPath) -_Ts = TypeVarTuple("_Ts") - -class Compiler: - compiler_type: ClassVar[str] - executables: ClassVar[dict[str, Incomplete]] - - # Subclasses that rely on the standard filename generation methods - # implemented below should override these - src_extensions: ClassVar[list[str] | None] - obj_extension: ClassVar[str | None] - static_lib_extension: ClassVar[str | None] - shared_lib_extension: ClassVar[str | None] - static_lib_format: ClassVar[str | None] - shared_lib_format: ClassVar[str | None] - exe_extension: ClassVar[str | None] - - language_map: ClassVar[dict[str, str]] - language_order: ClassVar[list[str]] - dry_run: bool - force: bool - verbose: bool - output_dir: str | None - macros: list[_Macro] - include_dirs: list[str] - libraries: list[str] - library_dirs: list[str] - runtime_library_dirs: list[str] - objects: list[str] - - SHARED_OBJECT: Final = "shared_object" - SHARED_LIBRARY: Final = "shared_library" - EXECUTABLE: Final = "executable" - def __init__(self, verbose: bool = False, dry_run: bool = False, force: bool = False) -> 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: ... - def set_libraries(self, libnames: list[str]) -> None: ... - def add_library_dir(self, dir: str) -> None: ... - def set_library_dirs(self, dirs: list[str]) -> None: ... - def add_runtime_library_dir(self, dir: str) -> None: ... - def set_runtime_library_dirs(self, dirs: list[str]) -> None: ... - def define_macro(self, name: str, value: str | None = None) -> None: ... - def undefine_macro(self, name: str) -> None: ... - 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: Iterable[str], lib: str, debug: bool = False) -> str | None: ... - def has_function( - self, - funcname: str, - includes: Iterable[str] | None = None, - include_dirs: list[str] | tuple[str, ...] | None = None, - libraries: list[str] | None = None, - library_dirs: list[str] | tuple[str, ...] | None = None, - ) -> bool: ... - def library_dir_option(self, dir: str) -> str: ... - def library_option(self, lib: str) -> str: ... - def runtime_library_dir_option(self, dir: str) -> str: ... - def set_executables(self, **kwargs: str) -> None: ... - def set_executable(self, key: str, value) -> None: ... - def compile( - self, - sources: Sequence[StrPath], - output_dir: str | None = None, - macros: list[_Macro] | None = None, - include_dirs: list[str] | tuple[str, ...] | None = None, - debug: bool = False, - extra_preargs: list[str] | None = None, - extra_postargs: list[str] | None = None, - depends: list[str] | tuple[str, ...] | None = None, - ) -> list[str]: ... - def create_static_lib( - self, - objects: list[str] | tuple[str, ...], - output_libname: str, - output_dir: str | None = None, - debug: bool = False, - target_lang: str | None = None, - ) -> None: ... - def link( - self, - target_desc: str, - objects: list[str] | tuple[str, ...], - output_filename: str, - output_dir: str | None = None, - libraries: list[str] | tuple[str, ...] | None = None, - library_dirs: list[str] | tuple[str, ...] | None = None, - runtime_library_dirs: list[str] | tuple[str, ...] | None = None, - export_symbols: Iterable[str] | None = None, - debug: bool = False, - extra_preargs: list[str] | None = None, - extra_postargs: list[str] | None = None, - build_temp: StrPath | None = None, - target_lang: str | None = None, - ) -> None: ... - def link_executable( - self, - objects: list[str] | tuple[str, ...], - output_progname: str, - output_dir: str | None = None, - libraries: list[str] | tuple[str, ...] | None = None, - library_dirs: list[str] | tuple[str, ...] | None = None, - runtime_library_dirs: list[str] | tuple[str, ...] | None = None, - debug: bool = False, - extra_preargs: list[str] | None = None, - extra_postargs: list[str] | None = None, - target_lang: str | None = None, - ) -> None: ... - def link_shared_lib( - self, - objects: list[str] | tuple[str, ...], - output_libname: str, - output_dir: str | None = None, - libraries: list[str] | tuple[str, ...] | None = None, - library_dirs: list[str] | tuple[str, ...] | None = None, - runtime_library_dirs: list[str] | tuple[str, ...] | None = None, - export_symbols: Iterable[str] | None = None, - debug: bool = False, - extra_preargs: list[str] | None = None, - extra_postargs: list[str] | None = None, - build_temp: StrPath | None = None, - target_lang: str | None = None, - ) -> None: ... - def link_shared_object( - self, - objects: list[str] | tuple[str, ...], - output_filename: str, - output_dir: str | None = None, - libraries: list[str] | tuple[str, ...] | None = None, - library_dirs: list[str] | tuple[str, ...] | None = None, - runtime_library_dirs: list[str] | tuple[str, ...] | None = None, - export_symbols: Iterable[str] | None = None, - debug: bool = False, - extra_preargs: list[str] | None = None, - extra_postargs: list[str] | None = None, - build_temp: StrPath | None = None, - target_lang: str | None = None, - ) -> None: ... - def preprocess( - self, - source: StrPath, - output_file: StrPath | None = None, - macros: list[_Macro] | None = None, - include_dirs: list[str] | tuple[str, ...] | None = None, - extra_preargs: list[str] | None = None, - extra_postargs: Iterable[str] | None = None, - ) -> None: ... - @overload - def executable_filename(self, basename: str, strip_dir: Literal[False] = False, output_dir: StrPath = "") -> str: ... - @overload - def executable_filename(self, basename: StrPath, strip_dir: Literal[True], output_dir: StrPath = "") -> str: ... - def library_filename( - self, libname: str, lib_type: str = "static", strip_dir: bool = False, output_dir: StrPath = "" - ) -> str: ... - @property - def out_extensions(self) -> dict[str, str]: ... - def object_filenames( - self, source_filenames: Iterable[StrPath], strip_dir: bool = False, output_dir: StrPath | None = "" - ) -> list[str]: ... - @overload - def shared_object_filename(self, basename: str, strip_dir: Literal[False] = False, output_dir: StrPath = "") -> str: ... - @overload - def shared_object_filename(self, basename: StrPath, strip_dir: Literal[True], output_dir: StrPath = "") -> str: ... - def execute( - self, func: Callable[[Unpack[_Ts]], Unused], args: tuple[Unpack[_Ts]], msg: str | None = None, level: int = 1 - ) -> None: ... - def spawn(self, cmd: MutableSequence[bytes | StrPath]) -> None: ... - def mkpath(self, name: str, mode: int = 0o777) -> None: ... - @overload - def move_file(self, src: StrPath, dst: _StrPathT) -> _StrPathT | str: ... - @overload - def move_file(self, src: BytesPath, dst: _BytesPathT) -> _BytesPathT | bytes: ... - def announce(self, msg: str, level: int = 1) -> None: ... - def warn(self, msg: str) -> None: ... - def debug_print(self, msg: str) -> None: ... - -def get_default_compiler(osname: str | None = None, platform: str | None = None) -> str: ... - -compiler_class: dict[str, tuple[str, str, str]] - -def show_compilers() -> None: ... -def new_compiler( - plat: str | None = None, compiler: str | None = None, verbose: bool = False, dry_run: bool = False, force: bool = False -) -> Compiler: ... -def gen_preprocess_options(macros: Iterable[_Macro], include_dirs: Iterable[str]) -> list[str]: ... -def gen_lib_options( - compiler: Compiler, library_dirs: Iterable[str], runtime_library_dirs: Iterable[str], libraries: Iterable[str] -) -> list[str]: ... diff --git a/stubs/setuptools/setuptools/_distutils/compilers/C/errors.pyi b/stubs/setuptools/setuptools/_distutils/compilers/C/errors.pyi deleted file mode 100644 index 5c3cf1e9f0c6..000000000000 --- a/stubs/setuptools/setuptools/_distutils/compilers/C/errors.pyi +++ /dev/null @@ -1,6 +0,0 @@ -class Error(Exception): ... -class PreprocessError(Error): ... -class CompileError(Error): ... -class LibError(Error): ... -class LinkError(Error): ... -class UnknownFileType(Error): ... diff --git a/stubs/setuptools/setuptools/_distutils/compilers/C/msvc.pyi b/stubs/setuptools/setuptools/_distutils/compilers/C/msvc.pyi deleted file mode 100644 index 2b419aa986d7..000000000000 --- a/stubs/setuptools/setuptools/_distutils/compilers/C/msvc.pyi +++ /dev/null @@ -1,24 +0,0 @@ -from _typeshed import Incomplete -from typing import ClassVar, Final - -from . import base - -PLAT_SPEC_TO_RUNTIME: Final[dict[str, str]] - -class Compiler(base.Compiler): - compiler_type: ClassVar[str] - executables: ClassVar[dict[str, Incomplete]] - src_extensions: ClassVar[list[str]] - res_extension: ClassVar[str] - obj_extension: ClassVar[str] - static_lib_extension: ClassVar[str] - shared_lib_extension: ClassVar[str] - # This was accidentally removed upstream and should be back pretty soon. - # shared_lib_format: ClassVar[str] - # static_lib_format = shared_lib_format - static_lib_format: ClassVar[str] - exe_extension: ClassVar[str] - initialized: bool - def initialize(self, plat_name: str | None = None) -> None: ... - @property - def out_extensions(self) -> dict[str, str]: ... diff --git a/stubs/setuptools/setuptools/_distutils/dep_util.pyi b/stubs/setuptools/setuptools/_distutils/dep_util.pyi deleted file mode 100644 index 88cd92f00160..000000000000 --- a/stubs/setuptools/setuptools/_distutils/dep_util.pyi +++ /dev/null @@ -1 +0,0 @@ -from ._modified import newer as newer, newer_group as newer_group, newer_pairwise as newer_pairwise diff --git a/stubs/setuptools/setuptools/_distutils/dist.pyi b/stubs/setuptools/setuptools/_distutils/dist.pyi deleted file mode 100644 index 4552c94d8364..000000000000 --- a/stubs/setuptools/setuptools/_distutils/dist.pyi +++ /dev/null @@ -1,178 +0,0 @@ -from _typeshed import Incomplete, StrOrBytesPath, StrPath, SupportsWrite -from collections.abc import Iterable, MutableMapping -from re import Pattern -from typing import IO, ClassVar, Literal, TypeVar, overload -from typing_extensions import TypeAlias - -from .cmd import Command - -command_re: Pattern[str] - -_OptionsList: TypeAlias = list[tuple[str, str | None, str, int] | tuple[str, str | None, str]] -_CommandT = TypeVar("_CommandT", bound=Command) - -class DistributionMetadata: - def __init__(self, path: StrOrBytesPath | None = None) -> None: ... - name: str | None - version: str | None - author: str | None - author_email: str | None - maintainer: str | None - maintainer_email: str | None - url: str | None - license: str | None - description: str | None - long_description: str | None - keywords: str | list[str] | None - platforms: str | list[str] | None - classifiers: str | list[str] | None - download_url: str | None - provides: list[str] | None - requires: list[str] | None - obsoletes: list[str] | None - def read_pkg_file(self, file: IO[str]) -> None: ... - def write_pkg_info(self, base_dir: StrPath) -> None: ... - def write_pkg_file(self, file: SupportsWrite[str]) -> None: ... - def get_name(self) -> str: ... - def get_version(self) -> str: ... - def get_fullname(self) -> str: ... - def get_author(self) -> str | None: ... - def get_author_email(self) -> str | None: ... - def get_maintainer(self) -> str | None: ... - def get_maintainer_email(self) -> str | None: ... - def get_contact(self) -> str | None: ... - def get_contact_email(self) -> str | None: ... - def get_url(self) -> str | None: ... - def get_license(self) -> str | None: ... - get_licence = get_license - def get_description(self) -> str | None: ... - def get_long_description(self) -> str | None: ... - def get_keywords(self) -> str | list[str]: ... - def set_keywords(self, value: str | Iterable[str]) -> None: ... - def get_platforms(self) -> str | list[str] | None: ... - def set_platforms(self, value: str | Iterable[str]) -> None: ... - def get_classifiers(self) -> str | list[str]: ... - def set_classifiers(self, value): ... - def get_download_url(self) -> str | None: ... - def get_requires(self) -> str | list[str]: ... - def set_requires(self, value: Iterable[str]) -> None: ... - def get_provides(self) -> str | list[str]: ... - def set_provides(self, value: Iterable[str]) -> None: ... - def get_obsoletes(self) -> str | list[str]: ... - def set_obsoletes(self, value: Iterable[str]) -> None: ... - -class Distribution: - cmdclass: dict[str, type[Command]] - metadata: DistributionMetadata - def __init__(self, attrs: MutableMapping[str, Incomplete] | None = None) -> None: ... - def get_option_dict(self, command: str) -> dict[str, tuple[str, str]]: ... - def parse_config_files(self, filenames: Iterable[str] | None = None) -> None: ... - global_options: ClassVar[_OptionsList] - common_usage: ClassVar[str] - display_options: ClassVar[_OptionsList] - display_option_names: ClassVar[list[str]] - negative_opt: ClassVar[dict[str, str]] - verbose: bool - dry_run: bool - help: bool - command_packages: str | list[str] | None - script_name: StrPath | None - script_args: list[str] | None - command_options: dict[str, dict[str, tuple[str, str]]] - dist_files: list[tuple[str, str, str]] - packages: Incomplete - package_data: dict[str, list[str]] - package_dir: Incomplete - py_modules: Incomplete - libraries: Incomplete - headers: Incomplete - ext_modules: Incomplete - ext_package: Incomplete - include_dirs: Incomplete - extra_path: Incomplete - scripts: Incomplete - data_files: Incomplete - password: str - command_obj: dict[str, Command] - have_run: dict[str, bool] - want_user_cfg: bool - def dump_option_dicts( - self, header: Incomplete | None = None, commands: Incomplete | None = None, indent: str = "" - ) -> None: ... - def find_config_files(self): ... - commands: Incomplete - def parse_command_line(self): ... - def finalize_options(self) -> None: ... - def handle_display_options(self, option_order): ... - def print_command_list(self, commands, header, max_length) -> None: ... - def print_commands(self) -> None: ... - def get_command_list(self): ... - def get_command_packages(self): ... - # NOTE: Because this is private setuptools implementation and we don't re-expose all commands here, - # we're not overloading each and every command possibility. - @overload - def get_command_obj(self, command: str, create: Literal[True] = True) -> Command: ... - @overload - def get_command_obj(self, command: str, create: Literal[False]) -> Command | None: ... - def get_command_class(self, command: str) -> type[Command]: ... - @overload - def reinitialize_command(self, command: str, reinit_subcommands: bool = False) -> Command: ... - @overload - def reinitialize_command(self, command: _CommandT, reinit_subcommands: bool = False) -> _CommandT: ... - def announce(self, msg, level: int = 20) -> None: ... - def run_commands(self) -> None: ... - def run_command(self, command: str) -> None: ... - def has_pure_modules(self) -> bool: ... - def has_ext_modules(self) -> bool: ... - def has_c_libraries(self) -> bool: ... - def has_modules(self) -> bool: ... - def has_headers(self) -> bool: ... - def has_scripts(self) -> bool: ... - def has_data_files(self) -> bool: ... - def is_pure(self) -> bool: ... - - # Default getter methods generated in __init__ from self.metadata._METHOD_BASENAMES - def get_name(self) -> str: ... - def get_version(self) -> str: ... - def get_fullname(self) -> str: ... - def get_author(self) -> str: ... - def get_author_email(self) -> str: ... - def get_maintainer(self) -> str: ... - def get_maintainer_email(self) -> str: ... - def get_contact(self) -> str: ... - def get_contact_email(self) -> str: ... - def get_url(self) -> str: ... - def get_license(self) -> str: ... - def get_licence(self) -> str: ... - def get_description(self) -> str: ... - def get_long_description(self) -> str: ... - def get_keywords(self) -> str | list[str]: ... - def get_platforms(self) -> str | list[str]: ... - def get_classifiers(self) -> str | list[str]: ... - def get_download_url(self) -> str: ... - def get_requires(self) -> list[str]: ... - def get_provides(self) -> list[str]: ... - def get_obsoletes(self) -> list[str]: ... - - # Default attributes generated in __init__ from self.display_option_names - help_commands: bool - name: str | Literal[False] - version: str | Literal[False] - fullname: str | Literal[False] - author: str | Literal[False] - author_email: str | Literal[False] - maintainer: str | Literal[False] - maintainer_email: str | Literal[False] - contact: str | Literal[False] - contact_email: str | Literal[False] - url: str | Literal[False] - license: str | Literal[False] - licence: str | Literal[False] - description: str | Literal[False] - long_description: str | Literal[False] - platforms: str | list[str] | Literal[False] - classifiers: str | list[str] | Literal[False] - keywords: str | list[str] | Literal[False] - provides: list[str] | Literal[False] - requires: list[str] | Literal[False] - obsoletes: list[str] | Literal[False] diff --git a/stubs/setuptools/setuptools/_distutils/errors.pyi b/stubs/setuptools/setuptools/_distutils/errors.pyi deleted file mode 100644 index 79eb7f7baa0f..000000000000 --- a/stubs/setuptools/setuptools/_distutils/errors.pyi +++ /dev/null @@ -1,25 +0,0 @@ -from .compilers.C.errors import ( - CompileError as CompileError, - Error as _Error, - LibError as LibError, - LinkError as LinkError, - PreprocessError as PreprocessError, - UnknownFileType as _UnknownFileType, -) - -CCompilerError = _Error -UnknownFileError = _UnknownFileType - -class DistutilsError(Exception): ... -class DistutilsModuleError(DistutilsError): ... -class DistutilsClassError(DistutilsError): ... -class DistutilsGetoptError(DistutilsError): ... -class DistutilsArgError(DistutilsError): ... -class DistutilsFileError(DistutilsError): ... -class DistutilsOptionError(DistutilsError): ... -class DistutilsSetupError(DistutilsError): ... -class DistutilsPlatformError(DistutilsError): ... -class DistutilsExecError(DistutilsError): ... -class DistutilsInternalError(DistutilsError): ... -class DistutilsTemplateError(DistutilsError): ... -class DistutilsByteCompileError(DistutilsError): ... diff --git a/stubs/setuptools/setuptools/_distutils/extension.pyi b/stubs/setuptools/setuptools/_distutils/extension.pyi deleted file mode 100644 index 1aee26696a94..000000000000 --- a/stubs/setuptools/setuptools/_distutils/extension.pyi +++ /dev/null @@ -1,39 +0,0 @@ -from _typeshed import StrPath -from collections.abc import Iterable - -class Extension: - name: str - sources: list[str] - include_dirs: list[str] - define_macros: list[tuple[str, str | None]] - undef_macros: list[str] - library_dirs: list[str] - libraries: list[str] - runtime_library_dirs: list[str] - extra_objects: list[str] - extra_compile_args: list[str] - extra_link_args: list[str] - export_symbols: list[str] - swig_opts: list[str] - depends: list[str] - language: str | None - optional: bool | None - def __init__( - self, - name: str, - sources: Iterable[StrPath], - include_dirs: list[str] | None = None, - define_macros: list[tuple[str, str | None]] | None = None, - undef_macros: list[str] | None = None, - library_dirs: list[str] | None = None, - libraries: list[str] | None = None, - runtime_library_dirs: list[str] | None = None, - extra_objects: list[str] | None = None, - extra_compile_args: list[str] | None = None, - extra_link_args: list[str] | None = None, - export_symbols: list[str] | None = None, - swig_opts: list[str] | None = None, - depends: list[str] | None = None, - language: str | None = None, - optional: bool | None = None, - ) -> None: ... diff --git a/stubs/setuptools/setuptools/_distutils/filelist.pyi b/stubs/setuptools/setuptools/_distutils/filelist.pyi deleted file mode 100644 index a5be13d3ce7d..000000000000 --- a/stubs/setuptools/setuptools/_distutils/filelist.pyi +++ /dev/null @@ -1,38 +0,0 @@ -from _typeshed import StrPath, Unused -from collections.abc import Iterable -from re import Pattern -from typing import Literal, overload - -# class is entirely undocumented -class FileList: - allfiles: Iterable[str] | None - files: list[str] - def __init__(self, warn: Unused = None, debug_print: Unused = None) -> None: ... - def set_allfiles(self, allfiles: Iterable[str]) -> None: ... - def findall(self, dir: StrPath = ...) -> None: ... - def debug_print(self, msg: object) -> None: ... - def append(self, item: str) -> None: ... - def extend(self, items: Iterable[str]) -> None: ... - def sort(self) -> None: ... - def remove_duplicates(self) -> None: ... - def process_template_line(self, line: str) -> None: ... - @overload - def include_pattern( - self, pattern: str, anchor: bool = True, prefix: str | None = None, is_regex: Literal[False] = False - ) -> bool: ... - @overload - def include_pattern( - self, pattern: str | Pattern[str], anchor: bool = True, prefix: str | None = None, *, is_regex: Literal[True] - ) -> bool: ... - @overload - def include_pattern(self, pattern: str | Pattern[str], anchor: bool, prefix: str | None, is_regex: Literal[True]) -> bool: ... - @overload - def exclude_pattern( - self, pattern: str, anchor: bool = True, prefix: str | None = None, is_regex: Literal[False] = False - ) -> bool: ... - @overload - def exclude_pattern( - self, pattern: str | Pattern[str], anchor: bool = True, prefix: str | None = None, *, is_regex: Literal[True] - ) -> bool: ... - @overload - def exclude_pattern(self, pattern: str | Pattern[str], anchor: bool, prefix: str | None, is_regex: Literal[True]) -> bool: ... diff --git a/stubs/setuptools/setuptools/_distutils/spawn.pyi b/stubs/setuptools/setuptools/_distutils/spawn.pyi deleted file mode 100644 index 259a3a99d23b..000000000000 --- a/stubs/setuptools/setuptools/_distutils/spawn.pyi +++ /dev/null @@ -1,12 +0,0 @@ -from _typeshed import StrPath -from collections.abc import MutableSequence -from subprocess import _ENV - -def spawn( - cmd: MutableSequence[bytes | StrPath], - search_path: bool = True, - verbose: bool = False, - dry_run: bool = False, - env: _ENV | None = None, -) -> None: ... -def find_executable(executable: str, path: str | None = None) -> str | None: ... diff --git a/stubs/setuptools/setuptools/_distutils/sysconfig.pyi b/stubs/setuptools/setuptools/_distutils/sysconfig.pyi deleted file mode 100644 index b75ae74fcab8..000000000000 --- a/stubs/setuptools/setuptools/_distutils/sysconfig.pyi +++ /dev/null @@ -1,22 +0,0 @@ -from typing import Final, Literal, overload -from typing_extensions import deprecated - -from setuptools._distutils.ccompiler import CCompiler - -PREFIX: Final[str] -EXEC_PREFIX: Final[str] - -@overload -@deprecated("SO is deprecated, use EXT_SUFFIX. Support will be removed when this module is synchronized with stdlib Python 3.11") -def get_config_var(name: Literal["SO"]) -> int | str | None: ... -@overload -def get_config_var(name: str) -> int | str | None: ... -@overload -def get_config_vars() -> dict[str, str | int]: ... -@overload -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 = False, prefix: str | None = None) -> str: ... -def get_python_lib(plat_specific: bool = False, standard_lib: bool = False, prefix: str | None = None) -> str: ... -def customize_compiler(compiler: CCompiler) -> None: ... diff --git a/stubs/setuptools/setuptools/_distutils/util.pyi b/stubs/setuptools/setuptools/_distutils/util.pyi deleted file mode 100644 index 64ff78f3c04a..000000000000 --- a/stubs/setuptools/setuptools/_distutils/util.pyi +++ /dev/null @@ -1,38 +0,0 @@ -from _typeshed import GenericPath, StrPath, Unused -from collections.abc import Callable, Iterable, Mapping -from typing import AnyStr, Literal -from typing_extensions import TypeVarTuple, Unpack - -_Ts = TypeVarTuple("_Ts") - -def get_host_platform() -> str: ... -def get_platform() -> str: ... -def get_macosx_target_ver_from_syscfg(): ... -def get_macosx_target_ver(): ... -def split_version(s: str) -> list[int]: ... -def convert_path(pathname: StrPath) -> str: ... -def change_root(new_root: GenericPath[AnyStr], pathname: GenericPath[AnyStr]) -> AnyStr: ... -def check_environ() -> None: ... -def subst_vars(s: str, local_vars: Mapping[str, object]) -> str: ... -def grok_environment_error(exc: object, prefix: str = "error: ") -> str: ... -def split_quoted(s: str) -> list[str]: ... -def execute( - func: Callable[[Unpack[_Ts]], Unused], - args: tuple[Unpack[_Ts]], - msg: str | None = None, - verbose: bool = False, - dry_run: bool = False, -) -> None: ... -def strtobool(val: str) -> Literal[0, 1]: ... -def byte_compile( - py_files: Iterable[str], - optimize: int = 0, - force: bool = False, - prefix: str | None = None, - base_dir: str | None = None, - verbose: bool = True, - dry_run: bool = False, - direct: bool | None = None, -) -> None: ... -def rfc822_escape(header: str) -> str: ... -def is_mingw() -> bool: ... diff --git a/stubs/setuptools/setuptools/archive_util.pyi b/stubs/setuptools/setuptools/archive_util.pyi index 600586a65578..17eadfb48114 100644 --- a/stubs/setuptools/setuptools/archive_util.pyi +++ b/stubs/setuptools/setuptools/archive_util.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from collections.abc import Callable -from ._distutils.errors import DistutilsError +from setuptools._distutils.errors import DistutilsError __all__ = [ "unpack_archive", diff --git a/stubs/setuptools/setuptools/command/bdist_rpm.pyi b/stubs/setuptools/setuptools/command/bdist_rpm.pyi index cb79f3dbf156..695308540f28 100644 --- a/stubs/setuptools/setuptools/command/bdist_rpm.pyi +++ b/stubs/setuptools/setuptools/command/bdist_rpm.pyi @@ -1,7 +1,6 @@ +from setuptools._distutils.command import bdist_rpm as orig from setuptools.dist import Distribution -from .._distutils.command import bdist_rpm as orig - class bdist_rpm(orig.bdist_rpm): distribution: Distribution # override distutils.dist.Distribution with setuptools.dist.Distribution def run(self) -> None: ... diff --git a/stubs/setuptools/setuptools/command/build.pyi b/stubs/setuptools/setuptools/command/build.pyi index 5263a05bda51..6c5b44787629 100644 --- a/stubs/setuptools/setuptools/command/build.pyi +++ b/stubs/setuptools/setuptools/command/build.pyi @@ -1,9 +1,8 @@ from typing import Protocol +from setuptools._distutils.command.build import build as _build from setuptools.dist import Distribution -from .._distutils.command.build import build as _build - class build(_build): distribution: Distribution # override distutils.dist.Distribution with setuptools.dist.Distribution diff --git a/stubs/setuptools/setuptools/command/build_clib.pyi b/stubs/setuptools/setuptools/command/build_clib.pyi index 6f657c2c7c2f..ed9ff385c0d8 100644 --- a/stubs/setuptools/setuptools/command/build_clib.pyi +++ b/stubs/setuptools/setuptools/command/build_clib.pyi @@ -1,7 +1,6 @@ +from setuptools._distutils.command import build_clib as orig from setuptools.dist import Distribution -from .._distutils.command import build_clib as orig - class build_clib(orig.build_clib): distribution: Distribution # override distutils.dist.Distribution with setuptools.dist.Distribution diff --git a/stubs/setuptools/setuptools/command/build_ext.pyi b/stubs/setuptools/setuptools/command/build_ext.pyi index 6f4e74424a27..eedf4ced6b88 100644 --- a/stubs/setuptools/setuptools/command/build_ext.pyi +++ b/stubs/setuptools/setuptools/command/build_ext.pyi @@ -1,10 +1,9 @@ from _typeshed import Incomplete from typing import ClassVar +from setuptools._distutils.command.build_ext import build_ext as _build_ext from setuptools.dist import Distribution -from .._distutils.command.build_ext import build_ext as _build_ext - have_rtld: bool use_stubs: bool libtype: str diff --git a/stubs/setuptools/setuptools/command/build_py.pyi b/stubs/setuptools/setuptools/command/build_py.pyi index 7a2435bed01c..a419fc81f1f6 100644 --- a/stubs/setuptools/setuptools/command/build_py.pyi +++ b/stubs/setuptools/setuptools/command/build_py.pyi @@ -1,11 +1,10 @@ from _typeshed import Incomplete, StrPath, Unused from typing import ClassVar +from setuptools._distutils.cmd import _StrPathT +from setuptools._distutils.command import build_py as orig from setuptools.dist import Distribution -from .._distutils.cmd import _StrPathT -from .._distutils.command import build_py as orig - def make_writable(target) -> None: ... class build_py(orig.build_py): diff --git a/stubs/setuptools/setuptools/command/dist_info.pyi b/stubs/setuptools/setuptools/command/dist_info.pyi index 1343b926905b..89a37e6a08c1 100644 --- a/stubs/setuptools/setuptools/command/dist_info.pyi +++ b/stubs/setuptools/setuptools/command/dist_info.pyi @@ -1,6 +1,6 @@ from typing import ClassVar -from .._distutils.cmd import Command +from setuptools._distutils.cmd import Command class dist_info(Command): description: str diff --git a/stubs/setuptools/setuptools/command/easy_install.pyi b/stubs/setuptools/setuptools/command/easy_install.pyi index 0255102d8d8b..b089dac08b58 100644 --- a/stubs/setuptools/setuptools/command/easy_install.pyi +++ b/stubs/setuptools/setuptools/command/easy_install.pyi @@ -1,6 +1,6 @@ from _typeshed import Incomplete from collections.abc import Iterable, Iterator -from typing import Any, ClassVar, Literal, NoReturn, TypedDict +from typing import Any, ClassVar, NoReturn, TypedDict from typing_extensions import Self from pkg_resources import Distribution, Environment @@ -44,7 +44,7 @@ class easy_install(Command): pth_file: Incomplete site_dirs: Incomplete installed_projects: Incomplete - verbose: bool | Literal[0, 1] + verbose: bool def initialize_options(self) -> None: ... def delete_blockers(self, blockers) -> None: ... config_vars: dict[str, Any] diff --git a/stubs/setuptools/setuptools/command/egg_info.pyi b/stubs/setuptools/setuptools/command/egg_info.pyi index db57845ec268..276c99374f13 100644 --- a/stubs/setuptools/setuptools/command/egg_info.pyi +++ b/stubs/setuptools/setuptools/command/egg_info.pyi @@ -1,8 +1,9 @@ from _typeshed import Incomplete from typing import ClassVar, Final +from setuptools._distutils.filelist import FileList as _FileList + from .. import Command, SetuptoolsDeprecationWarning -from .._distutils.filelist import FileList as _FileList from .sdist import sdist PY_MAJOR: Final[str] diff --git a/stubs/setuptools/setuptools/command/install.pyi b/stubs/setuptools/setuptools/command/install.pyi index 064c11a6dd69..fb5e28e1f48f 100644 --- a/stubs/setuptools/setuptools/command/install.pyi +++ b/stubs/setuptools/setuptools/command/install.pyi @@ -2,10 +2,9 @@ from _typeshed import Incomplete from collections.abc import Callable from typing import Any, ClassVar +from setuptools._distutils.command import install as orig from setuptools.dist import Distribution -from .._distutils.command import install as orig - class install(orig.install): distribution: Distribution # override distutils.dist.Distribution with setuptools.dist.Distribution user_options: ClassVar[list[tuple[str, str | None, str]]] diff --git a/stubs/setuptools/setuptools/command/install_lib.pyi b/stubs/setuptools/setuptools/command/install_lib.pyi index a7576d20a35a..ace0cbc1ae12 100644 --- a/stubs/setuptools/setuptools/command/install_lib.pyi +++ b/stubs/setuptools/setuptools/command/install_lib.pyi @@ -1,9 +1,8 @@ from _typeshed import StrPath, Unused +from setuptools._distutils.command import install_lib as orig from setuptools.dist import Distribution -from .._distutils.command import install_lib as orig - class install_lib(orig.install_lib): distribution: Distribution # override distutils.dist.Distribution with setuptools.dist.Distribution def run(self) -> None: ... diff --git a/stubs/setuptools/setuptools/command/install_scripts.pyi b/stubs/setuptools/setuptools/command/install_scripts.pyi index f131b0f7c4fa..994d32a1bd59 100644 --- a/stubs/setuptools/setuptools/command/install_scripts.pyi +++ b/stubs/setuptools/setuptools/command/install_scripts.pyi @@ -1,7 +1,6 @@ +from setuptools._distutils.command import install_scripts as orig from setuptools.dist import Distribution -from .._distutils.command import install_scripts as orig - class install_scripts(orig.install_scripts): distribution: Distribution # override distutils.dist.Distribution with setuptools.dist.Distribution no_ep: bool diff --git a/stubs/setuptools/setuptools/command/sdist.pyi b/stubs/setuptools/setuptools/command/sdist.pyi index 77c87df95d0b..66d76f45bc25 100644 --- a/stubs/setuptools/setuptools/command/sdist.pyi +++ b/stubs/setuptools/setuptools/command/sdist.pyi @@ -2,10 +2,9 @@ from _typeshed import Incomplete from collections.abc import Iterator from typing import ClassVar +from setuptools._distutils.command import sdist as orig from setuptools.dist import Distribution -from .._distutils.command import sdist as orig - def walk_revctrl(dirname: str = "") -> Iterator[Incomplete]: ... class sdist(orig.sdist): diff --git a/stubs/setuptools/setuptools/config/setupcfg.pyi b/stubs/setuptools/setuptools/config/setupcfg.pyi index 7c78eefd9250..f2d2f7943038 100644 --- a/stubs/setuptools/setuptools/config/setupcfg.pyi +++ b/stubs/setuptools/setuptools/config/setupcfg.pyi @@ -4,7 +4,8 @@ from collections.abc import Callable, Iterable from typing import Any, ClassVar, Generic, TypeVar from typing_extensions import TypeAlias -from .._distutils.dist import DistributionMetadata +from setuptools._distutils.dist import DistributionMetadata + from ..dist import Distribution from . import expand diff --git a/stubs/setuptools/setuptools/dist.pyi b/stubs/setuptools/setuptools/dist.pyi index 928c55c7131a..c607da02ce03 100644 --- a/stubs/setuptools/setuptools/dist.pyi +++ b/stubs/setuptools/setuptools/dist.pyi @@ -2,9 +2,10 @@ from _typeshed import Incomplete, StrPath from collections.abc import Iterable, Iterator, MutableMapping from typing import Literal, TypeVar, overload +from setuptools._distutils.cmd import Command as _Command +from setuptools._distutils.dist import Distribution as _Distribution + from . import Command, SetuptoolsDeprecationWarning -from ._distutils.cmd import Command as _Command -from ._distutils.dist import Distribution as _Distribution from .command.alias import alias from .command.bdist_egg import bdist_egg from .command.bdist_rpm import bdist_rpm diff --git a/stubs/setuptools/setuptools/errors.pyi b/stubs/setuptools/setuptools/errors.pyi index 9723a11d514f..a6925c880aab 100644 --- a/stubs/setuptools/setuptools/errors.pyi +++ b/stubs/setuptools/setuptools/errors.pyi @@ -1,4 +1,4 @@ -from ._distutils import errors as _distutils_errors +from setuptools._distutils import errors as _distutils_errors ByteCompileError = _distutils_errors.DistutilsByteCompileError CCompilerError = _distutils_errors.CCompilerError diff --git a/stubs/setuptools/setuptools/extension.pyi b/stubs/setuptools/setuptools/extension.pyi index 0f9c99214ad2..a9041cd1f035 100644 --- a/stubs/setuptools/setuptools/extension.pyi +++ b/stubs/setuptools/setuptools/extension.pyi @@ -1,7 +1,7 @@ from _typeshed import StrPath from collections.abc import Iterable -from ._distutils.extension import Extension as _Extension +from setuptools._distutils.extension import Extension as _Extension def have_pyrex() -> bool: ... diff --git a/stubs/setuptools/setuptools/modified.pyi b/stubs/setuptools/setuptools/modified.pyi index 0437d4efc3ed..822ba183ae6e 100644 --- a/stubs/setuptools/setuptools/modified.pyi +++ b/stubs/setuptools/setuptools/modified.pyi @@ -1,3 +1,3 @@ -from ._distutils._modified import newer, newer_group, newer_pairwise, newer_pairwise_group +from setuptools._distutils._modified import newer, newer_group, newer_pairwise, newer_pairwise_group __all__ = ["newer", "newer_pairwise", "newer_group", "newer_pairwise_group"] diff --git a/stubs/setuptools/setuptools/sandbox.pyi b/stubs/setuptools/setuptools/sandbox.pyi index ee5935c056ec..c5e93461870e 100644 --- a/stubs/setuptools/setuptools/sandbox.pyi +++ b/stubs/setuptools/setuptools/sandbox.pyi @@ -3,7 +3,7 @@ from types import TracebackType from typing import ClassVar from typing_extensions import Self -from ._distutils.errors import DistutilsError +from setuptools._distutils.errors import DistutilsError __all__ = ["AbstractSandbox", "DirectorySandbox", "SandboxViolation", "run_setup"] diff --git a/tests/check_typeshed_structure.py b/tests/check_typeshed_structure.py index 81adb8c74269..edce2106d020 100755 --- a/tests/check_typeshed_structure.py +++ b/tests/check_typeshed_structure.py @@ -90,13 +90,27 @@ def check_tests_dir(tests_dir: Path) -> None: def check_distutils() -> None: """Check whether all setuptools._distutils files are re-exported from distutils.""" - def all_relative_paths_in_directory(path: Path) -> set[Path]: - return {pyi.relative_to(path) for pyi in path.rglob("*.pyi")} + def is_exposed_module(relative_to: Path, path: Path) -> bool: + # This feels hacky, but it is code hyper-specific to setuptools/_distutils after all. + relative_path = path.relative_to(relative_to) + if relative_path.parts[0] in {"_msvccompiler.py", "__init__.py"}: + return True + return not any([part in {"tests", "compat"} or part.startswith("_") for part in relative_path.parts]) - setuptools_path = STUBS_PATH / "setuptools" / "setuptools" / "_distutils" + def all_setuptools_distutils_relative_paths(path: Path) -> set[Path]: + return {file.relative_to(path).with_suffix(".pyi") for file in path.rglob("*.py") if is_exposed_module(path, file)} + + def all_distutils_stub_relative_paths(path: Path) -> set[Path]: + return {file.relative_to(path) for file in path.rglob("*.pyi")} + + from importlib.util import find_spec + + setuptools_distutils_spec = find_spec("setuptools._distutils") + assert setuptools_distutils_spec and setuptools_distutils_spec.origin, "Is setuptools installed?" + setuptools_path = Path(setuptools_distutils_spec.origin).parent distutils_path = STUBS_PATH / "setuptools" / "distutils" - all_setuptools_files = all_relative_paths_in_directory(setuptools_path) - all_distutils_files = all_relative_paths_in_directory(distutils_path) + all_setuptools_files = all_setuptools_distutils_relative_paths(setuptools_path) + all_distutils_files = all_distutils_stub_relative_paths(distutils_path) assert all_setuptools_files and all_distutils_files, "Looks like this test might be out of date!" extra_files = all_setuptools_files - all_distutils_files joined = "\n".join(f" * {distutils_path / f}" for f in extra_files) diff --git a/tests/mypy_test.py b/tests/mypy_test.py index b5e91bd8af58..371b376b4d0d 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -5,26 +5,23 @@ import argparse import concurrent.futures -import functools import os import subprocess import sys import tempfile import time from collections import defaultdict -from collections.abc import Generator from dataclasses import dataclass -from enum import Enum from itertools import product from pathlib import Path from threading import Lock -from typing import Any, NamedTuple +from typing import NamedTuple from typing_extensions import Annotated, TypeAlias -import tomli from packaging.requirements import Requirement -from ts_utils.metadata import PackageDependencies, get_recursive_requirements, metadata_path, read_metadata +from ts_utils.metadata import PackageDependencies, get_recursive_requirements, read_metadata +from ts_utils.mypy import MypyDistConf, MypyResult, mypy_configuration_from_distribution, temporary_mypy_config_file from ts_utils.paths import STDLIB_PATH, STUBS_PATH, TESTS_DIR, TS_BASE_PATH, distribution_path from ts_utils.utils import ( PYTHON_VERSION, @@ -46,24 +43,6 @@ print_error("Cannot import mypy. Did you install it?") sys.exit(1) -# We need to work around a limitation of tempfile.NamedTemporaryFile on Windows -# For details, see https://github.com/python/typeshed/pull/13620#discussion_r1990185997 -# Python 3.12 added a workaround with `tempfile.NamedTemporaryFile("w+", delete_on_close=False)` -if sys.platform != "win32": - _named_temporary_file = functools.partial(tempfile.NamedTemporaryFile, "w+") -else: - from contextlib import contextmanager - - @contextmanager - def _named_temporary_file() -> Generator[tempfile._TemporaryFileWrapper[str]]: # pyright: ignore[reportPrivateUsage] - temp = tempfile.NamedTemporaryFile("w+", delete=False) # noqa: SIM115 - try: - yield temp - finally: - temp.close() - os.remove(temp.name) - - SUPPORTED_VERSIONS = ["3.13", "3.12", "3.11", "3.10", "3.9"] SUPPORTED_PLATFORMS = ("linux", "win32", "darwin") DIRECTORIES_TO_TEST = [STDLIB_PATH, STUBS_PATH] @@ -177,50 +156,6 @@ def add_files(files: list[Path], module: Path, args: TestConfig) -> None: files.extend(sorted(file for file in module.rglob("*.pyi") if match(file, args))) -class MypyDistConf(NamedTuple): - module_name: str - values: dict[str, dict[str, Any]] - - -# The configuration section in the metadata file looks like the following, with multiple module sections possible -# [mypy-tests] -# [mypy-tests.yaml] -# module_name = "yaml" -# [mypy-tests.yaml.values] -# disallow_incomplete_defs = true -# disallow_untyped_defs = true - - -def add_configuration(configurations: list[MypyDistConf], distribution: str) -> None: - with metadata_path(distribution).open("rb") as f: - data = tomli.load(f) - - # TODO: This could be added to ts_utils.metadata, but is currently unused - mypy_tests_conf: dict[str, dict[str, Any]] = data.get("mypy-tests", {}) - if not mypy_tests_conf: - return - - assert isinstance(mypy_tests_conf, dict), "mypy-tests should be a section" - for section_name, mypy_section in mypy_tests_conf.items(): - assert isinstance(mypy_section, dict), f"{section_name} should be a section" - module_name = mypy_section.get("module_name") - - assert module_name is not None, f"{section_name} should have a module_name key" - assert isinstance(module_name, str), f"{section_name} should be a key-value pair" - - assert "values" in mypy_section, f"{section_name} should have a values section" - values: dict[str, dict[str, Any]] = mypy_section["values"] - assert isinstance(values, dict), "values should be a section" - - configurations.append(MypyDistConf(module_name, values.copy())) - - -class MypyResult(Enum): - SUCCESS = 0 - FAILURE = 1 - CRASH = 2 - - def run_mypy( args: TestConfig, configurations: list[MypyDistConf], @@ -234,15 +169,7 @@ def run_mypy( env_vars = dict(os.environ) if mypypath is not None: env_vars["MYPYPATH"] = mypypath - - with _named_temporary_file() as temp: - temp.write("[mypy]\n") - for dist_conf in configurations: - temp.write(f"[mypy-{dist_conf.module_name}]\n") - for k, v in dist_conf.values.items(): - temp.write(f"{k} = {v}\n") - temp.flush() - + with temporary_mypy_config_file(configurations) as temp: flags = [ "--python-version", args.version, @@ -278,29 +205,27 @@ def run_mypy( if args.verbose: print(colored(f"running {' '.join(mypy_command)}", "blue")) result = subprocess.run(mypy_command, capture_output=True, text=True, env=env_vars) - if result.returncode: - print_error(f"failure (exit code {result.returncode})\n") - if result.stdout: - print_error(result.stdout) - if result.stderr: - print_error(result.stderr) - if non_types_dependencies and args.verbose: - print("Ran with the following environment:") - subprocess.run(["uv", "pip", "freeze"], env={**os.environ, "VIRTUAL_ENV": str(venv_dir)}) - print() - else: - print_success_msg() - if result.returncode == 0: - return MypyResult.SUCCESS - elif result.returncode == 1: - return MypyResult.FAILURE - else: - return MypyResult.CRASH + if result.returncode: + print_error(f"failure (exit code {result.returncode})\n") + if result.stdout: + print_error(result.stdout) + if result.stderr: + print_error(result.stderr) + if non_types_dependencies and args.verbose: + print("Ran with the following environment:") + subprocess.run(["uv", "pip", "freeze"], env={**os.environ, "VIRTUAL_ENV": str(venv_dir)}) + print() + else: + print_success_msg() + if result.returncode == 0: + return MypyResult.SUCCESS + elif result.returncode == 1: + return MypyResult.FAILURE + else: + return MypyResult.CRASH -def add_third_party_files( - distribution: str, files: list[Path], args: TestConfig, configurations: list[MypyDistConf], seen_dists: set[str] -) -> None: +def add_third_party_files(distribution: str, files: list[Path], args: TestConfig, seen_dists: set[str]) -> None: typeshed_reqs = get_recursive_requirements(distribution).typeshed_pkgs if distribution in seen_dists: return @@ -311,7 +236,6 @@ def add_third_party_files( if name.startswith("."): continue add_files(files, (root / name), args) - add_configuration(configurations, distribution) class TestResult(NamedTuple): @@ -328,9 +252,9 @@ def test_third_party_distribution( and the second element is the number of checked files. """ files: list[Path] = [] - configurations: list[MypyDistConf] = [] seen_dists: set[str] = set() - add_third_party_files(distribution, files, args, configurations, seen_dists) + add_third_party_files(distribution, files, args, seen_dists) + configurations = mypy_configuration_from_distribution(distribution) if not files and args.filter: return TestResult(MypyResult.SUCCESS, 0) diff --git a/tests/regr_test.py b/tests/regr_test.py index 248708b90d64..af90d529afaf 100755 --- a/tests/regr_test.py +++ b/tests/regr_test.py @@ -22,6 +22,7 @@ from typing_extensions import TypeAlias from ts_utils.metadata import get_recursive_requirements, read_metadata +from ts_utils.mypy import mypy_configuration_from_distribution, temporary_mypy_config_file from ts_utils.paths import STDLIB_PATH, TEST_CASES_DIR, TS_BASE_PATH, distribution_path from ts_utils.utils import ( PYTHON_VERSION, @@ -169,62 +170,71 @@ def run_testcases( env_vars = dict(os.environ) new_test_case_dir = tempdir / TEST_CASES_DIR - # "--enable-error-code ignore-without-code" is purposefully omitted. - # See https://github.com/python/typeshed/pull/8083 - flags = [ - "--python-version", - version, - "--show-traceback", - "--no-error-summary", - "--platform", - platform, - "--strict", - "--pretty", - # Avoid race conditions when reading the cache - # (https://github.com/python/typeshed/issues/11220) - "--no-incremental", - # Not useful for the test cases - "--disable-error-code=empty-body", - ] - if package.is_stdlib: - python_exe = sys.executable - custom_typeshed = TS_BASE_PATH - flags.append("--no-site-packages") + configurations = [] else: - custom_typeshed = tempdir / TYPESHED - env_vars["MYPYPATH"] = os.pathsep.join(map(str, custom_typeshed.glob("stubs/*"))) - has_non_types_dependencies = (tempdir / VENV_DIR).exists() - if has_non_types_dependencies: - python_exe = str(venv_python(tempdir / VENV_DIR)) - else: + configurations = mypy_configuration_from_distribution(package.name) + + with temporary_mypy_config_file(configurations) as temp: + + # "--enable-error-code ignore-without-code" is purposefully omitted. + # See https://github.com/python/typeshed/pull/8083 + flags = [ + "--python-version", + version, + "--show-traceback", + "--no-error-summary", + "--platform", + platform, + "--strict", + "--pretty", + "--config-file", + temp.name, + # Avoid race conditions when reading the cache + # (https://github.com/python/typeshed/issues/11220) + "--no-incremental", + # Not useful for the test cases + "--disable-error-code=empty-body", + ] + + if package.is_stdlib: python_exe = sys.executable + custom_typeshed = TS_BASE_PATH flags.append("--no-site-packages") - - flags.extend(["--custom-typeshed-dir", str(custom_typeshed)]) - - # If the test-case filename ends with -py39, - # only run the test if --python-version was set to 3.9 or higher (for example) - for path in new_test_case_dir.rglob("*.py"): - if match := re.fullmatch(r".*-py3(\d{1,2})", path.stem): - minor_version_required = int(match[1]) - assert f"3.{minor_version_required}" in SUPPORTED_VERSIONS - python_minor_version = int(version.split(".")[1]) - if minor_version_required > python_minor_version: - continue - flags.append(str(path)) - - mypy_command = [python_exe, "-m", "mypy", *flags] - if verbosity is Verbosity.VERBOSE: - description = f"{package.name}/{version}/{platform}" - msg = f"{description}: {mypy_command=}\n" - if "MYPYPATH" in env_vars: - msg += f"{description}: {env_vars['MYPYPATH']=}" else: - msg += f"{description}: MYPYPATH not set" - msg += "\n" - verbose_log(msg) - return subprocess.run(mypy_command, capture_output=True, text=True, env=env_vars) + custom_typeshed = tempdir / TYPESHED + env_vars["MYPYPATH"] = os.pathsep.join(map(str, custom_typeshed.glob("stubs/*"))) + has_non_types_dependencies = (tempdir / VENV_DIR).exists() + if has_non_types_dependencies: + python_exe = str(venv_python(tempdir / VENV_DIR)) + else: + python_exe = sys.executable + flags.append("--no-site-packages") + + flags.extend(["--custom-typeshed-dir", str(custom_typeshed)]) + + # If the test-case filename ends with -py39, + # only run the test if --python-version was set to 3.9 or higher (for example) + for path in new_test_case_dir.rglob("*.py"): + if match := re.fullmatch(r".*-py3(\d{1,2})", path.stem): + minor_version_required = int(match[1]) + assert f"3.{minor_version_required}" in SUPPORTED_VERSIONS + python_minor_version = int(version.split(".")[1]) + if minor_version_required > python_minor_version: + continue + flags.append(str(path)) + + mypy_command = [python_exe, "-m", "mypy", *flags] + if verbosity is Verbosity.VERBOSE: + description = f"{package.name}/{version}/{platform}" + msg = f"{description}: {mypy_command=}\n" + if "MYPYPATH" in env_vars: + msg += f"{description}: {env_vars['MYPYPATH']=}" + else: + msg += f"{description}: MYPYPATH not set" + msg += "\n" + verbose_log(msg) + return subprocess.run(mypy_command, capture_output=True, text=True, env=env_vars) @dataclass(frozen=True) diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index a83d4fbc572f..1489efb4548c 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -16,6 +16,7 @@ from typing import NoReturn from ts_utils.metadata import NoSuchStubError, get_recursive_requirements, read_metadata +from ts_utils.mypy import mypy_configuration_from_distribution, temporary_mypy_config_file from ts_utils.paths import STUBS_PATH, allowlists_path, tests_path from ts_utils.utils import ( PYTHON_VERSION, @@ -103,89 +104,93 @@ def run_stubtest( print_command_failure("Failed to install", e) return False - ignore_missing_stub = ["--ignore-missing-stub"] if stubtest_settings.ignore_missing_stub else [] - packages_to_check = [d.name for d in dist.iterdir() if d.is_dir() and d.name.isidentifier()] - modules_to_check = [d.stem for d in dist.iterdir() if d.is_file() and d.suffix == ".pyi"] - stubtest_cmd = [ - python_exe, - "-m", - "mypy.stubtest", - # Use --custom-typeshed-dir in case we make linked changes to stdlib or _typeshed - "--custom-typeshed-dir", - str(dist.parent.parent), - *ignore_missing_stub, - *packages_to_check, - *modules_to_check, - *allowlist_stubtest_arguments(dist_name), - ] - - stubs_dir = dist.parent - mypypath_items = [str(dist)] + [str(stubs_dir / pkg.name) for pkg in requirements.typeshed_pkgs] - mypypath = os.pathsep.join(mypypath_items) - # For packages that need a display, we need to pass at least $DISPLAY - # to stubtest. $DISPLAY is set by xvfb-run in CI. - # - # It seems that some other environment variables are needed too, - # because the CI fails if we pass only os.environ["DISPLAY"]. I didn't - # "bisect" to see which variables are actually needed. - stubtest_env = os.environ | {"MYPYPATH": mypypath, "MYPY_FORCE_COLOR": "1"} - - # Perform some black magic in order to run stubtest inside uWSGI - if dist_name == "uWSGI": - if not setup_uwsgi_stubtest_command(dist, venv_dir, stubtest_cmd): - return False - - if dist_name == "gdb": - if not setup_gdb_stubtest_command(venv_dir, stubtest_cmd): - return False + mypy_configuration = mypy_configuration_from_distribution(dist_name) + with temporary_mypy_config_file(mypy_configuration) as temp: + ignore_missing_stub = ["--ignore-missing-stub"] if stubtest_settings.ignore_missing_stub else [] + packages_to_check = [d.name for d in dist.iterdir() if d.is_dir() and d.name.isidentifier()] + modules_to_check = [d.stem for d in dist.iterdir() if d.is_file() and d.suffix == ".pyi"] + stubtest_cmd = [ + python_exe, + "-m", + "mypy.stubtest", + "--mypy-config-file", + temp.name, + # Use --custom-typeshed-dir in case we make linked changes to stdlib or _typeshed + "--custom-typeshed-dir", + str(dist.parent.parent), + *ignore_missing_stub, + *packages_to_check, + *modules_to_check, + *allowlist_stubtest_arguments(dist_name), + ] + + stubs_dir = dist.parent + mypypath_items = [str(dist)] + [str(stubs_dir / pkg.name) for pkg in requirements.typeshed_pkgs] + mypypath = os.pathsep.join(mypypath_items) + # For packages that need a display, we need to pass at least $DISPLAY + # to stubtest. $DISPLAY is set by xvfb-run in CI. + # + # It seems that some other environment variables are needed too, + # because the CI fails if we pass only os.environ["DISPLAY"]. I didn't + # "bisect" to see which variables are actually needed. + stubtest_env = os.environ | {"MYPYPATH": mypypath, "MYPY_FORCE_COLOR": "1"} + + # Perform some black magic in order to run stubtest inside uWSGI + if dist_name == "uWSGI": + if not setup_uwsgi_stubtest_command(dist, venv_dir, stubtest_cmd): + return False + + if dist_name == "gdb": + if not setup_gdb_stubtest_command(venv_dir, stubtest_cmd): + return False + + try: + subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True) + except subprocess.CalledProcessError as e: + print_time(time() - t) + print_error("fail") + + print_divider() + print("Commands run:") + print_commands(pip_cmd, stubtest_cmd, mypypath) + + print_divider() + print("Command output:\n") + print_command_output(e) + + print_divider() + print("Python version: ", end="", flush=True) + ret = subprocess.run([sys.executable, "-VV"], capture_output=True) + print_command_output(ret) - try: - subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True) - except subprocess.CalledProcessError as e: - print_time(time() - t) - print_error("fail") - - print_divider() - print("Commands run:") - print_commands(pip_cmd, stubtest_cmd, mypypath) - - print_divider() - print("Command output:\n") - print_command_output(e) - - print_divider() - print("Python version: ", end="", flush=True) - ret = subprocess.run([sys.executable, "-VV"], capture_output=True) - print_command_output(ret) - - print("\nRan with the following environment:") - ret = subprocess.run([pip_exe, "freeze", "--all"], capture_output=True) - print_command_output(ret) - if keep_tmp_dir: - print("Path to virtual environment:", venv_dir, flush=True) - - print_divider() - main_allowlist_path = allowlists_path(dist_name) / "stubtest_allowlist.txt" - if main_allowlist_path.exists(): - print(f'To fix "unused allowlist" errors, remove the corresponding entries from {main_allowlist_path}') - print() - else: - print(f"Re-running stubtest with --generate-allowlist.\nAdd the following to {main_allowlist_path}:") - ret = subprocess.run([*stubtest_cmd, "--generate-allowlist"], env=stubtest_env, capture_output=True) + print("\nRan with the following environment:") + ret = subprocess.run([pip_exe, "freeze", "--all"], capture_output=True) print_command_output(ret) + if keep_tmp_dir: + print("Path to virtual environment:", venv_dir, flush=True) - print_divider() - print(f"Upstream repository: {metadata.upstream_repository}") - print(f"Typeshed source code: https://github.com/python/typeshed/tree/main/stubs/{dist.name}") + print_divider() + main_allowlist_path = allowlists_path(dist_name) / "stubtest_allowlist.txt" + if main_allowlist_path.exists(): + print(f'To fix "unused allowlist" errors, remove the corresponding entries from {main_allowlist_path}') + print() + else: + print(f"Re-running stubtest with --generate-allowlist.\nAdd the following to {main_allowlist_path}:") + ret = subprocess.run([*stubtest_cmd, "--generate-allowlist"], env=stubtest_env, capture_output=True) + print_command_output(ret) - print_divider() + print_divider() + print(f"Upstream repository: {metadata.upstream_repository}") + print(f"Typeshed source code: https://github.com/python/typeshed/tree/main/stubs/{dist.name}") - return False - else: - print_time(time() - t) - print_success_msg() - if keep_tmp_dir: - print_info(f"Virtual environment kept at: {venv_dir}") + print_divider() + + return False + else: + print_time(time() - t) + print_success_msg() + if keep_tmp_dir: + print_info(f"Virtual environment kept at: {venv_dir}") finally: if not keep_tmp_dir: rmtree(venv_dir)