Skip to content

fix: use PEP 503 normalized names in Simple API distribution URLs - #1158

Open
juliosuas wants to merge 2 commits into
CycloneDX:mainfrom
juliosuas:fix/1154
Open

juliosuas wants to merge 2 commits into
CycloneDX:mainfrom
juliosuas:fix/1154

Conversation

@juliosuas

Copy link
Copy Markdown
Contributor

Description

Implicit distribution URLs built from a package index used the raw requirement name (.../simple/Flask_SQLAlchemy/). PEP 503 requires clients to request /<normalized-name>/ and redirects are optional, so these URLs 404 on static PEP 503 mirrors (S3/Nginx) and local directories.

This PR applies the existing normalize_packagename() helper to the URL path segment in:

  • requirements: implicit dist url and implicit dist extra-url
  • pipenv: from explicit index / from implicit index: pypi
  • poetry: from legacy-api

Component name and purl are unchanged.

Resolves #1154

Tests

  • New fixture tests/_data/infiles/requirements/unnormalized-names.txt (with --index-url and --extra-index-url) and its snapshots.
  • Regenerated snapshots for existing pipenv/poetry/requirements fixtures whose URLs now use the normalized name (e.g. ruamel.yaml.clib -> ruamel-yaml-clib).
  • python -m unittest discover -t . -s tests: 1463 tests, only the TestCliEnvironment.setUpClass testbed error that also occurs on main in my sandbox (it needs network to build the venv testbeds). flake8 and mypy clean.

AI Tool Disclosure

  • My contribution includes AI-generated content: drafted with an AI assistant, reviewed and tested by me.

Affirmation

  • My code follows the CONTRIBUTING.md guidelines

The implicit distribution URLs built from an index (requirements
--index-url/--extra-index-url, Pipfile.lock indexes, poetry legacy
sources) interpolated the raw requirement name. PEP 503 requires
clients to request /<normalized-name>/ and makes redirects optional,
so names such as Flask_SQLAlchemy, PyYAML or ruamel.yaml.clib produced
URLs that 404 on static PEP 503 mirrors and local directories.

Apply normalize_packagename() to those URL path segments. Component
names and PURLs are unchanged.

fixes CycloneDX#1154

Signed-off-by: Julio César Suástegui <5745504+juliosuas@users.noreply.github.com>
@juliosuas
juliosuas requested a review from a team as a code owner November 26, 2026 17:14
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity ✅ 0 (≤ 20 complexity)
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@jkowalleck jkowalleck added the bug Something isn't working label Nov 27, 2026

@jkowalleck jkowalleck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation and tests look good. 👍

just very litle refactoring needed to streamline things

Comment thread cyclonedx_py/_internal/requirements.py Outdated
# url based on https://warehouse.pypa.io/api-reference/legacy.html
# PEP 503 requires clients to request the normalized project name
# see https://packaging.python.org/en/latest/specifications/simple-repository-api/#project-detail
simple_name = normalize_packagename(name) if name else name

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets call it name_normalized

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets rename this to normalize-packagename.txt - aligned with tests/_data/infiles/pipenv/normalize-packagename

Call the normalized package name name_normalized in _make_component,
and rename the requirements fixture to normalize-packagename.txt so it
matches tests/_data/infiles/pipenv/normalize-packagename.

Signed-off-by: Julio César Suástegui <5745504+juliosuas@users.noreply.github.com>
@juliosuas

Copy link
Copy Markdown
Contributor Author

@jkowalleck thanks! Both done in e851746: simple_name is now name_normalized, and the fixture is normalize-packagename.txt (its snapshots renamed with it, content unchanged). flake8, mypy and the unit tests pass locally, also with current main merged in. The Actions workflows are waiting for approval to run whenever you get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Simple API distribution URLs use raw package names instead of PEP 503 normalized names

2 participants