Skip to content

Commit 0605ef0

Browse files
authored
Switch to packaging for parsing metadata and support metadata 2.4 (#1180)
* Remove "content" from set of specially handled metadata fields The "content" field is always added to the form data after the package metadata has been flattened, thus it is not needed to handle it in the flattening method. Remove the associated test. This will allow to tighten typing in a successive commit. * Remove "attestations" from the set of specially handled metadata fields The "attestations" field is a string: strings do not need flattening. * Refactor code a tiny bit Avoid looking a key up into a set of one element and remove an indirection through a module global variable. This will make it a bit easier to extend the flattening logic in successive commits. * Switch from pkginfo to packaging for parsing distribution metadata The packaging package is maintained by the PyPA and it is the de-facto reference implementation for the packaging standards. Using packaging for parsing metadata guarantees support for the latest metadata versions. warehouse, the Python package index implementation used by PyPI, also uses packaging for parsing metadata. This guarantees that metadata parsing is the same on the client and server side, for the most prominent index. * Enable some more mypy checks * Move monkeypatching of metadata 2.0 support to a more proper place It was done in the support code for the wheel file format but it affects metadata loading from all supported distribution types. Move it to generic code. * Accommodate for invalid metadata produced by setuptools See pypa/setuptools#4759.
1 parent 1703ae7 commit 0605ef0

17 files changed

+714
-351
lines changed

changelog/1180.misc.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- ``packaging`` is used instead of ``pkginfo`` for parsing and validating
2+
metadata. This aligns metadata validation to the one performed by PyPI.
3+
``packaging`` version 24.0 or later is required. Support for metadata
4+
version 2.4 requires ``packaging`` 24.2 or later. ``pkginfo`` is not a
5+
dependency anymore.
6+
- With ``packaging`` version 24.2 or later, metadata fields added with
7+
metadata version 2.4 as defined by PEP 639 are now sent to the package index
8+
when a distribution is uploaded. This results in licensing information to
9+
appear correctly on the package page on PyPI when uploading packages using
10+
metadata version 2.4.

docs/conf.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,12 @@
283283
intersphinx_mapping = {
284284
"python": ("https://docs.python.org/3", None),
285285
"requests": ("https://requests.readthedocs.io/en/latest/", None),
286+
"packaging": ("https://packaging.pypa.io/en/latest/", None),
286287
}
287288

288289
# Be strict about the invalid references:
289290
nitpicky = True
290291

291-
# TODO: Try to add these to intersphinx_mapping
292-
nitpick_ignore_regex = [
293-
(r"py:.*", r"pkginfo.*"),
294-
("py:class", r"warnings\.WarningMessage"),
295-
]
296-
297292
# -- Options for apidoc output ------------------------------------------------
298293

299294
autodoc_default_options = {

mypy.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ show_traceback = True
55
warn_redundant_casts = True
66
warn_unused_configs = True
77
warn_unused_ignores = True
8-
; Enabling this will fail on subclasses of untyped imports, e.g. pkginfo
9-
; disallow_subclassing_any = True
8+
disallow_subclassing_any = True
109
disallow_any_generics = True
1110
disallow_untyped_calls = True
1211
disallow_untyped_defs = True

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ classifiers = [
3131
]
3232
requires-python = ">=3.8"
3333
dependencies = [
34-
"pkginfo >= 1.8.1",
3534
"readme-renderer >= 35.0",
3635
"requests >= 2.20",
3736
"requests-toolbelt >= 0.8.0, != 0.9.0",
@@ -41,7 +40,7 @@ dependencies = [
4140
"keyring >= 15.1; platform_machine != 'ppc64le' and platform_machine != 's390x'",
4241
"rfc3986 >= 1.4.0",
4342
"rich >= 12.0.0",
44-
"packaging",
43+
"packaging >= 24.0",
4544
"id",
4645
]
4746
dynamic = ["version"]

tests/fixtures/everything.metadata

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Metadata-Version: 2.4
2+
Name: BeagleVote
3+
Version: 1.0a2
4+
Platform: ObscureUnix
5+
Platform: RareDOS
6+
Supported-Platform: RedHat 7.2
7+
Supported-Platform: i386-win32-2791
8+
Summary: A module for collecting votes from beagles.
9+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
10+
Keywords: dog,puppy,voting,election
11+
Home-page: http://www.example.com/~cschultz/bvote/
12+
Download-URL: …/BeagleVote-0.45.tgz
13+
Author: C. Schultz, Universal Features Syndicate,
14+
Los Angeles, CA <cschultz@peanuts.example.com>
15+
Author-email: "C. Schultz" <cschultz@example.com>
16+
Maintainer: C. Schultz, Universal Features Syndicate,
17+
Los Angeles, CA <cschultz@peanuts.example.com>
18+
Maintainer-email: "C. Schultz" <cschultz@example.com>
19+
License: This software may only be obtained by sending the
20+
author a postcard, and then the user promises not
21+
to redistribute it.
22+
License-Expression: Apache-2.0 OR BSD-2-Clause
23+
License-File: LICENSE.APACHE
24+
License-File: LICENSE.BSD
25+
Classifier: Development Status :: 4 - Beta
26+
Classifier: Environment :: Console (Text Based)
27+
Provides-Extra: pdf
28+
Requires-Dist: reportlab; extra == 'pdf'
29+
Requires-Dist: pkginfo
30+
Requires-Dist: PasteDeploy
31+
Requires-Dist: zope.interface (>3.5.0)
32+
Requires-Dist: pywin32 >1.0; sys_platform == 'win32'
33+
Requires-Python: >=3
34+
Requires-External: C
35+
Requires-External: libpng (>=1.5)
36+
Requires-External: make; sys_platform != "win32"
37+
Project-URL: Bug Tracker, http://bitbucket.org/tarek/distribute/issues/
38+
Project-URL: Documentation, https://example.com/BeagleVote
39+
Provides-Dist: OtherProject
40+
Provides-Dist: AnotherProject (3.4)
41+
Provides-Dist: virtual_package; python_version >= "3.4"
42+
Dynamic: Obsoletes-Dist
43+
44+
This description intentionally left blank.

tests/fixtures/twine-1.5.0.zip

34.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)