Skip to content

Truncate Pypi package metadata fields

What does this MR do and why?

This is a follow-up to these MRs:

When we introduced new metadata fields with text limits, some packages encountered errors during uploading due to the text limit. We addressed the most common cases in the 2 MRs above, but there are still some metadata fields that are prone to the error:

  • summary
  • author_email
  • required_python
  • metadata_version (this is generated by Twine and not set from pyproject.toml)
  • description_content_type

This MR applies the truncation solution from !137000 (merged) into the other metadata fields listed above.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

No UI changes 🌈

How to set up and validate locally

  1. Install the prerequisites
  1. Clone this python package
  2. Modify pyproject.toml to make some fields exceed the maximum length constraints. You can do one or more of the following:
  • Change the value of the authors key to make it exceed 2048 characters. You can copy the single author line multiple times.
  • Add a requires_python key under the [project] section. Set it to a string longer than 255 characters.
  1. Build the package. From the package directory, run python3 -m build
  2. Setup authentication following our guide
  3. Upload the package. From the package directory, run python3 -m twine upload --verbose --repository gitlab dist/*.

NOTE: The upload will fail if you try to upload a version that already exists. Delete the existing version in Package Registry, or build and upload a different version.

Expected response when running the MR branch:

Uploading python_benedict-0.33.1-py3-none-any.whl
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 kB • 00:00 • 134.5 MB/s
INFO     Response from http://gdk.test:3000/api/v4/projects/47/packages/pypi:                                                                                                                               
         201 Created                                                                                                                                                                                        
INFO     {"message":"201 Created"}                                                                                                                                                                          
Uploading python-benedict-0.33.1.tar.gz
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 99.8/99.8 kB • 00:00 • 138.6 MB/s
INFO     Response from http://gdk.test:3000/api/v4/projects/47/packages/pypi:                                                                                                                               
         201 Created                                                                                                                                                                                        
INFO     {"message":"201 Created"}  

In the master branch, the upload will fail:

Uploading python_benedict-0.33.1-py3-none-any.whl
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 kB • 00:00 • 133.5 MB/s
INFO     Response from http://gdk.test:3000/api/v4/projects/47/packages/pypi:                                                                                                                               
         400 Bad Request                                                                                                                                                                                    
INFO     {"message":"400 Bad request - Validation failed: Keywords is too long (maximum is 255 characters)"}                                                                                                
ERROR    HTTPError: 400 Bad Request from http://gdk.test:3000/api/v4/projects/47/packages/pypi                                                                                                              
         Bad Request        
  1. View the uploaded package in the package registry. The Additional metadata section should show the truncated text for:
  • Required Python
  • Summary
  • Keywords
  • Author email

Related to #444304

Edited by Radamanthus Batnag

Merge request reports