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

docs/api: clean up Upload API docs slightly #17514

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

woodruffw
Copy link
Member

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:

  • Made formatting more uniform: list items now mostly start with the field they're describing, instead of describing the field in free-form prose.
  • Elaborated on the description of how metadata is transformed into form fields, including a description of how multiple-use fields are pluralized (Classifier -> classifiers). Also added a table visualizing the different cases.
  • Added a clarifying link about the format of pyversion Python tags.
  • Replaced i.e. with e.g. where appropriate.

I think this (along with the other recent upload API doc changes) is sufficient to close #3151 🙂

Signed-off-by: William Woodruff <william@trailofbits.com>
Comment on lines 47 to 62
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**.
Copy link
Member

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:

# 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}

Copy link
Member Author

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:

  1. "Email" representation: License-File
  2. "pyproject" representation: license-files
  3. "Raw" representation: license_files
  4. "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:

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 🙂

Copy link
Member Author

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document data format for upload API
2 participants