Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove setuptools/pkg_resources #13369

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stubs/Pygments/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version = "2.18.*"
upstream_repository = "https://github.com/pygments/pygments"
requires = ["types-docutils", "types-setuptools"]
requires = ["types-docutils"]
partial_stub = true

[tool.stubtest]
Expand Down
14 changes: 11 additions & 3 deletions stubs/Pygments/pygments/plugin.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import Generator, Iterable
import sys
from collections.abc import Generator
from typing import Any

from pkg_resources import EntryPoint
from pygments.filter import Filter
from pygments.formatter import Formatter
from pygments.lexer import Lexer
Expand All @@ -12,7 +12,15 @@ FORMATTER_ENTRY_POINT: str
STYLE_ENTRY_POINT: str
FILTER_ENTRY_POINT: str

def iter_entry_points(group_name: str) -> Iterable[EntryPoint]: ...
if sys.version_info >= (3, 10):
from importlib.metadata import EntryPoints
def iter_entry_points(group_name: str) -> EntryPoints: ...

else:
from importlib.metadata import EntryPoint

def iter_entry_points(group_name: str) -> tuple[EntryPoint, ...] | list[EntryPoint]: ...

def find_plugin_lexers() -> Generator[type[Lexer], None, None]: ...
def find_plugin_formatters() -> Generator[tuple[str, type[Formatter[Any]]], None, None]: ...
def find_plugin_styles() -> Generator[tuple[str, type[Style]], None, None]: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/fanstatic/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version = "1.4.*"
upstream_repository = "https://github.com/zopefoundation/fanstatic"
requires = ["types-setuptools", "types-WebOb"]
requires = ["types-WebOb", "types-setuptools"]
11 changes: 8 additions & 3 deletions stubs/fanstatic/fanstatic/registry.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from abc import abstractmethod
from collections.abc import Iterable
from threading import Lock
from typing import Any, ClassVar, Literal, Protocol, TypeVar
from typing import Any, ClassVar, Literal, Protocol, TypeVar, type_check_only
from typing_extensions import Self

from fanstatic.compiler import Compiler, Minifier
from fanstatic.core import Library
from fanstatic.injector import InjectorPlugin
from pkg_resources import EntryPoint

# Used to be pkg_resources.EntryPoint, but any EntryPoint-like class with a `load` method works
@type_check_only
class _EntryPoint(Protocol):
def load(self) -> Any: ... # Can be any attribute in the module

@type_check_only
class _HasName(Protocol):
@property
def name(self) -> str: ...
Expand All @@ -24,7 +29,7 @@ class Registry(dict[str, _NamedT]):
def __init__(self, items: Iterable[_NamedT] = ()) -> None: ...
def add(self, item: _NamedT) -> None: ...
def load_items_from_entry_points(self) -> None: ...
def make_item_from_entry_point(self, entry_point: EntryPoint) -> Any: ...
def make_item_from_entry_point(self, entry_point: _EntryPoint) -> Any: ...
@classmethod
def instance(cls) -> Self: ...

Expand Down
9 changes: 0 additions & 9 deletions stubs/setuptools/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# Is always set in __init__
pkg_resources.PathMetadata.egg_info
pkg_resources.EggMetadata.loader
pkg_resources.ZipProvider.loader

# @classmethod alias not handled correctly by stubtest
pkg_resources.ZipManifests.load

# Is a functools.partial, so stubtest says "is not a function"
setuptools.modified.newer_pairwise_group
setuptools._distutils._modified.newer_pairwise_group
Expand Down Expand Up @@ -112,4 +104,3 @@ setuptools.config._validate_pyproject.*
setuptools.compat.*
setuptools.command.build_py.build_py.existing_egg_info_dir
.+?\.tests.*
.+?\._vendor.*
35 changes: 0 additions & 35 deletions stubs/setuptools/@tests/test_cases/check_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,13 @@

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(_, _, _)
Expand Down
5 changes: 3 additions & 2 deletions stubs/setuptools/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version = "75.6.*"
upstream_repository = "https://github.com/pypa/setuptools"
extra_description = """\
If using `setuptools >= 71.1` *only* for `pkg_resources`,
you don't need `types-setuptools` since `pkg_resources` is now typed.\
Given that `pkg_resources` is typed since `setuptools >= 71.1`, \
it is no longer included with `types-setuptools`.
"""
requires = ["setuptools"] # For pkg_resources
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, a stub can't depend on the library it stubs >.<
Since this restriction is in place for security reasons, would it make sense to allow types-Foo to require Foo ?

stub_uploader.metadata.InvalidRequires: Expected dependency setuptools to be listed in setuptools's requires_dist or the sdist's *.egg-info/requires.txt


[tool.stubtest]
# darwin is equivalent to linux for OS-specific methods
Expand Down
Loading
Loading