fix(python): normalize dependency names in PEP 621 pyproject.toml - #11050
Merged
DmitriyLewen merged 2 commits intoAug 6, 2026
Merged
Conversation
PEP 621 dependencies ([project].dependencies) were stored without name normalization, unlike the Poetry v1 branch which normalizes via python.NormalizePkgName. Since poetry.lock and pylock.toml store PEP 503 normalized names, a PEP 621 dependency written non-normalized (e.g. Flask, typing_extensions, ruamel.yaml) never matches its lock entry, so it is reported as indirect and, together with its transitive subtree, marked as a dev dependency. Normalize the name in the PEP 621 branch as well.
Fold the normalization fixture into `happy_v2.toml` instead of keeping a separate file. Make the `pyproject.toml` fixtures of the poetry and pylock analyzers use non-normalized names. Their expectations are unchanged, so both tests now fail if the normalization is dropped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PEP 621 dependencies (
[project].dependencies, used by Poetry v2 and other PEP 621 backends) are stored without name normalization, while Poetry v1 dependencies ([tool.poetry.dependencies]) are normalized viapython.NormalizePkgName.poetry.lockandpylock.tomlstore PEP 503 normalized names, so a PEP 621 dependency written in non-normalized form (canonical casing,_, or., e.g.Flask,typing_extensions,ruamel.yaml) never matches its lock entry.The consequence is in the poetry/pylock analyzers, which look up the direct dependencies by name (
dirDeps.Contains(pkg.Name)/prodRootDeps.Contains(pkg.Name)) against the normalized lock names. A direct dependency that fails to match is reported as indirect, and since the production-dependency walk starts from the direct set, that package and its transitive subtree end up markedDev: true. With--include-dev-deps=falsethey drop from the SBOM/scan, and the root -> dependency edge is lost from the graph.Example:
[project]withdependencies = ["Flask (==1.0.3)"]and apoetry.lockcontainingname = "flask":The fix normalizes the PEP 621 name the same way the Poetry v1 branch already does.
How I tested
Added a
TestPyProject_MainDepscase (testdata/normalize_v2.toml) withFlask,typing_extensions, andruamel.yaml, asserting the normalized set{flask, typing-extensions, ruamel-yaml}. It fails onmain(the set keeps the raw names) and passes with the change.go test ./pkg/dependency/parser/python/... ./pkg/fanal/analyzer/language/python/...stays green.Checklist