You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for Hatch! I'd like to ask about a small user experience issue with the hatch version command.
When incrementing the version of a project with hatch version <version>, Hatch changes the version syntax to the PEP 440 default, even if the version is a valid PEP 440 string.
This behavior of hatch version <version> particularly affects pre-releases. It can be an issue for users or teams who need to comply with other version syntaxes such as SemVer.
For a minimal reproduction, generate a project with hatch new, and bump the version with a valid PEP 440 string different from the default syntax, such as 0.0.2-alpha.0. Hatch converts 0.0.2-alpha.0 (compliant with both SemVer and PEP 440) to the PEP 440 default syntax 0.0.2a0 (not compliant with SemVer).
The relevant code appears to be using a private method from packaging, packaging.version._parse_letter_version, along with some custom conditions. I know Hatch and packaging are both part of PyPA, but it might be prudent to avoid using private methods in other packages.
Thanks for pointing out hatch-semver, looks helpful!
I think the comments in the original post would still apply directly to Hatch and Hatchling, though. I'm suggesting that, as long as the version is a valid PEP 440 string (whether the version scheme is SemVer or something else), Hatch should keep it as-is and not change it to the PEP 440 default.
I could also understand if Hatch decided to only supported PEP 440 default syntax in the hatch version command and related commands. If that is the decision, I think the behavior should at least be documented so that users know what to expect when they run hatch version. I'm happy to contribute some documentation for that, if that's the way you want to go.
Description
Thanks for Hatch! I'd like to ask about a small user experience issue with the
hatch version
command.When incrementing the version of a project with
hatch version <version>
, Hatch changes the version syntax to the PEP 440 default, even if the version is a valid PEP 440 string.This behavior of
hatch version <version>
particularly affects pre-releases. It can be an issue for users or teams who need to comply with other version syntaxes such as SemVer.For a minimal reproduction, generate a project with
hatch new
, and bump the version with a valid PEP 440 string different from the default syntax, such as0.0.2-alpha.0
. Hatch converts0.0.2-alpha.0
(compliant with both SemVer and PEP 440) to the PEP 440 default syntax0.0.2a0
(not compliant with SemVer).By comparing the version set by Hatch with the desired version, we can see that they are both valid and considered equivalent:
Suggestions
I would be happy to provide a PR for this.
I'd like to suggest that, rather than converting the version string to the PEP 440 default, Hatch should instead:
packaging.version.parse()
or similar logicTo take it further, Hatch could offer a configuration setting to control the behavior of the
hatch version
command.Related
External links
Project source code
The relevant code appears to be using a private method from packaging,
packaging.version._parse_letter_version
, along with some custom conditions. I know Hatch and packaging are both part of PyPA, but it might be prudent to avoid using private methods in other packages.hatch/src/hatch/cli/version/__init__.py
Lines 31 to 34 in bad4fb5
hatch/src/hatch/cli/application.py
Line 30 in bad4fb5
hatch/src/hatch/project/core.py
Lines 100 to 107 in bad4fb5
hatch/backend/src/hatchling/metadata/core.py
Lines 1389 to 1404 in bad4fb5
hatch/backend/src/hatchling/version/scheme/standard.py
Lines 11 to 19 in bad4fb5
hatch/backend/src/hatchling/version/scheme/standard.py
Lines 35 to 38 in bad4fb5
The text was updated successfully, but these errors were encountered: