Skip to content

Add utility to select things with compatible tags#1110

Open
sbidoul wants to merge 1 commit intopypa:mainfrom
sbidoul:select-best-wheel-sbi
Open

Add utility to select things with compatible tags#1110
sbidoul wants to merge 1 commit intopypa:mainfrom
sbidoul:select-best-wheel-sbi

Conversation

@sbidoul
Copy link
Member

@sbidoul sbidoul commented Mar 8, 2026

Coming from #1092 (comment), this PR proposes a utility to select things that best match an ordered list of tags.

It works like this, for instance, to select compatible wheel filenames:

    >>> filenames = ["foo-1.0-py3-none-any.whl", "foo-1.0-py2-none-any.whl"]
    >>> selector = create_compatible_tags_selector(tags.sys_tags())
    >>> compatible_filenames = list(selector([
    ...     (filename, parse_wheel_filename(filename)[-1]) for filename in filenames
    ... ]))
    ["foo-1.0-py3-none-any.whl"]

@sbidoul
Copy link
Member Author

sbidoul commented Mar 8, 2026

@brettcannon how do you like this one?

@sbidoul sbidoul force-pushed the select-best-wheel-sbi branch 6 times, most recently from 08ce96f to 8a3a7ec Compare March 8, 2026 13:38
@sbidoul sbidoul force-pushed the select-best-wheel-sbi branch from 8a3a7ec to 2cf7143 Compare March 8, 2026 15:13
@sbidoul
Copy link
Member Author

sbidoul commented Mar 8, 2026

I made it return an iterator to allow for possible future optimizations.

So obtaining the best compatible wheel looks like this:

    >>> filenames = ["foo-1.0-py3-none-any.whl", "foo-1.0-py2-none-any.whl"]
    >>> selector = create_compatible_tags_selector(tags.sys_tags())
    >>> next(selector([
    ...     (filename, parse_wheel_filename(filename)[-1]) for filename in filenames
    ... ]), None)
    "foo-1.0-py3-none-any.whl"

@sbidoul
Copy link
Member Author

sbidoul commented Mar 18, 2026

The first question here is if this seems worthwhile as a public API. If yes, we can refine it. If not, or if in doubt for now, I'll include this as a private API in #1092.

@brettcannon
Copy link
Member

I think it makes sent to make this public! I had one small improvement, otherwise LGTM!

@henryiii
Copy link
Contributor

Does this work with manylinux / linux correctly? In the past, manylinx/musllinux was placed at the wrong place in tags, causing the general manylinux to come before the specific linux tag, which means this would pick a generic manylinux wheel over a local compile.

If so, it should probably come with a warning in the docs at least?

Copy link
Member

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

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

I think this is just missing docs.

@henryiii
Copy link
Contributor

I think you'll automatically get docs if you add it to __all__.

@sbidoul
Copy link
Member Author

sbidoul commented Mar 24, 2026

Does this work with manylinux / linux correctly? In the past, manylinx/musllinux was placed at the wrong place in tags, causing the general manylinux to come before the specific linux tag, which means this would pick a generic manylinux wheel over a local compile.

It indeed seems tags.sys_tags() returns manylinux tags before corresponding linux tags.

If so, it should probably come with a warning in the docs at least?

So in the docs of sys_tags() ?

@sbidoul
Copy link
Member Author

sbidoul commented Mar 24, 2026

I think you'll automatically get docs if you add it to __all__.

@henryiii docs/tags.rst is not prepared for that yet? Although I was sure to have seen a PR (from you?) to improve that but I don't find it now.

@brettcannon
Copy link
Member

Does this work with manylinux / linux correctly? In the past, manylinx/musllinux was placed at the wrong place in tags, causing the general manylinux to come before the specific linux tag, which means this would pick a generic manylinux wheel over a local compile.

If so, it should probably come with a warning in the docs at least?

That's #160 so I think it's a separate issue from this PR.

@brettcannon
Copy link
Member

I think you'll automatically get docs if you add it to __all__.

@henryiii docs/tags.rst is not prepared for that yet? Although I was sure to have seen a PR (from you?) to improve that but I don't find it now.

@sbidoul did you want to wait for something like that or do a quick doc change by copying the docstring?

@henryiii
Copy link
Contributor

I did some of them, I can see about that one.

@sbidoul sbidoul force-pushed the select-best-wheel-sbi branch 4 times, most recently from 9da74b3 to f96c179 Compare March 24, 2026 18:03
@sbidoul
Copy link
Member Author

sbidoul commented Mar 24, 2026

I updated tags.rst and fixed the doctest.

@henryiii
Copy link
Contributor

Made #1130.

@sbidoul sbidoul force-pushed the select-best-wheel-sbi branch from f96c179 to 19a34e9 Compare March 25, 2026 06:56
@sbidoul sbidoul force-pushed the select-best-wheel-sbi branch 2 times, most recently from fa50510 to 344f912 Compare March 25, 2026 07:04
@sbidoul sbidoul force-pushed the select-best-wheel-sbi branch from 344f912 to 77d69c7 Compare March 25, 2026 07:08
@sbidoul
Copy link
Member Author

sbidoul commented Mar 25, 2026

Thanks! Docs updated.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants