Skip to content

Stop wheel filename parsing from retrying every hyphen split - #5347

Open
Cherith1222 wants to merge 1 commit into
pypa:mainfrom
Cherith1222:fix/4087-wheel-filename-regex
Open

Cherith1222 wants to merge 1 commit into
pypa:mainfrom
Cherith1222:fix/4087-wheel-filename-regex

Conversation

@Cherith1222

Copy link
Copy Markdown

Summary of changes

setuptools.wheel.Wheel parses filenames with WHEEL_NAME. The old pattern used several .+? groups, so one long run of hyphens retried every split and got slower as the run grew. The name, version, optional build, Python tag, and ABI now use [^\s-], so they stop at a hyphen or whitespace. The platform group is \S+, so a compressed tag can still contain dots, and a hyphen in that last field stays in the platform. The version still has to start with a digit (\d), which WHEEL_NAME already required. This is the same hyphen and whitespace constraint as WHEEL_INFO_RE in pypa/wheel, except wheel does not require the version to start with a digit.

Wheel('0-0' + '-' * 200) raises ValueError before and after this change. On Windows with Python 3.13.3, that call took about 0.601 seconds before and about 0.000010 seconds after. test_wheel_filename_hyphen_run_is_quick rejects a 200-hyphen run, with and without .whl, in under 0.5 seconds.

The existing WHEEL_INFO_TESTS filenames stay, including simple.dist-0.1-py2.py3-none-any.whl, a build tag, and PyQt5. Added cases parse foo-2-py2.py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl and test-1.0+what-py3-none-any.whl (version is 1.0+what). test-1.0-py2.whl, test-1.0-py2-none.whl, and test-1.0-py2-none-any raise ValueError.

A distribution name that itself contains a hyphen no longer parses. my-project-1.0-py3-none-any.whl used to parse with project_name my-project and version 1.0. The name group cannot cross a hyphen, and the following field is not a version starting with a digit, so Wheel now raises ValueError. A space in a tag also no longer parses: test-1.0-py 2-none-any.whl used to parse with py_version py 2 and now raises ValueError. bdist_wheel.wheel_dist_name builds the written distribution name with safer_name and safer_version, and both replace - with _ before that name is used. get_tag replaces -, ., and spaces in the platform tag with _.

newsfragments/4087.bugfix.rst is named with issue 4087, which is what newsfragments/README.rst asks for when an issue exists. The fragment does not need this pull request's number:

Fixed wheel filename parsing so a long run of hyphens finishes quickly.

On Windows, Python 3.13.3, pytest 8.4.2, setuptools/tests/test_wheel.py with test_wheel_install[extension] deselected reported 29 passed and 1 deselected. That deselected test compiles an extension. setuptools/tests/test_dist.py::test_dist_fetch_build_egg passed. That test calls Wheel on the wheel pip wrote.

Closes #4087.

Pull Request Checklist

AI-assisted (Cursor).

A long run of hyphens made the old pattern slower as the run grew. Components other than the platform now stop at a hyphen, as in pypa/wheel, and spec-legal names still parse to the same fields.

Fixes pypa#4087.

AI-assisted (Cursor).
@mergify

mergify Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

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.

[BUG] Inneficient Regex

1 participant