-
Notifications
You must be signed in to change notification settings - Fork 989
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
docs/api: clean up Upload API docs slightly #17514
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: William Woodruff <william@trailofbits.com>
docs/user/api/upload.md
Outdated
by underscores. Additionally, multiple-use fields (like `Classifier`) | ||
are pluralized. | ||
|
||
The table below provides examples: | ||
|
||
| Metadata field | Form field | | ||
|----------------|------------| | ||
| `Description-Content-Type` | `description_content_type` | | ||
| `License-File` | `license_files` | | ||
| `Classifier` | `classifiers` | | ||
|
||
!!! warning | ||
|
||
The transformation above *must* be performed. | ||
Sending a form field like `Description-Content-Type` will not raise an | ||
error but will be **silently ignored**. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is exactly true or if there are some edge cases. I haven't looked closely but some fields are getting mapped here while others like classifier
/classifiers
aren't:
warehouse/warehouse/forklift/metadata.py
Lines 270 to 276 in 80d26fd
# Map Form fields to RawMetadata | |
_override = { | |
"platforms": "platform", | |
"supported_platforms": "supported_platform", | |
"license_files": "license_file", | |
} | |
_FORM_TO_RAW_MAPPING = {_override.get(k, k): k for k in _RAW_TO_EMAIL_MAPPING} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is confusing: _RAW_TO_EMAIL_MAPPING
contains the classifier -> classifiers
pluralization as expected, but then _FORM_TO_RAW_MAPPING
overrides that pluralization for those three cases.
In other words, the mapping for License-File
goes:
- "Email" representation:
License-File
- "pyproject" representation:
license-files
- "Raw" representation:
license_files
- "POST form" representation:
license_file
As best I can tell representation (1)-(3) are defined in PEP 639, while representation (4) is a bit of a wild west (since it's particular to PyPI's upload API, not packaging standards). In the case of license_file
it looks like Hatch was the earliest adopter and chose not to pluralize the form field, so other implementations have followed suit:
twine
also useslicense_file
, probably following Hatch: https://github.com/pypa/twine/blob/353e0e4e2b02acedff37d00d52f26de056e33e55/twine/package.py#L152
TL;DR: As best I can tell these three fields are the only exceptions to the "multi-use fields get pluralized in the POST form representation" rule, so I'll update the docs to reflect that.
CC @ofek @brettcannon for thoughts as well 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: William Woodruff <william@trailofbits.com>
This is an attempt to clean up the Upload API docs (very) slightly, as well as document some other well-known edge cases/discrepancies between the metadata layout and the POST form layout.
Key changes:
Classifier -> classifiers
). Also added a table visualizing the different cases.pyversion
Python tags.I think this (along with the other recent upload API doc changes) is sufficient to close #3151 🙂