From ec253ca68189333af503fb6a84847ff7e46fe0f6 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 17 Apr 2023 17:37:34 -0400 Subject: [PATCH 1/6] Don't ignore missing stubs in setuptools --- .../setuptools/@tests/stubtest_allowlist.txt | 55 ++++++----- stubs/setuptools/METADATA.toml | 3 - stubs/setuptools/pkg_resources/__init__.pyi | 91 +++++++++++++------ stubs/setuptools/setuptools/__init__.pyi | 29 +++--- .../_distutils/command/bdist_rpm.pyi | 52 +++++++++++ .../setuptools/_distutils/command/build.pyi | 30 ++++++ .../setuptools/_distutils/errors.pyi | 18 ++++ stubs/setuptools/setuptools/archive_util.pyi | 10 ++ stubs/setuptools/setuptools/build_meta.pyi | 19 +++- stubs/setuptools/setuptools/command/alias.pyi | 2 +- .../setuptools/command/bdist_egg.pyi | 49 ++++++++++ .../setuptools/command/bdist_rpm.pyi | 4 + stubs/setuptools/setuptools/command/build.pyi | 16 ++++ .../setuptools/command/build_ext.pyi | 4 +- .../setuptools/command/build_py.pyi | 6 +- .../setuptools/setuptools/command/develop.pyi | 4 +- .../setuptools/command/dist_info.pyi | 4 +- .../setuptools/command/easy_install.pyi | 5 +- .../setuptools/command/editable_wheel.pyi | 77 ++++++++++++++++ .../setuptools/command/egg_info.pyi | 8 +- .../setuptools/command/install_egg_info.pyi | 2 +- .../setuptools/setuptools/command/rotate.pyi | 2 +- .../setuptools/command/saveopts.pyi | 2 +- .../setuptools/setuptools/command/setopt.pyi | 4 +- stubs/setuptools/setuptools/command/test.pyi | 2 +- stubs/setuptools/setuptools/config.pyi | 2 - .../setuptools/setuptools/config/__init__.pyi | 9 ++ stubs/setuptools/setuptools/config/expand.pyi | 50 ++++++++++ .../setuptools/config/pyprojecttoml.pyi | 51 +++++++++++ .../setuptools/setuptools/config/setupcfg.pyi | 83 +++++++++++++++++ stubs/setuptools/setuptools/depends.pyi | 6 ++ stubs/setuptools/setuptools/discovery.pyi | 45 +++++++++ stubs/setuptools/setuptools/dist.pyi | 5 +- stubs/setuptools/setuptools/errors.pyi | 23 ++++- stubs/setuptools/setuptools/glob.pyi | 2 + stubs/setuptools/setuptools/logging.pyi | 2 + stubs/setuptools/setuptools/package_index.pyi | 2 + stubs/setuptools/setuptools/sandbox.pyi | 25 ++++- stubs/setuptools/setuptools/wheel.pyi | 2 + 39 files changed, 711 insertions(+), 94 deletions(-) create mode 100644 stubs/setuptools/setuptools/_distutils/command/bdist_rpm.pyi create mode 100644 stubs/setuptools/setuptools/_distutils/command/build.pyi create mode 100644 stubs/setuptools/setuptools/command/bdist_egg.pyi create mode 100644 stubs/setuptools/setuptools/command/bdist_rpm.pyi create mode 100644 stubs/setuptools/setuptools/command/build.pyi create mode 100644 stubs/setuptools/setuptools/command/editable_wheel.pyi delete mode 100644 stubs/setuptools/setuptools/config.pyi create mode 100644 stubs/setuptools/setuptools/config/__init__.pyi create mode 100644 stubs/setuptools/setuptools/config/expand.pyi create mode 100644 stubs/setuptools/setuptools/config/pyprojecttoml.pyi create mode 100644 stubs/setuptools/setuptools/config/setupcfg.pyi create mode 100644 stubs/setuptools/setuptools/discovery.pyi create mode 100644 stubs/setuptools/setuptools/logging.pyi diff --git a/stubs/setuptools/@tests/stubtest_allowlist.txt b/stubs/setuptools/@tests/stubtest_allowlist.txt index 33deae5b6aa0..12eb997b38a5 100644 --- a/stubs/setuptools/@tests/stubtest_allowlist.txt +++ b/stubs/setuptools/@tests/stubtest_allowlist.txt @@ -1,27 +1,18 @@ -pkg_resources.Distribution.__cmp__ -pkg_resources.Distribution.activate -pkg_resources.Distribution.get_entry_map -pkg_resources.EggMetadata.__init__ -pkg_resources.Environment.best_match -pkg_resources.Environment.obtain -pkg_resources.FileMetadata.__init__ +# These are used like protocols, but forgot to specify "self" as the first method param +pkg_resources.IResourceProvider.get_resource_filename +pkg_resources.IResourceProvider.get_resource_stream +pkg_resources.IResourceProvider.get_resource_string +pkg_resources.IResourceProvider.has_resource +pkg_resources.IResourceProvider.resource_isdir +pkg_resources.IResourceProvider.resource_listdir pkg_resources.IMetadataProvider.get_metadata pkg_resources.IMetadataProvider.get_metadata_lines pkg_resources.IMetadataProvider.has_metadata pkg_resources.IMetadataProvider.metadata_isdir pkg_resources.IMetadataProvider.metadata_listdir pkg_resources.IMetadataProvider.run_script +# @type_check_only pkg_resources.IResourceManager -pkg_resources.Requirement.__init__ -pkg_resources.WorkingSet.find_plugins -pkg_resources.WorkingSet.resolve -pkg_resources.WorkingSet.subscribe -pkg_resources.declare_namespace -pkg_resources.fixup_namespace_packages -pkg_resources.get_entry_map -pkg_resources.get_provider -pkg_resources.split_sections -pkg_resources.to_filename # Is always set in __init__ pkg_resources.PathMetadata.egg_info @@ -53,16 +44,24 @@ setuptools._distutils.dist.Distribution.get_requires setuptools._distutils.dist.Distribution.get_provides setuptools._distutils.dist.Distribution.get_obsoletes -# Uncomment once ignore_missing_stub is turned off -# # Not supported by typeshed -# setuptools.py34compat +# Not supported by typeshed +setuptools.py34compat +setuptools.command.py36compat -# # Private modules -# setuptools.config._validate_pyproject.* -# setuptools.build_meta._BuildMetaBackend.* +# Private modules +setuptools.config._validate_pyproject.* +setuptools.command.build_py.build_py.existing_egg_info_dir -# # Vendored and modified version of stdlib's distutils. Basically implementation details -# setuptools._distutils.* -# # Other vendored code -# setuptools._vendor.* -# pkg_resources._vendor.* +# Loop variable leak +setuptools.sandbox.AbstractSandbox.name + +# Vendored and modified version of stdlib's distutils. Basically implementation details +setuptools._distutils.* +# Other vendored code +setuptools._vendor.* +pkg_resources._vendor.* +# Deprecated in favor of importlib.resources, importlib.metadata and their backports +# So like distutils, we only add what we need to reference. +pkg_resources.AvailableDistributions +pkg_resources.ResourceManager +pkg_resources.extern diff --git a/stubs/setuptools/METADATA.toml b/stubs/setuptools/METADATA.toml index d67b34ab7833..fa9a86f13825 100644 --- a/stubs/setuptools/METADATA.toml +++ b/stubs/setuptools/METADATA.toml @@ -1,4 +1 @@ version = "67.6.*" - -[tool.stubtest] -ignore_missing_stub = true diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index df0fa6aca79a..424984b45ca0 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -6,7 +6,7 @@ from abc import ABCMeta from collections.abc import Callable, Generator, Iterable, Sequence from io import BytesIO from re import Pattern -from typing import IO, Any, ClassVar, TypeVar, overload +from typing import IO, Any, ClassVar, Protocol, TypeVar, overload, type_check_only from typing_extensions import Literal, Self, TypeAlias _Version: TypeAlias = Incomplete # from packaging.version @@ -21,8 +21,8 @@ _PkgReqType: TypeAlias = str | Requirement _DistFinderType: TypeAlias = Callable[[_Importer, str, bool], Generator[Distribution, None, None]] _NSHandlerType: TypeAlias = Callable[[_Importer, str, str, types.ModuleType], str] -def declare_namespace(name: str) -> None: ... -def fixup_namespace_packages(path_item: str) -> None: ... +def declare_namespace(packageName: str) -> None: ... +def fixup_namespace_packages(path_item: str, parent=None) -> None: ... class WorkingSet: entries: list[str] @@ -35,24 +35,30 @@ class WorkingSet: def __iter__(self) -> Generator[Distribution, None, None]: ... def find(self, req: Requirement) -> Distribution | None: ... def resolve( - self, requirements: Iterable[Requirement], env: Environment | None = None, installer: _InstallerType | None = None + self, + requirements: Iterable[Requirement], + env: Environment | None = None, + installer: _InstallerType | None = None, + replace_conflicting=False, + extras=None, ) -> list[Distribution]: ... def add(self, dist: Distribution, entry: str | None = None, insert: bool = True, replace: bool = False) -> None: ... - def subscribe(self, callback: Callable[[Distribution], object]) -> None: ... + def subscribe(self, callback: Callable[[Distribution], object], existing=True) -> None: ... def find_plugins( - self, plugin_env: Environment, full_env: Environment | None = None, fallback: bool = True + self, plugin_env: Environment, full_env: Environment | None = None, installer=None, fallback: bool = True ) -> tuple[list[Distribution], dict[Distribution, Exception]]: ... working_set: WorkingSet require = working_set.require run_script = working_set.run_script +run_main = run_script iter_entry_points = working_set.iter_entry_points add_activation_listener = working_set.subscribe class Environment: def __init__( - self, search_path: Sequence[str] | None = None, platform: str | None = ..., python: str | None = ... + self, search_path: Sequence[str] | None = None, platform: str | None = ..., python: str | None = "3.9" ) -> None: ... def __getitem__(self, project_name: str) -> list[Distribution]: ... def __iter__(self) -> Generator[str, None, None]: ... @@ -62,13 +68,15 @@ class Environment: def __add__(self, other: Distribution | Environment) -> Environment: ... def __iadd__(self, other: Distribution | Environment) -> Self: ... @overload - def best_match(self, req: Requirement, working_set: WorkingSet, *, replace_conflicting: bool = False) -> Distribution: ... + def best_match( + self, req: Requirement, working_set: WorkingSet, installer: None = None, replace_conflicting: bool = False + ) -> Distribution: ... @overload def best_match( self, req: Requirement, working_set: WorkingSet, installer: Callable[[Requirement], _T], replace_conflicting: bool = False ) -> _T: ... @overload - def obtain(self, requirement: Requirement) -> None: ... + def obtain(self, requirement: Requirement, installer: None = None) -> None: ... @overload def obtain(self, requirement: Requirement, installer: Callable[[Requirement], _T]) -> _T: ... def scan(self, search_path: Sequence[str] | None = None) -> None: ... @@ -89,6 +97,7 @@ class Requirement: # TODO: change this to packaging.markers.Marker | None once we can import # packaging.markers marker: Incomplete | None + def __init__(self, requirement_string) -> None: ... @staticmethod def parse(s: str | Iterable[str]) -> Requirement: ... def __contains__(self, item: Distribution | str | tuple[str, ...]) -> bool: ... @@ -97,11 +106,12 @@ class Requirement: def load_entry_point(dist: _EPDistType, group: str, name: str) -> Any: ... def get_entry_info(dist: _EPDistType, group: str, name: str) -> EntryPoint | None: ... @overload -def get_entry_map(dist: _EPDistType) -> dict[str, dict[str, EntryPoint]]: ... +def get_entry_map(dist: _EPDistType, group: None = None) -> dict[str, dict[str, EntryPoint]]: ... @overload def get_entry_map(dist: _EPDistType, group: str) -> dict[str, EntryPoint]: ... class EntryPoint: + pattern: ClassVar[Pattern[str]] name: str module_name: str attrs: tuple[str, ...] @@ -133,11 +143,21 @@ def get_distribution(dist: _D) -> _D: ... @overload def get_distribution(dist: _PkgReqType) -> Distribution: ... -class Distribution(NullProvider, IResourceProvider, IMetadataProvider): +# Doesn't actually extend NullProvider +class Distribution(NullProvider): PKG_INFO: ClassVar[str] location: str project_name: str @property + def hashcmp(self) -> tuple[Incomplete, int, str, Incomplete | None, str, str]: ... + def __hash__(self) -> int: ... + def __lt__(self, other) -> bool: ... + def __le__(self, other) -> bool: ... + def __gt__(self, other) -> bool: ... + def __ge__(self, other) -> bool: ... + def __eq__(self, other) -> bool: ... + def __ne__(self, other) -> bool: ... + @property def key(self) -> str: ... @property def extras(self) -> list[str]: ... @@ -164,15 +184,17 @@ class Distribution(NullProvider, IResourceProvider, IMetadataProvider): ) -> Distribution: ... @classmethod def from_filename(cls, filename: str, metadata: _MetadataType = None, **kw: str | None | int) -> Distribution: ... - def activate(self, path: list[str] | None = None) -> None: ... + def activate(self, path: list[str] | None = None, replace=False) -> None: ... def as_requirement(self) -> Requirement: ... def requires(self, extras: tuple[str, ...] = ()) -> list[Requirement]: ... + def check_version_conflict(self) -> None: ... + def has_version(self) -> bool: ... def clone(self, **kw: str | int | None) -> Requirement: ... def egg_name(self) -> str: ... # type: ignore[override] # supertype's egg_name is a variable, not a method - def __cmp__(self, other: Any) -> bool: ... def get_entry_info(self, group: str, name: str) -> EntryPoint | None: ... + def insert_on(self, path, loc: Incomplete | None = None, replace: bool = False) -> None: ... @overload - def get_entry_map(self) -> dict[str, dict[str, EntryPoint]]: ... + def get_entry_map(self, group: None = None) -> dict[str, dict[str, EntryPoint]]: ... @overload def get_entry_map(self, group: str) -> dict[str, EntryPoint]: ... def load_entry_point(self, group: str, name: str) -> Any: ... @@ -191,8 +213,8 @@ def resource_listdir(package_or_requirement: _PkgReqType, resource_name: str) -> def resource_filename(package_or_requirement: _PkgReqType, resource_name: str) -> str: ... def set_extraction_path(path: str) -> None: ... def cleanup_resources(force: bool = False) -> list[str]: ... - -class IResourceManager: +@type_check_only +class IResourceManager(Protocol): def resource_exists(self, package_or_requirement: _PkgReqType, resource_name: str) -> bool: ... def resource_stream(self, package_or_requirement: _PkgReqType, resource_name: str) -> IO[bytes]: ... def resource_string(self, package_or_requirement: _PkgReqType, resource_name: str) -> bytes: ... @@ -206,11 +228,11 @@ class IResourceManager: def postprocess(self, tempname: str, filename: str) -> None: ... @overload -def get_provider(package_or_requirement: str) -> IResourceProvider: ... +def get_provider(moduleOrReq: str) -> IResourceProvider: ... @overload -def get_provider(package_or_requirement: Requirement) -> Distribution: ... +def get_provider(moduleOrReq: Requirement) -> Distribution: ... -class IMetadataProvider: +class IMetadataProvider(Protocol): def has_metadata(self, name: str) -> bool | None: ... def metadata_isdir(self, name: str) -> bool: ... def metadata_listdir(self, name: str) -> list[str]: ... @@ -254,7 +276,16 @@ def register_finder(importer_type: type, distribution_finder: _DistFinderType) - def register_loader_type(loader_type: type, provider_factory: Callable[[types.ModuleType], IResourceProvider]) -> None: ... def register_namespace_handler(importer_type: type, namespace_handler: _NSHandlerType) -> None: ... -class IResourceProvider(IMetadataProvider): ... +class IResourceProvider(IMetadataProvider, Protocol): + def get_resource_filename(self, manager, resource_name): ... + def get_resource_stream(self, manager, resource_name): ... + def get_resource_string(self, manager, resource_name): ... + def has_resource(self, resource_name): ... + def resource_isdir(self, resource_name): ... + def resource_listdir(self, resource_name): ... + +def invalid_marker(text) -> SyntaxError | Literal[False]: ... +def evaluate_marker(text, extra: Incomplete | None = None): ... class NullProvider: egg_name: str | None @@ -281,7 +312,7 @@ class EggProvider(NullProvider): class DefaultProvider(EggProvider): ... -class PathMetadata(DefaultProvider, IResourceProvider): +class PathMetadata(DefaultProvider): egg_info: str module_path: str def __init__(self, path: str, egg_info: str) -> None: ... @@ -289,11 +320,13 @@ class PathMetadata(DefaultProvider, IResourceProvider): class ZipProvider(EggProvider): eagers: list[str] | None zip_pre: str + @property + def zipinfo(self): ... -class EggMetadata(ZipProvider, IResourceProvider): +class EggMetadata(ZipProvider): loader: zipimport.zipimporter module_path: str - def __init__(self, zipimporter: zipimport.zipimporter) -> None: ... + def __init__(self, importer: zipimport.zipimporter) -> None: ... class EmptyProvider(NullProvider): module_path: None @@ -301,17 +334,19 @@ class EmptyProvider(NullProvider): empty_provider: EmptyProvider -class FileMetadata(EmptyProvider, IResourceProvider): - def __init__(self, path_to_pkg_info: str) -> None: ... +class FileMetadata(EmptyProvider): + def __init__(self, path: str) -> None: ... + +class PEP440Warning(RuntimeWarning): ... parse_version = _Version def yield_lines(iterable: _NestedStr) -> Generator[str, None, None]: ... -def split_sections(strs: _NestedStr) -> Generator[tuple[str | None, list[str]], None, None]: ... +def split_sections(s: _NestedStr) -> Generator[tuple[str | None, list[str]], None, None]: ... def safe_name(name: str) -> str: ... def safe_version(version: str) -> str: ... def safe_extra(extra: str) -> str: ... -def to_filename(name_or_version: str) -> str: ... +def to_filename(name: str) -> str: ... def get_build_platform() -> str: ... def get_platform() -> str: ... def get_supported_platform() -> str: ... @@ -320,3 +355,5 @@ def get_default_cache() -> str: ... def get_importer(path_item: str) -> _Importer: ... def ensure_directory(path: str) -> None: ... def normalize_path(filename: str) -> str: ... + +class PkgResourcesDeprecationWarning(Warning): ... diff --git a/stubs/setuptools/setuptools/__init__.pyi b/stubs/setuptools/setuptools/__init__.pyi index 0fef3642e449..86f68333f4de 100644 --- a/stubs/setuptools/setuptools/__init__.pyi +++ b/stubs/setuptools/setuptools/__init__.pyi @@ -1,21 +1,26 @@ from abc import abstractmethod -from collections.abc import Iterable, Mapping, Sequence +from collections.abc import Mapping, Sequence from typing import Any -from setuptools._deprecation_warning import SetuptoolsDeprecationWarning as SetuptoolsDeprecationWarning -from setuptools.depends import Require as Require -from setuptools.dist import Distribution as Distribution -from setuptools.extension import Extension as Extension - +from ._deprecation_warning import SetuptoolsDeprecationWarning as SetuptoolsDeprecationWarning from ._distutils.cmd import Command as _Command +from .depends import Require as Require +from .discovery import PackageFinder, PEP420PackageFinder +from .dist import Distribution as Distribution +from .extension import Extension as Extension -__version__: str - -class PackageFinder: - @classmethod - def find(cls, where: str = ".", exclude: Iterable[str] = (), include: Iterable[str] = ("*",)) -> list[str]: ... +__all__ = [ + "setup", + "Distribution", + "Command", + "Extension", + "Require", + "SetuptoolsDeprecationWarning", + "find_packages", + "find_namespace_packages", +] -class PEP420PackageFinder(PackageFinder): ... +__version__: str find_packages = PackageFinder.find find_namespace_packages = PEP420PackageFinder.find diff --git a/stubs/setuptools/setuptools/_distutils/command/bdist_rpm.pyi b/stubs/setuptools/setuptools/_distutils/command/bdist_rpm.pyi new file mode 100644 index 000000000000..929b1b4a97a7 --- /dev/null +++ b/stubs/setuptools/setuptools/_distutils/command/bdist_rpm.pyi @@ -0,0 +1,52 @@ +from _typeshed import Incomplete + +from ..cmd import Command + +class bdist_rpm(Command): + description: str + user_options: Incomplete + boolean_options: Incomplete + negative_opt: Incomplete + 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: int + use_rpm_opt_flags: int + rpm3_mode: int + no_autoreq: int + force_arch: Incomplete + quiet: int + 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 new file mode 100644 index 000000000000..02f82169ae2c --- /dev/null +++ b/stubs/setuptools/setuptools/_distutils/command/build.pyi @@ -0,0 +1,30 @@ +from _typeshed import Incomplete + +from ..cmd import Command + +def show_compilers() -> None: ... + +class build(Command): + description: str + user_options: Incomplete + boolean_options: Incomplete + help_options: Incomplete + 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: int + 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/errors.pyi b/stubs/setuptools/setuptools/_distutils/errors.pyi index d19ac8b04eaa..e483362bfbf1 100644 --- a/stubs/setuptools/setuptools/_distutils/errors.pyi +++ b/stubs/setuptools/setuptools/_distutils/errors.pyi @@ -1 +1,19 @@ 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): ... +class CCompilerError(Exception): ... +class PreprocessError(CCompilerError): ... +class CompileError(CCompilerError): ... +class LibError(CCompilerError): ... +class LinkError(CCompilerError): ... +class UnknownFileError(CCompilerError): ... diff --git a/stubs/setuptools/setuptools/archive_util.pyi b/stubs/setuptools/setuptools/archive_util.pyi index b11be8191cb3..44fe556de4b5 100644 --- a/stubs/setuptools/setuptools/archive_util.pyi +++ b/stubs/setuptools/setuptools/archive_util.pyi @@ -3,6 +3,16 @@ from typing import Any from ._distutils.errors import DistutilsError +__all__ = [ + "unpack_archive", + "unpack_zipfile", + "unpack_tarfile", + "default_filter", + "UnrecognizedFormat", + "extraction_drivers", + "unpack_directory", +] + class UnrecognizedFormat(DistutilsError): ... def default_filter(src, dst): ... diff --git a/stubs/setuptools/setuptools/build_meta.pyi b/stubs/setuptools/setuptools/build_meta.pyi index f4f632db2479..90004985a700 100644 --- a/stubs/setuptools/setuptools/build_meta.pyi +++ b/stubs/setuptools/setuptools/build_meta.pyi @@ -1,7 +1,20 @@ from collections.abc import Mapping from typing import Any -from setuptools import dist +from . import dist + +__all__ = [ + "get_requires_for_build_sdist", + "get_requires_for_build_wheel", + "prepare_metadata_for_build_wheel", + "build_wheel", + "build_sdist", + "get_requires_for_build_editable", + "prepare_metadata_for_build_editable", + "build_editable", + "__legacy__", + "SetupRequirementsError", +] class SetupRequirementsError(BaseException): specifiers: Any @@ -41,4 +54,8 @@ prepare_metadata_for_build_wheel = _BACKEND.prepare_metadata_for_build_wheel build_wheel = _BACKEND.build_wheel build_sdist = _BACKEND.build_sdist +get_requires_for_build_editable = _BACKEND.get_requires_for_build_editable +prepare_metadata_for_build_editable = _BACKEND.prepare_metadata_for_build_editable +build_editable = _BACKEND.build_editable + __legacy__: _BuildMetaLegacyBackend diff --git a/stubs/setuptools/setuptools/command/alias.pyi b/stubs/setuptools/setuptools/command/alias.pyi index ff79d933a431..6486ffaa845a 100644 --- a/stubs/setuptools/setuptools/command/alias.pyi +++ b/stubs/setuptools/setuptools/command/alias.pyi @@ -1,6 +1,6 @@ from typing import Any -from setuptools.command.setopt import option_base +from .setopt import option_base def shquote(arg): ... diff --git a/stubs/setuptools/setuptools/command/bdist_egg.pyi b/stubs/setuptools/setuptools/command/bdist_egg.pyi new file mode 100644 index 000000000000..2b6276bbea85 --- /dev/null +++ b/stubs/setuptools/setuptools/command/bdist_egg.pyi @@ -0,0 +1,49 @@ +from _typeshed import Incomplete +from collections.abc import Generator + +from .. import Command + +def strip_module(filename): ... +def sorted_walk(dir) -> Generator[Incomplete, None, None]: ... +def write_stub(resource, pyfile) -> None: ... + +class bdist_egg(Command): + description: str + user_options: Incomplete + boolean_options: Incomplete + bdist_dir: Incomplete + plat_name: Incomplete + keep_temp: int + dist_dir: Incomplete + skip_build: int + egg_output: Incomplete + exclude_source_files: Incomplete + def initialize_options(self) -> None: ... + egg_info: Incomplete + def finalize_options(self) -> None: ... + def do_install_data(self) -> None: ... + def get_outputs(self): ... + def call_command(self, cmdname, **kw): ... + stubs: Incomplete + def run(self) -> None: ... + def zap_pyfiles(self) -> None: ... + def zip_safe(self): ... + def gen_header(self): ... + def copy_metadata_to(self, target_dir) -> None: ... + def get_ext_outputs(self): ... + +NATIVE_EXTENSIONS: Incomplete + +def walk_egg(egg_dir) -> Generator[Incomplete, None, None]: ... +def analyze_egg(egg_dir, stubs): ... +def write_safety_flag(egg_dir, safe) -> None: ... + +safety_flags: Incomplete + +def scan_module(egg_dir, base, name, stubs): ... +def iter_symbols(code) -> Generator[Incomplete, None, None]: ... +def can_scan(): ... + +INSTALL_DIRECTORY_ATTRS: Incomplete + +def make_zipfile(zip_filename, base_dir, verbose: int = 0, dry_run: int = 0, compress: bool = True, mode: str = "w"): ... diff --git a/stubs/setuptools/setuptools/command/bdist_rpm.pyi b/stubs/setuptools/setuptools/command/bdist_rpm.pyi new file mode 100644 index 000000000000..31de5b470555 --- /dev/null +++ b/stubs/setuptools/setuptools/command/bdist_rpm.pyi @@ -0,0 +1,4 @@ +from .._distutils.command import bdist_rpm as orig + +class bdist_rpm(orig.bdist_rpm): + def run(self) -> None: ... diff --git a/stubs/setuptools/setuptools/command/build.pyi b/stubs/setuptools/setuptools/command/build.pyi new file mode 100644 index 000000000000..6319600c1ed6 --- /dev/null +++ b/stubs/setuptools/setuptools/command/build.pyi @@ -0,0 +1,16 @@ +from typing import Protocol + +from .._distutils.command.build import build as _build + +class build(_build): + def get_sub_commands(self): ... + +class SubCommand(Protocol): + editable_mode: bool + build_lib: str + def initialize_options(self) -> None: ... + def finalize_options(self) -> None: ... + def run(self) -> None: ... + def get_source_files(self) -> list[str]: ... + def get_outputs(self) -> list[str]: ... + def get_output_mapping(self) -> dict[str, str]: ... diff --git a/stubs/setuptools/setuptools/command/build_ext.pyi b/stubs/setuptools/setuptools/command/build_ext.pyi index b2ceb17bc2bc..21973fb79d8b 100644 --- a/stubs/setuptools/setuptools/command/build_ext.pyi +++ b/stubs/setuptools/setuptools/command/build_ext.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from typing import Any +from typing import Any, ClassVar from .._distutils.command.build_ext import build_ext as _build_ext @@ -11,6 +11,7 @@ def if_dl(s): ... def get_abi3_suffix(): ... class build_ext(_build_ext): + editable_mode: ClassVar[bool] inplace: Any def run(self) -> None: ... def copy_extensions_to_source(self) -> None: ... @@ -27,6 +28,7 @@ class build_ext(_build_ext): def build_extension(self, ext) -> None: ... def links_to_dynamic(self, ext): ... def get_outputs(self): ... + def get_output_mapping(self) -> dict[str, str]: ... def write_stub(self, output_dir, ext, compile: bool = False) -> None: ... def link_shared_object( diff --git a/stubs/setuptools/setuptools/command/build_py.pyi b/stubs/setuptools/setuptools/command/build_py.pyi index 0e2fc54abfd2..3bdce5ca63f1 100644 --- a/stubs/setuptools/setuptools/command/build_py.pyi +++ b/stubs/setuptools/setuptools/command/build_py.pyi @@ -1,10 +1,12 @@ -from typing import Any +from _typeshed import Incomplete +from typing import Any, ClassVar from .._distutils.command import build_py as orig def make_writable(target) -> None: ... class build_py(orig.build_py): + editable_mode: ClassVar[bool] package_data: Any exclude_package_data: Any def finalize_options(self) -> None: ... @@ -12,9 +14,11 @@ class build_py(orig.build_py): data_files: Any def __getattr__(self, attr: str): ... def build_module(self, module, module_file, package): ... + def get_data_files_without_manifest(self) -> list[tuple[Incomplete, Incomplete, Incomplete, list[Incomplete]]]: ... def find_data_files(self, package, src_dir): ... def build_package_data(self) -> None: ... manifest_files: Any + def get_output_mapping(self) -> dict[str, str]: ... def analyze_manifest(self) -> None: ... def get_data_files(self) -> None: ... def check_package(self, package, package_dir): ... diff --git a/stubs/setuptools/setuptools/command/develop.pyi b/stubs/setuptools/setuptools/command/develop.pyi index f7c1058ce0b3..ebefbc2d49b7 100644 --- a/stubs/setuptools/setuptools/command/develop.pyi +++ b/stubs/setuptools/setuptools/command/develop.pyi @@ -1,7 +1,7 @@ from typing import Any -from setuptools import namespaces -from setuptools.command.easy_install import easy_install +from .. import namespaces +from .easy_install import easy_install class develop(namespaces.DevelopInstaller, easy_install): description: str diff --git a/stubs/setuptools/setuptools/command/dist_info.pyi b/stubs/setuptools/setuptools/command/dist_info.pyi index d2501e80be41..723a764d7ba3 100644 --- a/stubs/setuptools/setuptools/command/dist_info.pyi +++ b/stubs/setuptools/setuptools/command/dist_info.pyi @@ -1,10 +1,12 @@ -from typing import Any +from typing import Any, ClassVar from .._distutils.cmd import Command class dist_info(Command): description: str user_options: Any + boolean_options: ClassVar[list[str]] + negative_opt: ClassVar[dict[str, str]] egg_base: Any def initialize_options(self) -> None: ... def finalize_options(self) -> None: ... diff --git a/stubs/setuptools/setuptools/command/easy_install.pyi b/stubs/setuptools/setuptools/command/easy_install.pyi index b2b0d859c5de..0363907d1523 100644 --- a/stubs/setuptools/setuptools/command/easy_install.pyi +++ b/stubs/setuptools/setuptools/command/easy_install.pyi @@ -3,7 +3,10 @@ from collections.abc import Iterator from typing import Any from pkg_resources import Environment -from setuptools import Command, SetuptoolsDeprecationWarning + +from .. import Command, SetuptoolsDeprecationWarning + +__all__ = ["easy_install", "PthDistributions", "extract_wininst_cfg", "get_exe_prefixes"] class easy_install(Command): description: str diff --git a/stubs/setuptools/setuptools/command/editable_wheel.pyi b/stubs/setuptools/setuptools/command/editable_wheel.pyi new file mode 100644 index 000000000000..7378bf56968f --- /dev/null +++ b/stubs/setuptools/setuptools/command/editable_wheel.pyi @@ -0,0 +1,77 @@ +from _typeshed import Incomplete +from enum import Enum +from pathlib import Path +from typing import Protocol +from typing_extensions import TypeAlias + +from .. import Command, errors, namespaces +from ..dist import Distribution + +# Actually from wheel.wheelfile import _WheelFile +_WheelFile: TypeAlias = Incomplete +_Path: TypeAlias = str | Path + +class _EditableMode(Enum): + STRICT: str + LENIENT: str + COMPAT: str + @classmethod + def convert(cls, mode: str | None) -> _EditableMode: ... + +class editable_wheel(Command): + description: str + user_options: Incomplete + dist_dir: Incomplete + dist_info_dir: Incomplete + project_dir: Incomplete + mode: Incomplete + def initialize_options(self) -> None: ... + package_dir: Incomplete + def finalize_options(self) -> None: ... + def run(self) -> None: ... + +class EditableStrategy(Protocol): + def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]): ... + def __enter__(self) -> None: ... + def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ... + +class _StaticPth: + dist: Incomplete + name: Incomplete + path_entries: Incomplete + def __init__(self, dist: Distribution, name: str, path_entries: list[Path]) -> None: ... + def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]): ... + def __enter__(self): ... + def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ... + +class _LinkTree(_StaticPth): + auxiliary_dir: Incomplete + build_lib: Incomplete + def __init__(self, dist: Distribution, name: str, auxiliary_dir: _Path, build_lib: _Path) -> None: ... + def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]): ... + def __enter__(self): ... + def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ... + +class _TopLevelFinder: + dist: Incomplete + name: Incomplete + def __init__(self, dist: Distribution, name: str) -> None: ... + def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]): ... + def __enter__(self): ... + def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ... + +class _NamespaceInstaller(namespaces.Installer): + distribution: Incomplete + src_root: Incomplete + installation_dir: Incomplete + editable_name: Incomplete + outputs: Incomplete + dry_run: bool + def __init__(self, distribution, installation_dir, editable_name, src_root) -> None: ... + +class InformationOnly(UserWarning): ... +class LinksNotSupported(errors.FileError): ... + +class _DebuggingTips(InformationOnly): + @classmethod + def warn(cls, project: str): ... diff --git a/stubs/setuptools/setuptools/command/egg_info.pyi b/stubs/setuptools/setuptools/command/egg_info.pyi index d63a3c7f1af3..9685a9270649 100644 --- a/stubs/setuptools/setuptools/command/egg_info.pyi +++ b/stubs/setuptools/setuptools/command/egg_info.pyi @@ -1,9 +1,11 @@ from typing import Any +from typing_extensions import Final -from setuptools import Command, SetuptoolsDeprecationWarning -from setuptools.command.sdist import sdist - +from .. import Command, SetuptoolsDeprecationWarning from .._distutils.filelist import FileList as _FileList +from .sdist import sdist + +PY_MAJOR: Final[str] def translate_pattern(glob): ... diff --git a/stubs/setuptools/setuptools/command/install_egg_info.pyi b/stubs/setuptools/setuptools/command/install_egg_info.pyi index 2977e32c280e..a37c98cca4fd 100644 --- a/stubs/setuptools/setuptools/command/install_egg_info.pyi +++ b/stubs/setuptools/setuptools/command/install_egg_info.pyi @@ -1,6 +1,6 @@ from typing import Any -from setuptools import Command, namespaces +from .. import Command, namespaces class install_egg_info(namespaces.Installer, Command): description: str diff --git a/stubs/setuptools/setuptools/command/rotate.pyi b/stubs/setuptools/setuptools/command/rotate.pyi index 5d5de6f18e01..27c11582ea6a 100644 --- a/stubs/setuptools/setuptools/command/rotate.pyi +++ b/stubs/setuptools/setuptools/command/rotate.pyi @@ -1,6 +1,6 @@ from typing import Any -from setuptools import Command +from .. import Command class rotate(Command): description: str diff --git a/stubs/setuptools/setuptools/command/saveopts.pyi b/stubs/setuptools/setuptools/command/saveopts.pyi index 09d435c6343a..c96862b29284 100644 --- a/stubs/setuptools/setuptools/command/saveopts.pyi +++ b/stubs/setuptools/setuptools/command/saveopts.pyi @@ -1,4 +1,4 @@ -from setuptools.command.setopt import option_base +from .setopt import option_base class saveopts(option_base): description: str diff --git a/stubs/setuptools/setuptools/command/setopt.pyi b/stubs/setuptools/setuptools/command/setopt.pyi index 8ad8da2ce130..c57c3601d5ff 100644 --- a/stubs/setuptools/setuptools/command/setopt.pyi +++ b/stubs/setuptools/setuptools/command/setopt.pyi @@ -1,7 +1,9 @@ from abc import abstractmethod from typing import Any -from setuptools import Command +from .. import Command + +__all__ = ["config_file", "edit_config", "option_base", "setopt"] def config_file(kind: str = "local"): ... def edit_config(filename, settings, dry_run: bool = False) -> None: ... diff --git a/stubs/setuptools/setuptools/command/test.pyi b/stubs/setuptools/setuptools/command/test.pyi index 004b534e79dd..1764926f94bf 100644 --- a/stubs/setuptools/setuptools/command/test.pyi +++ b/stubs/setuptools/setuptools/command/test.pyi @@ -5,7 +5,7 @@ from typing import Any, Generic, TypeVar, overload from typing_extensions import Self from unittest import TestLoader, TestSuite -from setuptools import Command +from .. import Command _T = TypeVar("_T") diff --git a/stubs/setuptools/setuptools/config.pyi b/stubs/setuptools/setuptools/config.pyi deleted file mode 100644 index 0d865c53cb6f..000000000000 --- a/stubs/setuptools/setuptools/config.pyi +++ /dev/null @@ -1,2 +0,0 @@ -def read_configuration(filepath, find_others: bool = False, ignore_option_errors: bool = False): ... -def parse_configuration(distribution, command_options, ignore_option_errors: bool = False): ... diff --git a/stubs/setuptools/setuptools/config/__init__.pyi b/stubs/setuptools/setuptools/config/__init__.pyi new file mode 100644 index 000000000000..ca745c9194b9 --- /dev/null +++ b/stubs/setuptools/setuptools/config/__init__.pyi @@ -0,0 +1,9 @@ +from _typeshed import Incomplete +from collections.abc import Callable +from typing import TypeVar + +Fn = TypeVar("Fn", bound=Callable[..., Incomplete]) # noqa: Y001 # Exists at runtime +__all__ = ("parse_configuration", "read_configuration") + +def read_configuration(filepath, find_others: bool = False, ignore_option_errors: bool = False): ... +def parse_configuration(distribution, command_options, ignore_option_errors: bool = False): ... diff --git a/stubs/setuptools/setuptools/config/expand.pyi b/stubs/setuptools/setuptools/config/expand.pyi new file mode 100644 index 000000000000..d60d65b7df24 --- /dev/null +++ b/stubs/setuptools/setuptools/config/expand.pyi @@ -0,0 +1,50 @@ +import os +from _typeshed import Incomplete +from collections.abc import Callable, Iterable, Iterator, Mapping +from importlib.machinery import ModuleSpec +from typing import TypeVar +from typing_extensions import TypeAlias + +from ..dist import Distribution + +chain_iter: Incomplete +_Path: TypeAlias = str | os.PathLike[Incomplete] +_K = TypeVar("_K") +_V = TypeVar("_V", covariant=True) + +class StaticModule: + def __init__(self, name: str, spec: ModuleSpec) -> None: ... + def __getattr__(self, attr): ... + +def glob_relative(patterns: Iterable[str], root_dir: _Path | None = None) -> list[str]: ... +def read_files(filepaths: str | bytes | Iterable[_Path], root_dir: Incomplete | None = None) -> str: ... +def read_attr(attr_desc: str, package_dir: Mapping[str, str] | None = None, root_dir: _Path | None = None): ... +def resolve_class( + qualified_class_name: str, package_dir: Mapping[str, str] | None = None, root_dir: _Path | None = None +) -> Callable[..., Incomplete]: ... +def cmdclass( + values: dict[str, str], package_dir: Mapping[str, str] | None = None, root_dir: _Path | None = None +) -> dict[str, Callable[..., Incomplete]]: ... +def find_packages( + *, namespaces: bool = True, fill_package_dir: dict[str, str] | None = None, root_dir: _Path | None = None, **kwargs +) -> list[str]: ... +def version(value: Callable[..., Incomplete] | Iterable[str | int] | str) -> str: ... +def canonic_package_data(package_data: dict[Incomplete, Incomplete]) -> dict[Incomplete, Incomplete]: ... +def canonic_data_files( + data_files: list[Incomplete] | dict[Incomplete, Incomplete], root_dir: _Path | None = None +) -> list[tuple[str, list[str]]]: ... +def entry_points(text: str, text_source: str = "entry-points") -> dict[str, dict[Incomplete, Incomplete]]: ... + +class EnsurePackagesDiscovered: + def __init__(self, distribution: Distribution) -> None: ... + def __call__(self) -> None: ... + def __enter__(self): ... + def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ... + @property + def package_dir(self) -> Mapping[str, str]: ... + +class LazyMappingProxy(Mapping[_K, _V]): + def __init__(self, obtain_mapping_value: Callable[[], Mapping[_K, _V]]) -> None: ... + def __getitem__(self, key: _K) -> _V: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_K]: ... diff --git a/stubs/setuptools/setuptools/config/pyprojecttoml.pyi b/stubs/setuptools/setuptools/config/pyprojecttoml.pyi new file mode 100644 index 000000000000..7a8849cf9c4e --- /dev/null +++ b/stubs/setuptools/setuptools/config/pyprojecttoml.pyi @@ -0,0 +1,51 @@ +import os +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +from ..dist import Distribution +from . import expand + +_Path: TypeAlias = str | os.PathLike[Incomplete] + +def load_file(filepath: _Path) -> dict[Incomplete, Incomplete]: ... +def validate(config: dict[Incomplete, Incomplete], filepath: _Path) -> bool: ... +def apply_configuration(dist: Distribution, filepath: _Path, ignore_option_errors: bool = False) -> Distribution: ... +def read_configuration( + filepath: _Path, expand: bool = True, ignore_option_errors: bool = False, dist: Distribution | None = None +): ... +def expand_configuration( + config: dict[Incomplete, Incomplete], + root_dir: _Path | None = None, + ignore_option_errors: bool = False, + dist: Distribution | None = None, +) -> dict[Incomplete, Incomplete]: ... + +class _ConfigExpander: + config: Incomplete + root_dir: Incomplete + project_cfg: Incomplete + dynamic: Incomplete + setuptools_cfg: Incomplete + dynamic_cfg: Incomplete + ignore_option_errors: Incomplete + def __init__( + self, + config: dict[Incomplete, Incomplete], + root_dir: _Path | None = None, + ignore_option_errors: bool = False, + dist: Distribution | None = None, + ) -> None: ... + def expand(self): ... + +class _EnsurePackagesDiscovered(expand.EnsurePackagesDiscovered): + def __init__( + self, distribution: Distribution, project_cfg: dict[Incomplete, Incomplete], setuptools_cfg: dict[Incomplete, Incomplete] + ) -> None: ... + def __enter__(self): ... + def __exit__(self, exc_type, exc_value, traceback): ... + +class _BetaConfiguration(UserWarning): ... + +class _InvalidFile(UserWarning): + @classmethod + def message(cls): ... diff --git a/stubs/setuptools/setuptools/config/setupcfg.pyi b/stubs/setuptools/setuptools/config/setupcfg.pyi new file mode 100644 index 000000000000..222792693e09 --- /dev/null +++ b/stubs/setuptools/setuptools/config/setupcfg.pyi @@ -0,0 +1,83 @@ +import os +from _typeshed import Incomplete +from typing import Generic, TypeVar +from typing_extensions import TypeAlias + +from .._distutils.dist import DistributionMetadata +from ..dist import Distribution +from . import expand + +_Path: TypeAlias = str | os.PathLike[Incomplete] +SingleCommandOptions: Incomplete +AllCommandOptions: Incomplete +Target = TypeVar("Target", bound=Distribution | DistributionMetadata) # noqa: Y001 # Exists at runtime + +def read_configuration( + filepath: _Path, find_others: bool = False, ignore_option_errors: bool = False +) -> dict[Incomplete, Incomplete]: ... +def apply_configuration(dist: Distribution, filepath: _Path) -> Distribution: ... +def configuration_to_dict( + handlers: tuple[ConfigHandler[Distribution | DistributionMetadata], ...] +) -> dict[Incomplete, Incomplete]: ... +def parse_configuration( + distribution: Distribution, command_options: AllCommandOptions, ignore_option_errors: bool = False +) -> tuple[ConfigMetadataHandler, ConfigOptionsHandler]: ... + +class ConfigHandler(Generic[Target]): + section_prefix: str + aliases: dict[str, str] + ignore_option_errors: Incomplete + target_obj: Incomplete + sections: Incomplete + set_options: Incomplete + ensure_discovered: Incomplete + def __init__( + self, + target_obj: Target, + options: AllCommandOptions, + ignore_option_errors, + ensure_discovered: expand.EnsurePackagesDiscovered, + ) -> None: ... + @property + def parsers(self) -> None: ... + def __setitem__(self, option_name, value): ... + def parse_section(self, section_options) -> None: ... + def parse(self) -> None: ... + +class ConfigMetadataHandler(ConfigHandler[DistributionMetadata]): + section_prefix: str + aliases: Incomplete + strict_mode: bool + package_dir: Incomplete + root_dir: Incomplete + def __init__( + self, + target_obj: DistributionMetadata, + options: AllCommandOptions, + ignore_option_errors: bool, + ensure_discovered: expand.EnsurePackagesDiscovered, + package_dir: dict[Incomplete, Incomplete] | None = None, + root_dir: _Path = ".", + ) -> None: ... + @property + def parsers(self): ... + +class ConfigOptionsHandler(ConfigHandler[Distribution]): + section_prefix: str + root_dir: Incomplete + package_dir: Incomplete + def __init__( + self, + target_obj: Distribution, + options: AllCommandOptions, + ignore_option_errors: bool, + ensure_discovered: expand.EnsurePackagesDiscovered, + ) -> None: ... + @property + def parsers(self): ... + def parse_section_packages__find(self, section_options): ... + def parse_section_entry_points(self, section_options) -> None: ... + def parse_section_package_data(self, section_options) -> None: ... + def parse_section_exclude_package_data(self, section_options) -> None: ... + def parse_section_extras_require(self, section_options): ... + def parse_section_data_files(self, section_options) -> None: ... diff --git a/stubs/setuptools/setuptools/depends.pyi b/stubs/setuptools/setuptools/depends.pyi index 072ebc51e524..4f2edc1d09d5 100644 --- a/stubs/setuptools/setuptools/depends.pyi +++ b/stubs/setuptools/setuptools/depends.pyi @@ -1,4 +1,10 @@ from _typeshed import Incomplete +from typing import IO, Any +from typing_extensions import Literal + +__all__ = ["Require", "find_module", "get_module_constant", "extract_constant"] + +def find_module(module, paths=None) -> tuple[IO[Any], str, tuple[str, Literal["", "r", "rb"], Literal[7, 6, 1, 2, 3, -1]]]: ... class Require: def __init__( diff --git a/stubs/setuptools/setuptools/discovery.pyi b/stubs/setuptools/setuptools/discovery.pyi new file mode 100644 index 000000000000..15f74d902802 --- /dev/null +++ b/stubs/setuptools/setuptools/discovery.pyi @@ -0,0 +1,45 @@ +import os +from _typeshed import Incomplete +from collections.abc import Iterable, Iterator, Mapping +from typing_extensions import TypeAlias + +from . import Distribution + +_Path: TypeAlias = str | os.PathLike[Incomplete] +StrIter: TypeAlias = Iterator[str] +chain_iter: Incomplete + +class _Filter: + def __init__(self, *patterns: str) -> None: ... + def __call__(self, item: str) -> bool: ... + def __contains__(self, item: str) -> bool: ... + +class _Finder: + ALWAYS_EXCLUDE: tuple[str, ...] + DEFAULT_EXCLUDE: tuple[str, ...] + @classmethod + def find(cls, where: _Path = ".", exclude: Iterable[str] = (), include: Iterable[str] = ("*",)) -> list[str]: ... + +class PackageFinder(_Finder): + ALWAYS_EXCLUDE: Incomplete + +class PEP420PackageFinder(PackageFinder): ... +class ModuleFinder(_Finder): ... + +class FlatLayoutPackageFinder(PEP420PackageFinder): + DEFAULT_EXCLUDE: Incomplete + +class FlatLayoutModuleFinder(ModuleFinder): + DEFAULT_EXCLUDE: Incomplete + +class ConfigDiscovery: + dist: Incomplete + def __init__(self, distribution: Distribution) -> None: ... + def __call__(self, force: bool = False, name: bool = True, ignore_ext_modules: bool = False) -> None: ... + def analyse_name(self) -> None: ... + +def remove_nested_packages(packages: list[str]) -> list[str]: ... +def remove_stubs(packages: list[str]) -> list[str]: ... +def find_parent_package(packages: list[str], package_dir: Mapping[str, str], root_dir: _Path) -> str | None: ... +def find_package_path(name: str, package_dir: Mapping[str, str], root_dir: _Path) -> str: ... +def construct_package_dir(packages: list[str], package_path: _Path) -> dict[str, str]: ... diff --git a/stubs/setuptools/setuptools/dist.pyi b/stubs/setuptools/setuptools/dist.pyi index 8ace1407a35b..c7b950061b1a 100644 --- a/stubs/setuptools/setuptools/dist.pyi +++ b/stubs/setuptools/setuptools/dist.pyi @@ -1,10 +1,11 @@ from collections.abc import Iterable, Iterator, Mapping, MutableMapping from typing import Any -from setuptools import Command, SetuptoolsDeprecationWarning - +from . import Command, SetuptoolsDeprecationWarning from ._distutils.dist import Distribution as _Distribution +__all__ = ["Distribution"] + class Distribution(_Distribution): def patch_missing_pkg_info(self, attrs: Mapping[str, Any]) -> None: ... src_root: str | None diff --git a/stubs/setuptools/setuptools/errors.pyi b/stubs/setuptools/setuptools/errors.pyi index 2e31b89c8bf8..003874563c7c 100644 --- a/stubs/setuptools/setuptools/errors.pyi +++ b/stubs/setuptools/setuptools/errors.pyi @@ -1,3 +1,22 @@ -from ._distutils.errors import DistutilsError +from ._distutils import errors as _distutils_errors -class RemovedCommandError(DistutilsError, RuntimeError): ... +ByteCompileError = _distutils_errors.DistutilsByteCompileError +CCompilerError = _distutils_errors.CCompilerError +ClassError = _distutils_errors.DistutilsClassError +CompileError = _distutils_errors.CompileError +ExecError = _distutils_errors.DistutilsExecError +FileError = _distutils_errors.DistutilsFileError +InternalError = _distutils_errors.DistutilsInternalError +LibError = _distutils_errors.LibError +LinkError = _distutils_errors.LinkError +ModuleError = _distutils_errors.DistutilsModuleError +OptionError = _distutils_errors.DistutilsOptionError +PlatformError = _distutils_errors.DistutilsPlatformError +PreprocessError = _distutils_errors.PreprocessError +SetupError = _distutils_errors.DistutilsSetupError +TemplateError = _distutils_errors.DistutilsTemplateError +UnknownFileError = _distutils_errors.UnknownFileError +BaseError = _distutils_errors.DistutilsError + +class RemovedCommandError(BaseError, RuntimeError): ... +class PackageDiscoveryError(BaseError, RuntimeError): ... diff --git a/stubs/setuptools/setuptools/glob.pyi b/stubs/setuptools/setuptools/glob.pyi index 3ae65a804a0a..e5d6431bbe95 100644 --- a/stubs/setuptools/setuptools/glob.pyi +++ b/stubs/setuptools/setuptools/glob.pyi @@ -1,3 +1,5 @@ +__all__ = ["glob", "iglob", "escape"] + def glob(pathname, recursive: bool = False): ... def iglob(pathname, recursive: bool = False): ... def escape(pathname): ... diff --git a/stubs/setuptools/setuptools/logging.pyi b/stubs/setuptools/setuptools/logging.pyi new file mode 100644 index 000000000000..6933bcbd5cba --- /dev/null +++ b/stubs/setuptools/setuptools/logging.pyi @@ -0,0 +1,2 @@ +def configure() -> None: ... +def set_threshold(level): ... diff --git a/stubs/setuptools/setuptools/package_index.pyi b/stubs/setuptools/setuptools/package_index.pyi index 171745051de9..b32b580b1665 100644 --- a/stubs/setuptools/setuptools/package_index.pyi +++ b/stubs/setuptools/setuptools/package_index.pyi @@ -4,6 +4,8 @@ from typing import Any from pkg_resources import Environment +__all__ = ["PackageIndex", "distros_for_url", "parse_bdist_wininst", "interpret_distro_name"] + def parse_bdist_wininst(name): ... def distros_for_url(url, metadata: Incomplete | None = None) -> None: ... def interpret_distro_name( diff --git a/stubs/setuptools/setuptools/sandbox.pyi b/stubs/setuptools/setuptools/sandbox.pyi index 89e141184a65..e5018ca8ba03 100644 --- a/stubs/setuptools/setuptools/sandbox.pyi +++ b/stubs/setuptools/setuptools/sandbox.pyi @@ -4,6 +4,8 @@ from typing_extensions import Literal from ._distutils.errors import DistutilsError +__all__ = ["AbstractSandbox", "DirectorySandbox", "SandboxViolation", "run_setup"] + class UnpickleableException(Exception): @staticmethod def dump(type, exc): ... @@ -23,12 +25,31 @@ class AbstractSandbox: self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None ) -> None: ... def run(self, func): ... + # Dynamically created + def access(self, path, *args, **kw): ... + def chdir(self, path, *args, **kw): ... + def chmod(self, path, *args, **kw): ... + def getcwd(self, *args, **kw): ... + def link(self, src, dst, *args, **kw): ... + def listdir(self, path, *args, **kw): ... + def lstat(self, path, *args, **kw): ... + def mkdir(self, path, *args, **kw): ... + def open(self, path, *args, **kw): ... + def readlink(self, path, *args, **kw): ... + def remove(self, path, *args, **kw): ... + def rename(self, src, dst, *args, **kw): ... + def rmdir(self, path, *args, **kw): ... + def startfile(self, path, *args, **kw): ... + def stat(self, path, *args, **kw): ... + def symlink(self, src, dst, *args, **kw): ... + def unlink(self, path, *args, **kw): ... + def utime(self, path, *args, **kw): ... class DirectorySandbox(AbstractSandbox): write_ops: Any - def __init__(self, sandbox, exceptions=...) -> None: ... + def __init__(self, sandbox, exceptions=["nul"]) -> None: ... def tmpnam(self) -> None: ... - def open(self, file, flags, mode: int = 511, *args, **kw): ... + def open(self, file, flags, mode: int = 511, *args, **kw): ... # type:ignore[override] class SandboxViolation(DistutilsError): tmpl: Any diff --git a/stubs/setuptools/setuptools/wheel.pyi b/stubs/setuptools/setuptools/wheel.pyi index fe8d564af79d..eeb7eee24b54 100644 --- a/stubs/setuptools/setuptools/wheel.pyi +++ b/stubs/setuptools/setuptools/wheel.pyi @@ -1,9 +1,11 @@ +from collections.abc import Generator from typing import Any WHEEL_NAME: Any NAMESPACE_PACKAGE_INIT: str def unpack(src_dir, dst_dir) -> None: ... +def disable_info_traces() -> Generator[None, None, None]: ... class Wheel: filename: Any From e72ce698516e8dbef0df1b1693bbd6df288467ec Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 17 Apr 2023 17:57:10 -0400 Subject: [PATCH 2/6] remove version dependant default --- stubs/setuptools/pkg_resources/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index 424984b45ca0..ccc8835eda95 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -58,7 +58,7 @@ add_activation_listener = working_set.subscribe class Environment: def __init__( - self, search_path: Sequence[str] | None = None, platform: str | None = ..., python: str | None = "3.9" + self, search_path: Sequence[str] | None = None, platform: str | None = ..., python: str | None = ... ) -> None: ... def __getitem__(self, project_name: str) -> list[Distribution]: ... def __iter__(self) -> Generator[str, None, None]: ... From f05d0765935f7a445fc751f821c468b37b50d5c4 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 17 Apr 2023 19:03:00 -0400 Subject: [PATCH 3/6] Fix pytype and linux errors --- .../@tests/stubtest_allowlist_darwin.txt | 2 ++ .../setuptools/@tests/stubtest_allowlist_linux.txt | 2 ++ stubs/setuptools/METADATA.toml | 3 +++ stubs/setuptools/setuptools/__init__.pyi | 12 +++++++----- stubs/setuptools/setuptools/sandbox.pyi | 14 ++++++++++++-- 5 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 stubs/setuptools/@tests/stubtest_allowlist_darwin.txt create mode 100644 stubs/setuptools/@tests/stubtest_allowlist_linux.txt diff --git a/stubs/setuptools/@tests/stubtest_allowlist_darwin.txt b/stubs/setuptools/@tests/stubtest_allowlist_darwin.txt new file mode 100644 index 000000000000..6b3c1d5e7f6c --- /dev/null +++ b/stubs/setuptools/@tests/stubtest_allowlist_darwin.txt @@ -0,0 +1,2 @@ +# Mock +setuptools.msvc.winreg diff --git a/stubs/setuptools/@tests/stubtest_allowlist_linux.txt b/stubs/setuptools/@tests/stubtest_allowlist_linux.txt new file mode 100644 index 000000000000..6b3c1d5e7f6c --- /dev/null +++ b/stubs/setuptools/@tests/stubtest_allowlist_linux.txt @@ -0,0 +1,2 @@ +# Mock +setuptools.msvc.winreg diff --git a/stubs/setuptools/METADATA.toml b/stubs/setuptools/METADATA.toml index fa9a86f13825..3668081c0fda 100644 --- a/stubs/setuptools/METADATA.toml +++ b/stubs/setuptools/METADATA.toml @@ -1 +1,4 @@ version = "67.6.*" + +[tool.stubtest] +platforms = ["darwin", "linux", "win32"] diff --git a/stubs/setuptools/setuptools/__init__.pyi b/stubs/setuptools/setuptools/__init__.pyi index 86f68333f4de..69468c177a0a 100644 --- a/stubs/setuptools/setuptools/__init__.pyi +++ b/stubs/setuptools/setuptools/__init__.pyi @@ -1,11 +1,11 @@ from abc import abstractmethod -from collections.abc import Mapping, Sequence +from collections.abc import Iterable, Mapping, Sequence from typing import Any from ._deprecation_warning import SetuptoolsDeprecationWarning as SetuptoolsDeprecationWarning from ._distutils.cmd import Command as _Command from .depends import Require as Require -from .discovery import PackageFinder, PEP420PackageFinder +from .discovery import _Path from .dist import Distribution as Distribution from .extension import Extension as Extension @@ -22,9 +22,11 @@ __all__ = [ __version__: str -find_packages = PackageFinder.find -find_namespace_packages = PEP420PackageFinder.find - +# Pytype fails with the following: +# find_packages = PackageFinder.find +# find_namespace_packages = PEP420PackageFinder.find +def find_packages(where: _Path = ".", exclude: Iterable[str] = (), include: Iterable[str] = ("*",)) -> list[str]: ... +def find_namespace_packages(where: _Path = ".", exclude: Iterable[str] = (), include: Iterable[str] = ("*",)) -> list[str]: ... def setup( *, name: str = ..., diff --git a/stubs/setuptools/setuptools/sandbox.pyi b/stubs/setuptools/setuptools/sandbox.pyi index e5018ca8ba03..26927566aa5c 100644 --- a/stubs/setuptools/setuptools/sandbox.pyi +++ b/stubs/setuptools/setuptools/sandbox.pyi @@ -1,3 +1,4 @@ +import sys from types import TracebackType from typing import Any from typing_extensions import Literal @@ -26,6 +27,16 @@ class AbstractSandbox: ) -> None: ... def run(self, func): ... # Dynamically created + if sys.platform != "linux": + def startfile(self, path, *args, **kw): ... + if sys.platform != "win32": + def chown(self, path, *args, **kw): ... + def chroot(self, path, *args, **kw): ... + def lchown(self, path, *args, **kw): ... + def mkfifo(self, path, *args, **kw): ... + def mknod(self, path, *args, **kw): ... + def pathconf(self, path, *args, **kw): ... + def access(self, path, *args, **kw): ... def chdir(self, path, *args, **kw): ... def chmod(self, path, *args, **kw): ... @@ -39,7 +50,6 @@ class AbstractSandbox: def remove(self, path, *args, **kw): ... def rename(self, src, dst, *args, **kw): ... def rmdir(self, path, *args, **kw): ... - def startfile(self, path, *args, **kw): ... def stat(self, path, *args, **kw): ... def symlink(self, src, dst, *args, **kw): ... def unlink(self, path, *args, **kw): ... @@ -47,7 +57,7 @@ class AbstractSandbox: class DirectorySandbox(AbstractSandbox): write_ops: Any - def __init__(self, sandbox, exceptions=["nul"]) -> None: ... + def __init__(self, sandbox, exceptions=...) -> None: ... def tmpnam(self) -> None: ... def open(self, file, flags, mode: int = 511, *args, **kw): ... # type:ignore[override] From bdf18cadde77884167304e1a1a30aba63f98f1ce Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 17 Apr 2023 19:07:26 -0400 Subject: [PATCH 4/6] Confirmed darwin is equivalent to linux --- stubs/setuptools/METADATA.toml | 3 ++- stubs/setuptools/setuptools/sandbox.pyi | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/stubs/setuptools/METADATA.toml b/stubs/setuptools/METADATA.toml index 3668081c0fda..d0dc85a8cc27 100644 --- a/stubs/setuptools/METADATA.toml +++ b/stubs/setuptools/METADATA.toml @@ -1,4 +1,5 @@ version = "67.6.*" [tool.stubtest] -platforms = ["darwin", "linux", "win32"] +# darwin is equivalent to linux for OS-specific methods +platforms = ["linux", "win32"] diff --git a/stubs/setuptools/setuptools/sandbox.pyi b/stubs/setuptools/setuptools/sandbox.pyi index 26927566aa5c..961e6f76a3ff 100644 --- a/stubs/setuptools/setuptools/sandbox.pyi +++ b/stubs/setuptools/setuptools/sandbox.pyi @@ -27,9 +27,9 @@ class AbstractSandbox: ) -> None: ... def run(self, func): ... # Dynamically created - if sys.platform != "linux": + if sys.platform == "win32": def startfile(self, path, *args, **kw): ... - if sys.platform != "win32": + else: def chown(self, path, *args, **kw): ... def chroot(self, path, *args, **kw): ... def lchown(self, path, *args, **kw): ... From d0485e85f15edc812cfa15a5ee351919b808d02c Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 29 Apr 2023 12:04:11 -0400 Subject: [PATCH 5/6] Address PR comments + merge from main --- .../setuptools/@tests/stubtest_allowlist.txt | 2 - stubs/setuptools/pkg_resources/__init__.pyi | 24 ++++++------ .../setuptools/command/editable_wheel.pyi | 39 +++++++++++-------- stubs/setuptools/setuptools/config/expand.pyi | 17 ++++---- .../setuptools/config/pyprojecttoml.pyi | 17 ++++---- stubs/setuptools/setuptools/depends.pyi | 4 +- stubs/setuptools/setuptools/py312compat.pyi | 3 ++ stubs/setuptools/setuptools/sandbox.pyi | 4 +- 8 files changed, 62 insertions(+), 48 deletions(-) create mode 100644 stubs/setuptools/setuptools/py312compat.pyi diff --git a/stubs/setuptools/@tests/stubtest_allowlist.txt b/stubs/setuptools/@tests/stubtest_allowlist.txt index 12eb997b38a5..48eb73ba546b 100644 --- a/stubs/setuptools/@tests/stubtest_allowlist.txt +++ b/stubs/setuptools/@tests/stubtest_allowlist.txt @@ -11,8 +11,6 @@ pkg_resources.IMetadataProvider.has_metadata pkg_resources.IMetadataProvider.metadata_isdir pkg_resources.IMetadataProvider.metadata_listdir pkg_resources.IMetadataProvider.run_script -# @type_check_only -pkg_resources.IResourceManager # Is always set in __init__ pkg_resources.PathMetadata.egg_info diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index ccc8835eda95..4ea9bb9b86a0 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -39,11 +39,11 @@ class WorkingSet: requirements: Iterable[Requirement], env: Environment | None = None, installer: _InstallerType | None = None, - replace_conflicting=False, + replace_conflicting: bool = False, extras=None, ) -> list[Distribution]: ... def add(self, dist: Distribution, entry: str | None = None, insert: bool = True, replace: bool = False) -> None: ... - def subscribe(self, callback: Callable[[Distribution], object], existing=True) -> None: ... + def subscribe(self, callback: Callable[[Distribution], object], existing: bool = True) -> None: ... def find_plugins( self, plugin_env: Environment, full_env: Environment | None = None, installer=None, fallback: bool = True ) -> tuple[list[Distribution], dict[Distribution, Exception]]: ... @@ -97,7 +97,7 @@ class Requirement: # TODO: change this to packaging.markers.Marker | None once we can import # packaging.markers marker: Incomplete | None - def __init__(self, requirement_string) -> None: ... + def __init__(self, requirement_string: str) -> None: ... @staticmethod def parse(s: str | Iterable[str]) -> Requirement: ... def __contains__(self, item: Distribution | str | tuple[str, ...]) -> bool: ... @@ -151,12 +151,12 @@ class Distribution(NullProvider): @property def hashcmp(self) -> tuple[Incomplete, int, str, Incomplete | None, str, str]: ... def __hash__(self) -> int: ... - def __lt__(self, other) -> bool: ... - def __le__(self, other) -> bool: ... - def __gt__(self, other) -> bool: ... - def __ge__(self, other) -> bool: ... - def __eq__(self, other) -> bool: ... - def __ne__(self, other) -> bool: ... + def __lt__(self, other: Distribution) -> bool: ... + def __le__(self, other: Distribution) -> bool: ... + def __gt__(self, other: Distribution) -> bool: ... + def __ge__(self, other: Distribution) -> bool: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... @property def key(self) -> str: ... @property @@ -184,7 +184,7 @@ class Distribution(NullProvider): ) -> Distribution: ... @classmethod def from_filename(cls, filename: str, metadata: _MetadataType = None, **kw: str | None | int) -> Distribution: ... - def activate(self, path: list[str] | None = None, replace=False) -> None: ... + def activate(self, path: list[str] | None = None, replace: bool = False) -> None: ... def as_requirement(self) -> Requirement: ... def requires(self, extras: tuple[str, ...] = ()) -> list[Requirement]: ... def check_version_conflict(self) -> None: ... @@ -214,7 +214,7 @@ def resource_filename(package_or_requirement: _PkgReqType, resource_name: str) - def set_extraction_path(path: str) -> None: ... def cleanup_resources(force: bool = False) -> list[str]: ... @type_check_only -class IResourceManager(Protocol): +class _IResourceManager(Protocol): def resource_exists(self, package_or_requirement: _PkgReqType, resource_name: str) -> bool: ... def resource_stream(self, package_or_requirement: _PkgReqType, resource_name: str) -> IO[bytes]: ... def resource_string(self, package_or_requirement: _PkgReqType, resource_name: str) -> bytes: ... @@ -266,7 +266,7 @@ class ContextualVersionConflict(VersionConflict): class UnknownExtra(ResolutionError): ... class ExtractionError(Exception): - manager: IResourceManager + manager: _IResourceManager cache_path: str original_error: Exception diff --git a/stubs/setuptools/setuptools/command/editable_wheel.pyi b/stubs/setuptools/setuptools/command/editable_wheel.pyi index 7378bf56968f..4f527d24aacb 100644 --- a/stubs/setuptools/setuptools/command/editable_wheel.pyi +++ b/stubs/setuptools/setuptools/command/editable_wheel.pyi @@ -1,13 +1,15 @@ from _typeshed import Incomplete from enum import Enum from pathlib import Path +from types import TracebackType from typing import Protocol -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias from .. import Command, errors, namespaces from ..dist import Distribution +from ..warnings import SetuptoolsWarning -# Actually from wheel.wheelfile import _WheelFile +# Actually from wheel.wheelfile import WheelFile _WheelFile: TypeAlias = Incomplete _Path: TypeAlias = str | Path @@ -31,9 +33,11 @@ class editable_wheel(Command): def run(self) -> None: ... class EditableStrategy(Protocol): - def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]): ... - def __enter__(self) -> None: ... - def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ... + def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]) -> None: ... + def __enter__(self): ... + def __exit__( + self, _exc_type: type[BaseException] | None, _exc_value: BaseException | None, _traceback: TracebackType | None + ) -> None: ... class _StaticPth: dist: Incomplete @@ -41,24 +45,30 @@ class _StaticPth: path_entries: Incomplete def __init__(self, dist: Distribution, name: str, path_entries: list[Path]) -> None: ... def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]): ... - def __enter__(self): ... - def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ... + def __enter__(self) -> Self: ... + def __exit__( + self, _exc_type: type[BaseException] | None, _exc_value: BaseException | None, _traceback: TracebackType | None + ) -> None: ... class _LinkTree(_StaticPth): auxiliary_dir: Incomplete build_lib: Incomplete def __init__(self, dist: Distribution, name: str, auxiliary_dir: _Path, build_lib: _Path) -> None: ... def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]): ... - def __enter__(self): ... - def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ... + def __enter__(self) -> Self: ... + def __exit__( + self, _exc_type: type[BaseException] | None, _exc_value: BaseException | None, _traceback: TracebackType | None + ) -> None: ... class _TopLevelFinder: dist: Incomplete name: Incomplete def __init__(self, dist: Distribution, name: str) -> None: ... def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]): ... - def __enter__(self): ... - def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ... + def __enter__(self) -> Self: ... + def __exit__( + self, _exc_type: type[BaseException] | None, _exc_value: BaseException | None, _traceback: TracebackType | None + ) -> None: ... class _NamespaceInstaller(namespaces.Installer): distribution: Incomplete @@ -69,9 +79,6 @@ class _NamespaceInstaller(namespaces.Installer): dry_run: bool def __init__(self, distribution, installation_dir, editable_name, src_root) -> None: ... -class InformationOnly(UserWarning): ... +class InformationOnly(SetuptoolsWarning): ... class LinksNotSupported(errors.FileError): ... - -class _DebuggingTips(InformationOnly): - @classmethod - def warn(cls, project: str): ... +class _DebuggingTips(SetuptoolsWarning): ... diff --git a/stubs/setuptools/setuptools/config/expand.pyi b/stubs/setuptools/setuptools/config/expand.pyi index d60d65b7df24..ff32f66904b0 100644 --- a/stubs/setuptools/setuptools/config/expand.pyi +++ b/stubs/setuptools/setuptools/config/expand.pyi @@ -2,15 +2,16 @@ import os from _typeshed import Incomplete from collections.abc import Callable, Iterable, Iterator, Mapping from importlib.machinery import ModuleSpec +from types import TracebackType from typing import TypeVar -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias from ..dist import Distribution chain_iter: Incomplete _Path: TypeAlias = str | os.PathLike[Incomplete] _K = TypeVar("_K") -_V = TypeVar("_V", covariant=True) +_VCo = TypeVar("_VCo", covariant=True) class StaticModule: def __init__(self, name: str, spec: ModuleSpec) -> None: ... @@ -38,13 +39,15 @@ def entry_points(text: str, text_source: str = "entry-points") -> dict[str, dict class EnsurePackagesDiscovered: def __init__(self, distribution: Distribution) -> None: ... def __call__(self) -> None: ... - def __enter__(self): ... - def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ... + def __enter__(self) -> Self: ... + def __exit__( + self, _exc_type: type[BaseException] | None, _exc_value: BaseException | None, _traceback: TracebackType | None + ) -> None: ... @property def package_dir(self) -> Mapping[str, str]: ... -class LazyMappingProxy(Mapping[_K, _V]): - def __init__(self, obtain_mapping_value: Callable[[], Mapping[_K, _V]]) -> None: ... - def __getitem__(self, key: _K) -> _V: ... +class LazyMappingProxy(Mapping[_K, _VCo]): + def __init__(self, obtain_mapping_value: Callable[[], Mapping[_K, _VCo]]) -> None: ... + def __getitem__(self, key: _K) -> _VCo: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_K]: ... diff --git a/stubs/setuptools/setuptools/config/pyprojecttoml.pyi b/stubs/setuptools/setuptools/config/pyprojecttoml.pyi index 7a8849cf9c4e..ce56e9baed01 100644 --- a/stubs/setuptools/setuptools/config/pyprojecttoml.pyi +++ b/stubs/setuptools/setuptools/config/pyprojecttoml.pyi @@ -1,8 +1,10 @@ import os from _typeshed import Incomplete -from typing_extensions import TypeAlias +from types import TracebackType +from typing_extensions import Self, TypeAlias from ..dist import Distribution +from ..warnings import SetuptoolsWarning from . import expand _Path: TypeAlias = str | os.PathLike[Incomplete] @@ -41,11 +43,10 @@ class _EnsurePackagesDiscovered(expand.EnsurePackagesDiscovered): def __init__( self, distribution: Distribution, project_cfg: dict[Incomplete, Incomplete], setuptools_cfg: dict[Incomplete, Incomplete] ) -> None: ... - def __enter__(self): ... - def __exit__(self, exc_type, exc_value, traceback): ... + def __enter__(self) -> Self: ... + def __exit__( + self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None + ): ... -class _BetaConfiguration(UserWarning): ... - -class _InvalidFile(UserWarning): - @classmethod - def message(cls): ... +class _BetaConfiguration(SetuptoolsWarning): ... +class _InvalidFile(SetuptoolsWarning): ... diff --git a/stubs/setuptools/setuptools/depends.pyi b/stubs/setuptools/setuptools/depends.pyi index 4f2edc1d09d5..34c877298c96 100644 --- a/stubs/setuptools/setuptools/depends.pyi +++ b/stubs/setuptools/setuptools/depends.pyi @@ -4,7 +4,9 @@ from typing_extensions import Literal __all__ = ["Require", "find_module", "get_module_constant", "extract_constant"] -def find_module(module, paths=None) -> tuple[IO[Any], str, tuple[str, Literal["", "r", "rb"], Literal[7, 6, 1, 2, 3, -1]]]: ... +def find_module( + module, paths=None +) -> tuple[IO[Any], str | None, tuple[str, Literal["", "r", "rb"], Literal[7, 6, 1, 2, 3, -1]]]: ... class Require: def __init__( diff --git a/stubs/setuptools/setuptools/py312compat.pyi b/stubs/setuptools/setuptools/py312compat.pyi new file mode 100644 index 000000000000..898cfa8f5e50 --- /dev/null +++ b/stubs/setuptools/setuptools/py312compat.pyi @@ -0,0 +1,3 @@ +from _typeshed import Incomplete, StrOrBytesPath + +def shutil_rmtree(path: StrOrBytesPath, ignore_errors: bool = False, onexc: Incomplete | None = None) -> None: ... diff --git a/stubs/setuptools/setuptools/sandbox.pyi b/stubs/setuptools/setuptools/sandbox.pyi index 961e6f76a3ff..acae6699779f 100644 --- a/stubs/setuptools/setuptools/sandbox.pyi +++ b/stubs/setuptools/setuptools/sandbox.pyi @@ -1,7 +1,7 @@ import sys from types import TracebackType from typing import Any -from typing_extensions import Literal +from typing_extensions import Literal, Self from ._distutils.errors import DistutilsError @@ -12,7 +12,7 @@ class UnpickleableException(Exception): def dump(type, exc): ... class ExceptionSaver: - def __enter__(self): ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None ) -> Literal[True] | None: ... From 6dfcf402536821d36cd9dd9aa75b0489472d3a90 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 29 Apr 2023 12:52:50 -0400 Subject: [PATCH 6/6] Try to add relevant tests --- .../@tests/test_cases/check_protocols.py | 54 +++++++++++++++++++ stubs/setuptools/pkg_resources/__init__.pyi | 12 ++--- 2 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 stubs/setuptools/@tests/test_cases/check_protocols.py diff --git a/stubs/setuptools/@tests/test_cases/check_protocols.py b/stubs/setuptools/@tests/test_cases/check_protocols.py new file mode 100644 index 000000000000..66237a4bc2ef --- /dev/null +++ b/stubs/setuptools/@tests/test_cases/check_protocols.py @@ -0,0 +1,54 @@ +from __future__ import annotations + +from typing import Any + +from pkg_resources import ( + DefaultProvider, + EggMetadata, + EggProvider, + EmptyProvider, + FileMetadata, + IMetadataProvider, + IResourceProvider, + NullProvider, + PathMetadata, + ZipProvider, +) +from setuptools.command.editable_wheel import EditableStrategy, _LinkTree, _StaticPth, _TopLevelFinder +from setuptools.config.expand import EnsurePackagesDiscovered +from setuptools.config.pyprojecttoml import _EnsurePackagesDiscovered + +# We don't care about the __init__ methods, only about if an instance respects the Protocol +_: Any = object() + +# Test IMetadataProvider Protocol implementers +metadata_provider: IMetadataProvider +metadata_provider = NullProvider(_) +metadata_provider = EggProvider(_) +metadata_provider = EmptyProvider() +metadata_provider = DefaultProvider(_) +metadata_provider = ZipProvider(_) +metadata_provider = FileMetadata(_) +metadata_provider = PathMetadata(_, _) +metadata_provider = EggMetadata(_) + +# Test IResourceProvider Protocol implementers +resource_provider: IResourceProvider +resource_provider = NullProvider(_) +resource_provider = EggProvider(_) +resource_provider = EmptyProvider() +resource_provider = DefaultProvider(_) +resource_provider = ZipProvider(_) +resource_provider = FileMetadata(_) +resource_provider = PathMetadata(_, _) +resource_provider = EggMetadata(_) + + +# Test EditableStrategy Protocol implementers +editable_strategy: EditableStrategy +editable_strategy = _StaticPth(_, _, _) +editable_strategy = _LinkTree(_, _, _, _) +editable_strategy = _TopLevelFinder(_, _) +# Not EditableStrategy due to incompatible __call__ method +editable_strategy = EnsurePackagesDiscovered(_) # type: ignore +editable_strategy = _EnsurePackagesDiscovered(_, _, _) # type: ignore diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index 4ea9bb9b86a0..5ce46274224e 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -277,9 +277,9 @@ def register_loader_type(loader_type: type, provider_factory: Callable[[types.Mo def register_namespace_handler(importer_type: type, namespace_handler: _NSHandlerType) -> None: ... class IResourceProvider(IMetadataProvider, Protocol): - def get_resource_filename(self, manager, resource_name): ... - def get_resource_stream(self, manager, resource_name): ... - def get_resource_string(self, manager, resource_name): ... + def get_resource_filename(self, manager: _IResourceManager, resource_name): ... + def get_resource_stream(self, manager: _IResourceManager, resource_name): ... + def get_resource_string(self, manager: _IResourceManager, resource_name): ... def has_resource(self, resource_name): ... def resource_isdir(self, resource_name): ... def resource_listdir(self, resource_name): ... @@ -294,9 +294,9 @@ class NullProvider: module_path: str | None def __init__(self, module) -> None: ... - def get_resource_filename(self, manager, resource_name) -> str: ... - def get_resource_stream(self, manager, resource_name) -> BytesIO: ... - def get_resource_string(self, manager, resource_name): ... + def get_resource_filename(self, manager: _IResourceManager, resource_name) -> str: ... + def get_resource_stream(self, manager: _IResourceManager, resource_name) -> BytesIO: ... + def get_resource_string(self, manager: _IResourceManager, resource_name): ... def has_resource(self, resource_name) -> bool: ... def has_metadata(self, name: str) -> bool | None: ... def get_metadata(self, name: str) -> str: ...