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"

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.

1 participant