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

add VersionMap helper #542

Merged
merged 1 commit into from
Jan 30, 2025
Merged

Conversation

dhellmann
Copy link
Member

Resolves #489

Copy link
Contributor

@rd4398 rd4398 left a comment

Choose a reason for hiding this comment

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

This looks good!

@prarit
Copy link
Contributor

prarit commented Jan 29, 2025

@dhellmann I think there's a minor error in the lookup() code. See 7749583 . I'm testing a patch right now.

@dhellmann
Copy link
Member Author

@dhellmann I think there's a minor error in the lookup() code. See 7749583 . I'm testing a patch right now.

@prarit I'm not quite sure I understand, but I think the tests here and here demonstrate that a requirement without a version specifier works with and without constraints.

If I'm wrong, could you add a comment to the tests with an assert that would fail?

@dhellmann
Copy link
Member Author

I added a test for the flag for allowing pre-release versions.

@prarit
Copy link
Contributor

prarit commented Jan 30, 2025

@dhellmann I think there's a minor error in the lookup() code. See 7749583 . I'm testing a patch right now.

@prarit I'm not quite sure I understand, but I think the tests here and here demonstrate that a requirement without a version specifier works with and without constraints.

If I'm wrong, could you add a comment to the tests with an assert that would fail?

So it's not the check as I thought but an issue with existing version maps in builder. The aotriton versionmap can be tested as:

`def test_with_constraint_fails():

m = VersionMap({Version("0.4.1b0"): "0.4.1b", Version("0.6b0"): "0.6b"})
assert m.lookup(Requirement("pkg"), Requirement("pkg<0.6b0")) == "0.4.1b0"
`
which will fail as the lookup() call returns "0.4.1b", not 0.4.1b0 as the current builder:package_plugins/utils.py:resolve_specifier() does. It seems that the versionmap for aotriton is valid. Let's discuss in the AM :)

[edit: I should add, the difference between the string and the Version in the VersionMap is intentional. The Version refers to the python package name, and the string refers to the github tarball name. Setting allow_prerelease=True does not seem to help. We could (should?) perhaps separate the builder python package and tarball name mapping into their own maps as a solution.]

[edit2 post workout clarity: Another solution here is to write a builder helper function in package_plugins/utils.py that 'does the right thing' and creates a versionmap with matching values to pass into the fromager code. That seems way easier and smarter IMO. That way there's no rewriting of builder code Version usage. Let me code that in the AM. It's a bit late now. Hope you're okay with the delay @dhellmann ]

@dhellmann dhellmann force-pushed the versionmap-type branch 2 times, most recently from a7b0c17 to 533c716 Compare January 30, 2025 13:42
@dhellmann
Copy link
Member Author

`def test_with_constraint_fails():

m = VersionMap({Version("0.4.1b0"): "0.4.1b", Version("0.6b0"): "0.6b"}) assert m.lookup(Requirement("pkg"), Requirement("pkg<0.6b0")) == "0.4.1b0" ` which will fail as the lookup() call returns "0.4.1b", not 0.4.1b0 as the current builder:package_plugins/utils.py:resolve_specifier() does. It seems that the versionmap for aotriton is valid. Let's discuss in the AM :)

[edit: I should add, the difference between the string and the Version in the VersionMap is intentional. The Version refers to the python package name, and the string refers to the github tarball name. Setting allow_prerelease=True does not seem to help. We could (should?) perhaps separate the builder python package and tarball name mapping into their own maps as a solution.]

The map doesn't do the same thing as the resolver function. The resolver tells you a version that matches. The map figures that value out, then returns the corresponding value in the dictionary.

I've changed the API to return both the version and the value, and updated the test content to make it clearer which is which.

Copy link
Contributor

@rd4398 rd4398 left a comment

Choose a reason for hiding this comment

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

This looks good!

@mergify mergify bot merged commit 431f479 into python-wheel-build:main Jan 30, 2025
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add a VersionMap type
3 participants