Skip to content

Commit 86b982f

Browse files
committed
Support optional-dependencies for third party packages
Part of #15549
1 parent d541d5a commit 86b982f

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

CONTRIBUTING.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ supported:
169169
be listed here, for security reasons. See
170170
[this issue](https://github.com/typeshed-internal/stub_uploader/issues/90)
171171
for more information about what external dependencies are allowed.
172+
* `optional-dependencies` (optional): A list of other stub packages or packages
173+
with type information that are imported by some stubs in this package. This
174+
is often used for packages that provide optional features that require extra
175+
dependencies. The same limitations apply to this field as to `dependencies`.
172176
* `extra-description` (optional): Can be used to add a custom description to
173177
the package's long description. It should be a multi-line string in
174178
Markdown format.
@@ -204,7 +208,8 @@ This has the following keys:
204208
this field should be identical to `partial-stub`.
205209
* `stubtest-dependencies` (default: `[]`): A list of Python packages that need
206210
to be installed for stubtest to run successfully. These packages are installed
207-
in addition to the dependencies in the `dependencies` field.
211+
in addition to the dependencies in the `dependencies` and
212+
`optional-dependencies` fields.
208213
* `apt-dependencies` (default: `[]`): A list of Ubuntu APT packages
209214
that need to be installed for stubtest to run successfully.
210215
* `brew-dependencies` (default: `[]`): A list of MacOS Homebrew packages

lib/ts_utils/metadata.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class StubMetadata:
175175
distribution: Annotated[str, "The name of the distribution on PyPI"]
176176
version_spec: Annotated[Specifier, "Upstream versions that the stubs are compatible with"]
177177
dependencies: Annotated[list[Requirement], "The parsed dependencies as listed in METADATA.toml"]
178+
optional_dependencies: Annotated[list[Requirement], "The parsed optional dependencies as listed in METADATA.toml"]
178179
extra_description: str | None
179180
stub_distribution: Annotated[str, "The name under which the distribution is uploaded to PyPI"]
180181
upstream_repository: Annotated[str, "The URL of the upstream repository"] | None
@@ -189,11 +190,20 @@ class StubMetadata:
189190
def is_obsolete(self) -> bool:
190191
return self.obsolete is not None
191192

193+
@property
194+
def all_dependencies(self) -> list[Requirement]:
195+
"""The dependencies and optional dependencies of this stubs package.
196+
197+
Does not include the stubtest dependencies.
198+
"""
199+
return self.dependencies + self.optional_dependencies
200+
192201

193202
_KNOWN_METADATA_FIELDS: Final = frozenset(
194203
{
195204
"version",
196205
"dependencies",
206+
"optional-dependencies",
197207
"extra-description",
198208
"stub-distribution",
199209
"upstream-repository",
@@ -264,6 +274,10 @@ def read_metadata(distribution: str) -> StubMetadata:
264274
assert isinstance(dependencies_s, list)
265275
dependencies = [parse_dependencies(distribution, dep) for dep in dependencies_s]
266276

277+
optional_dependencies_s = data.get("optional-dependencies", [])
278+
assert isinstance(optional_dependencies_s, list)
279+
optional_dependencies = [parse_dependencies(distribution, dep) for dep in optional_dependencies_s]
280+
267281
extra_description = data.get("extra-description")
268282
assert isinstance(extra_description, (str, type(None)))
269283

@@ -342,6 +356,7 @@ def read_metadata(distribution: str) -> StubMetadata:
342356
distribution=distribution,
343357
version_spec=version_spec,
344358
dependencies=dependencies,
359+
optional_dependencies=optional_dependencies,
345360
extra_description=extra_description,
346361
stub_distribution=stub_distribution,
347362
upstream_repository=upstream_repository,
@@ -411,7 +426,7 @@ def read_dependencies(distribution: str) -> PackageDependencies:
411426
pypi_name_to_typeshed_name_mapping = get_pypi_name_to_typeshed_name_mapping()
412427
typeshed: list[Requirement] = []
413428
external: list[Requirement] = []
414-
for dependency in read_metadata(distribution).dependencies:
429+
for dependency in read_metadata(distribution).all_dependencies:
415430
if dependency.name in pypi_name_to_typeshed_name_mapping:
416431
req = Requirement(str(dependency)) # copy the requirement
417432
req.name = pypi_name_to_typeshed_name_mapping[dependency.name]

stubs/Authlib/@tests/stubtest_allowlist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,5 @@ authlib.integrations.flask_client.*
4949
authlib.integrations.flask_oauth1.*
5050
authlib.integrations.flask_oauth2.*
5151
authlib.integrations.httpx_client.*
52-
authlib.integrations.requests_client.*
5352
authlib.integrations.sqla_oauth2.*
5453
authlib.integrations.starlette_client.*

stubs/Authlib/METADATA.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
version = "1.6.11"
22
upstream-repository = "https://github.com/authlib/authlib"
33
dependencies = ["cryptography"]
4+
optional-dependencies = ["requests"]

0 commit comments

Comments
 (0)