Skip to content

Comments

Always normalize recursive extras in dependency metadata#10794

Closed
charliermarsh wants to merge 3 commits intomainfrom
charlie/flatten-extras
Closed

Always normalize recursive extras in dependency metadata#10794
charliermarsh wants to merge 3 commits intomainfrom
charlie/flatten-extras

Conversation

@charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Jan 20, 2025

Summary

Some build backends flattten recursive extras, while others do not (see: https://discuss.python.org/t/core-metadata-for-self-referential-extras/77793/6). If a build backend does flatten its recursive extras, then if we read requirements from the pyproject.toml directly, and compare those requirements to the build backend-returned metadata (as is the case for, e.g., dynamic versions), the comparison will fail.

Instead, the DistributionDatabase now always returns metadata with these recursive extras normalized out.

Closes #10776.

@charliermarsh charliermarsh force-pushed the charlie/flatten-extras branch from a287d85 to ded17cc Compare January 20, 2025 22:57
@charliermarsh charliermarsh added the bug Something isn't working label Jan 20, 2025
@charliermarsh charliermarsh force-pushed the charlie/flatten-extras branch from ded17cc to 21e42e1 Compare January 20, 2025 23:04
@charliermarsh charliermarsh added the no-build Disable building binaries in CI label Jan 20, 2025
})
{
return false;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is pretty weird, but we have a lot of lockfile tests (lock_self_*) that test cases in which a package depends on itself, and puts a version specifier on that dependency. I don't think we can drop those.

For example:

[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["typing-extensions", "project==0.1.0"]

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not fully comfortable with this whole situation, self-dependencies seem to be poorly specified right now...

For example, Hatchling drops the ==0.2.0 in the foo extra here:

[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = []

[project.optional-dependencies]
foo = ["project[bar]==0.2.0"]
bar = ["iniconfig"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

Copy link
Member

Choose a reason for hiding this comment

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

I tried but couldn't reproduce this:

[project]
name = "hatch-drops-self-specifier"
version = "0.1.0"

[project.optional-dependencies]
foo = ["project[bar]==0.2.0"]
bar = ["iniconfig"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
rm -rf venv
uv venv
uv build
uv pip install --find-links dist hatch-drops-self-specifier --no-cache
cat .venv/lib/python3.*/site-packages/hatch_drops_self_specifier-0.1.0.dist-info/METADATA
Metadata-Version: 2.4
Name: hatch-drops-self-specifier
Version: 0.1.0
Provides-Extra: bar
Requires-Dist: iniconfig; extra == 'bar'
Provides-Extra: foo
Requires-Dist: project[bar]==0.2.0; extra == 'foo'

@charliermarsh charliermarsh force-pushed the charlie/flatten-extras branch from 7b950ea to 543b05a Compare January 20, 2025 23:37
@charliermarsh charliermarsh added this to the v0.6.0 milestone Jan 21, 2025
@charliermarsh
Copy link
Member Author

I might make this part of v0.6, and do a smaller fix for the linked issue.

charliermarsh added a commit that referenced this pull request Jan 21, 2025
## Summary

This is a smaller alternative to #10794. If the `Requires-Dist` that we
extract statically doesn't match the lockfile metadata, we now go back
to the distribution database to double-check. Checking the
`Requires-Dist` is itself very cheap, so in the worst case, we're just
paying the same cost as prior to this optimization.

Closes #10776.
@konstin
Copy link
Member

konstin commented Jan 21, 2025

(I'll wait with reviewing on how https://discuss.python.org/t/core-metadata-for-self-referential-extras/77793 goes, maybe we don't need to do this because we agree on not flattening)

@charliermarsh
Copy link
Member Author

That conversation is sort of irrelevant for solving #10776 though. The behavior already exists.

@charliermarsh charliermarsh marked this pull request as draft January 21, 2025 18:06
charliermarsh added a commit that referenced this pull request Jan 21, 2025
## Summary

I needed this for #10794, but it
makes sense as a standalone change, since it's much more testable. We
can also reuse this in at least one more place.
@charliermarsh
Copy link
Member Author

Let's just skip this for now.

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

Labels

bug Something isn't working no-build Disable building binaries in CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possibly broken uv lock after upgrading from 0.5.20 to 0.5.21

2 participants