Skip to content

Commit

Permalink
Add partial_stub metadata field (python#10157)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored May 10, 2023
1 parent ff700e1 commit db01498
Show file tree
Hide file tree
Showing 51 changed files with 68 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ supported:
* `upload` (optional): This field is set to `false` to prevent automatic
uploads to PyPI. This should only used in special cases, e.g. when the stubs
break the upload.
* `partial_stub` (optional): This field marks the type stub package as
[partial](https://peps.python.org/pep-0561/#partial-stub-packages). This is for
3rd-party stubs that don't cover the entirety of the package's public API.
In most cases, this field is identical to `ignore_missing_stub`.

In addition, we specify configuration for stubtest in the `tool.stubtest` table.
This has the following keys:
Expand Down
1 change: 1 addition & 0 deletions stubs/Flask-Cors/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "3.0.*"
# Requires a version of flask with a `py.typed` file
requires = ["Flask>=2.0.0"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/Flask-Migrate/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "4.0.*"
# Requires a version of flask with a `py.typed` file
requires = ["Flask>=2.0.0", "types-Flask-SQLAlchemy"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/Flask-SQLAlchemy/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "2.5.*"
requires = ["types-SQLAlchemy"]
obsolete_since = "3.0.1" # Released on 2022-10-11
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/Markdown/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "3.4.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/Pillow/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "9.5.*"
partial_stub = true

[tool.stubtest]
stubtest_requirements = ["olefile"]
Expand Down
1 change: 1 addition & 0 deletions stubs/PyMySQL/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "1.0.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/Pygments/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version = "2.15.*"
requires = ["types-docutils", "types-setuptools"]
partial_stub = true

[tool.stubtest]
stubtest_requirements = ["sphinx"]
Expand Down
1 change: 1 addition & 0 deletions stubs/Send2Trash/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "1.8.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/aws-xray-sdk/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "2.12.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/babel/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "2.11.*"
requires = ["types-pytz"]
obsolete_since = "2.12.1" # Released on 2023-02-28
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/beautifulsoup4/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version = "4.12.*"
requires = ["types-html5lib"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
Expand Down
1 change: 1 addition & 0 deletions stubs/bleach/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "6.0.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/boto/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version = "2.49.*"
requires = []
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/braintree/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "4.19.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/caldav/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "1.2.*"
# also types-lxml and types-icalendar when those stubs are added
requires = ["types-requests", "types-vobject"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/chardet/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version = "5.0.*"
obsolete_since = "5.1.0" # Released on 2022-12-01
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/commonmark/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "0.9.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/docutils/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "0.20.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/flake8-bugbear/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "23.5.9"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/flake8-builtins/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "2.1.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/flake8-docstrings/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "1.7.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/flake8-plugin-utils/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "1.3.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/flake8-rst-docstrings/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "0.3.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/flake8-simplify/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "0.20.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/flake8-typing-imports/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "1.14.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/google-cloud-ndb/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "2.1.*"
partial_stub = true

[tool.stubtest]
stubtest_requirements = ["protobuf==3.20.2"]
Expand Down
1 change: 1 addition & 0 deletions stubs/html5lib/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "1.1.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
Expand Down
1 change: 1 addition & 0 deletions stubs/invoke/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "2.0.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/jsonschema/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "4.17.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
Expand Down
1 change: 1 addition & 0 deletions stubs/ldap3/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version = "2.9.*"
requires = ["types-pyasn1"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
Expand Down
1 change: 1 addition & 0 deletions stubs/oauthlib/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "3.2.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/openpyxl/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "3.1.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/opentracing/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "2.4.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/paramiko/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "3.0.*"
# Requires a version of cryptography where cryptography.hazmat.primitives.ciphers.Cipher is generic
requires = ["cryptography>=37.0.0"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
Expand Down
1 change: 1 addition & 0 deletions stubs/pep8-naming/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "0.13.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/protobuf/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version = "4.23.*"
extra_description = "Generated with aid from mypy-protobuf v3.4.0"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/psycopg2/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "2.9.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/pyOpenSSL/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "23.1.*"
# Requires a version of cryptography with a `py.typed` file
requires = ["cryptography>=35.0.0"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/pyflakes/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "3.0.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/python-datemath/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "1.5.*"
# Requires a version of arrow with a `py.typed` file
requires = ["arrow>=1.0.1"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/python-dateutil/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "2.8.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/pyvmomi/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version = "8.0.0.*"
obsolete_since = "8.0.1.0" # Released on 2023-05-05
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/redis/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "4.5.5"
# Requires a version of cryptography with a `py.typed` file
requires = ["cryptography>=35.0.0", "types-pyOpenSSL"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
Expand Down
1 change: 1 addition & 0 deletions stubs/setuptools/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "67.7.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/simplejson/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "3.19.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/stripe/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "3.5.*"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/tensorflow/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "2.12.*"
# requires a version of numpy with a `py.typed` file
requires = ["numpy>=1.20", "types-protobuf"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
1 change: 1 addition & 0 deletions stubs/urllib3/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version = "1.26.*"
obsolete_since = "2.0.0" # Released on 2023-04-26
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
Expand Down
1 change: 1 addition & 0 deletions stubs/waitress/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version = "2.1.*"
requires = []
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
Expand Down
16 changes: 15 additions & 1 deletion tests/parse_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,22 @@ class StubMetadata:
obsolete_since: Annotated[str, "A string representing a specific version"] | None
no_longer_updated: bool
uploaded_to_pypi: Annotated[bool, "Whether or not a distribution is uploaded to PyPI"]
partial_stub: Annotated[bool, "Whether this is a partial type stub package as per PEP 561."]
stubtest_settings: StubtestSettings


_KNOWN_METADATA_FIELDS: Final = frozenset(
{"version", "requires", "extra_description", "stub_distribution", "obsolete_since", "no_longer_updated", "upload", "tool"}
{
"version",
"requires",
"extra_description",
"stub_distribution",
"obsolete_since",
"no_longer_updated",
"upload",
"tool",
"partial_stub",
}
)
_KNOWN_METADATA_TOOL_FIELDS: Final = {
"stubtest": {
Expand Down Expand Up @@ -190,6 +201,8 @@ def read_metadata(distribution: str) -> StubMetadata:
assert type(no_longer_updated) is bool
uploaded_to_pypi: object = data.get("upload", True)
assert type(uploaded_to_pypi) is bool
partial_stub: object = data.get("partial_stub", True)
assert type(partial_stub) is bool

empty_tools: dict[object, object] = {}
tools_settings: object = data.get("tool", empty_tools)
Expand All @@ -209,6 +222,7 @@ def read_metadata(distribution: str) -> StubMetadata:
obsolete_since=obsolete_since,
no_longer_updated=no_longer_updated,
uploaded_to_pypi=uploaded_to_pypi,
partial_stub=partial_stub,
stubtest_settings=read_stubtest_settings(distribution),
)

Expand Down

0 comments on commit db01498

Please sign in to comment.