-
Notifications
You must be signed in to change notification settings - Fork 250
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
Fix version pattern pre-releases #705
Conversation
This commit fixes a precedence issue with version pre-release tags. Relational --- The `version` module exports `VERSION_PATTERN`. Directly using it, might not produce expected results for pre-releases. ```py >>> import re >>> from packaging.version import VERSION_PATTERN >>> re.match(VERSION_PATTERN, "1.0.0-alpha1") <re.Match object; span=(0, 7), match='1.0.0-a'> ``` Trailing `1` from `-alpha1` is not matched, because previous pattern preferred consuming only `a` instead of `alpha` due to missing word boundary checks. Simplest solution is to re-order tokens, so regexp prefers longer tokens over their abbreviation. ```py >>> import re >>> from packaging.version import VERSION_PATTERN >>> re.match(VERSION_PATTERN, "1.0.0-alpha1") <re.Match object; span=(0, 12), match='1.0.0-alpha1'> ``` Note: This commit also removes an unnecessary capture group.
Is there an open issue for this? |
Since packaging/src/packaging/version.py Lines 146 to 156 in 3030822
|
A public value wouldn't have any value for me as I can't use this package anyway, due to the need of supporting python 3.3 I just stumbled about the pattern not doing what I expected without explicit anchors being added. If the variable is not intented for public use, it should probably not be part of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a reasonable fix to me.
It's a part of the public API, but we don't want the entire regex string to be presented in the documentation: https://packaging.pypa.io/en/stable/version.html#packaging.version.VERSION_PATTERN |
An alternative would be to align the pattern with the ones from specifiers module. packaging/src/packaging/specifiers.py Line 154 in 3030822
|
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [packaging](https://github.com/pypa/packaging) | minor | `==23.1` -> `==23.2` | --- ### Release Notes <details> <summary>pypa/packaging (packaging)</summary> ### [`v23.2`](https://github.com/pypa/packaging/releases/tag/23.2) [Compare Source](https://github.com/pypa/packaging/compare/23.1...23.2) #### What's Changed - parse_marker should consume the entire source string by [@​mwerschy](https://github.com/mwerschy) in [https://github.com/pypa/packaging/pull/687](https://github.com/pypa/packaging/pull/687) - Create a Security Policy file by [@​joycebrum](https://github.com/joycebrum) in [https://github.com/pypa/packaging/pull/695](https://github.com/pypa/packaging/pull/695) - Add python 3.12 to CI by [@​mayeut](https://github.com/mayeut) in [https://github.com/pypa/packaging/pull/689](https://github.com/pypa/packaging/pull/689) - Remove URL validation from requirement parsing by [@​uranusjr](https://github.com/uranusjr) in [https://github.com/pypa/packaging/pull/684](https://github.com/pypa/packaging/pull/684) - Add types for packaging.version.\_Version by [@​hauntsaninja](https://github.com/hauntsaninja) in [https://github.com/pypa/packaging/pull/665](https://github.com/pypa/packaging/pull/665) - Add PyPy 3.10 to CI by [@​mayeut](https://github.com/mayeut) in [https://github.com/pypa/packaging/pull/699](https://github.com/pypa/packaging/pull/699) - Remove unused argument in `_manylinux._is_compatible` by [@​mayeut](https://github.com/mayeut) in [https://github.com/pypa/packaging/pull/700](https://github.com/pypa/packaging/pull/700) - Canonicalize names for requirements comparison by [@​astrojuanlu](https://github.com/astrojuanlu) in [https://github.com/pypa/packaging/pull/696](https://github.com/pypa/packaging/pull/696) - Add platform tag support for LoongArch by [@​loongson-zn](https://github.com/loongson-zn) in [https://github.com/pypa/packaging/pull/693](https://github.com/pypa/packaging/pull/693) - Ability to install `armv7l manylinux/musllinux` wheels on `armv8l` by [@​mayeut](https://github.com/mayeut) in [https://github.com/pypa/packaging/pull/690](https://github.com/pypa/packaging/pull/690) - Include CHANGELOG.rst in sdist by [@​astrojuanlu](https://github.com/astrojuanlu) in [https://github.com/pypa/packaging/pull/704](https://github.com/pypa/packaging/pull/704) - Update pyupgrade to Python 3.7+ by [@​fangchenli](https://github.com/fangchenli) in [https://github.com/pypa/packaging/pull/580](https://github.com/pypa/packaging/pull/580) - Fix version pattern pre-releases by [@​deathaxe](https://github.com/deathaxe) in [https://github.com/pypa/packaging/pull/705](https://github.com/pypa/packaging/pull/705) - Fix typos found by codespell by [@​DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) in [https://github.com/pypa/packaging/pull/706](https://github.com/pypa/packaging/pull/706) - Support enriched metadata by [@​brettcannon](https://github.com/brettcannon) in [https://github.com/pypa/packaging/pull/686](https://github.com/pypa/packaging/pull/686) - Correct rST syntax in CHANGELOG.rst by [@​atugushev](https://github.com/atugushev) in [https://github.com/pypa/packaging/pull/709](https://github.com/pypa/packaging/pull/709) - fix: platform tag for GraalPy by [@​mayeut](https://github.com/mayeut) in [https://github.com/pypa/packaging/pull/711](https://github.com/pypa/packaging/pull/711) - Document that this library uses a calendar-based versioning scheme by [@​faph](https://github.com/faph) in [https://github.com/pypa/packaging/pull/717](https://github.com/pypa/packaging/pull/717) - fix: Update copyright date for docs by [@​garrypolley](https://github.com/garrypolley) in [https://github.com/pypa/packaging/pull/713](https://github.com/pypa/packaging/pull/713) - Bump pip version to avoid known vulnerabilities by [@​joycebrum](https://github.com/joycebrum) in [https://github.com/pypa/packaging/pull/720](https://github.com/pypa/packaging/pull/720) - Typing annotations fixed in version.py by [@​jolaf](https://github.com/jolaf) in [https://github.com/pypa/packaging/pull/723](https://github.com/pypa/packaging/pull/723) - parse\_{sdist,wheel}\_filename: don't raise InvalidVersion by [@​SpecLad](https://github.com/SpecLad) in [https://github.com/pypa/packaging/pull/721](https://github.com/pypa/packaging/pull/721) - Fix code blocks in CHANGELOG.md by [@​edmorley](https://github.com/edmorley) in [https://github.com/pypa/packaging/pull/724](https://github.com/pypa/packaging/pull/724) #### New Contributors - [@​mwerschy](https://github.com/mwerschy) made their first contribution in [https://github.com/pypa/packaging/pull/687](https://github.com/pypa/packaging/pull/687) - [@​joycebrum](https://github.com/joycebrum) made their first contribution in [https://github.com/pypa/packaging/pull/695](https://github.com/pypa/packaging/pull/695) - [@​astrojuanlu](https://github.com/astrojuanlu) made their first contribution in [https://github.com/pypa/packaging/pull/696](https://github.com/pypa/packaging/pull/696) - [@​loongson-zn](https://github.com/loongson-zn) made their first contribution in [https://github.com/pypa/packaging/pull/693](https://github.com/pypa/packaging/pull/693) - [@​fangchenli](https://github.com/fangchenli) made their first contribution in [https://github.com/pypa/packaging/pull/580](https://github.com/pypa/packaging/pull/580) - [@​deathaxe](https://github.com/deathaxe) made their first contribution in [https://github.com/pypa/packaging/pull/705](https://github.com/pypa/packaging/pull/705) - [@​DimitriPapadopoulos](https://github.com/DimitriPapadopoulos) made their first contribution in [https://github.com/pypa/packaging/pull/706](https://github.com/pypa/packaging/pull/706) - [@​atugushev](https://github.com/atugushev) made their first contribution in [https://github.com/pypa/packaging/pull/709](https://github.com/pypa/packaging/pull/709) - [@​faph](https://github.com/faph) made their first contribution in [https://github.com/pypa/packaging/pull/717](https://github.com/pypa/packaging/pull/717) - [@​garrypolley](https://github.com/garrypolley) made their first contribution in [https://github.com/pypa/packaging/pull/713](https://github.com/pypa/packaging/pull/713) - [@​jolaf](https://github.com/jolaf) made their first contribution in [https://github.com/pypa/packaging/pull/723](https://github.com/pypa/packaging/pull/723) - [@​SpecLad](https://github.com/SpecLad) made their first contribution in [https://github.com/pypa/packaging/pull/721](https://github.com/pypa/packaging/pull/721) - [@​edmorley](https://github.com/edmorley) made their first contribution in [https://github.com/pypa/packaging/pull/724](https://github.com/pypa/packaging/pull/724) **Full Changelog**: pypa/packaging@23.1...23.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on the first day of the month" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDkuNCIsInVwZGF0ZWRJblZlciI6IjM2LjEwOS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
This commit fixes a precedence issue with version pre-release tags.
Relational
The
version
module exportsVERSION_PATTERN
.Directly using it, might not produce expected results for pre-releases.
Trailing
1
from-alpha1
is not matched, because previous pattern preferred consuming onlya
instead ofalpha
due to missing word boundary checks.Simplest solution is to re-order tokens, so regexp prefers longer tokens over their abbreviation.
Note: This commit also removes an unnecessary capture group.