Skip to content
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

[bug] Pre-release versions are not always considered "later" than a release version (semver issue?) #14557

Closed
antoinebardoz opened this issue Aug 23, 2023 · 4 comments · Fixed by #14561
Assignees
Milestone

Comments

@antoinebardoz
Copy link

Environment details

  • Operating System+version: Ubuntu 22.04
  • Compiler+version: N/A
  • Conan version: 2.0.9
  • Python version: 3.10.8

Steps to reproduce

Use a version which has more than one hyphen:

>>> from conan.tools.scm import Version
>>> Version("0.0.1") > Version("0.0.1-3-1")
False

Quote:
1.1-alpha.1 is older than 1.1, not newer.

From:
https://docs.conan.io/2/tutorial/versioning/version_ranges.html#semantic-versioning

My understanding is that a pre-release should always be lower priority than a release, and the presence of a hyphen makes it a prerelease. According to the semver spec (item 9) a prerelease may itself contain a hyphen, so this should be legal.

(a workaround which works for me, by the way, is to instead use + inside the prerelease string: 0.0.1-3+1)

Logs

No response

@memsharded
Copy link
Member

Thanks for the report @antoinebardoz

I am having a look, and it seems the semver specification allows that. I am wondering why, this reads to me like a self-inflicting unnecessary pain. I would definitely recommend using prereleases in the form X.Y.Z-pre.1.2.3 or something like that, and restrict the hyphen to the definition of the pre-release.

I am checking if this can be changed in Conan, but seems complicated, because the way that versions are parsed, the extra hyphens will produce pre-releases into the pre-releases, not necessarily parsed as identifiers, and changing itseems that would require a big effort, so not sure if it is worth it.

Recall that Conan aims to be close to semver, but due to massive demand, it is not and it will not be fully conforming. For example Conan versions allow:

  • More than 3 numbers as digit versions. X.Y.Z.V.W is allowed and managed correctly, with version-ranges too
  • Less than 3 digits as versions
  • Allow letters too in the main "digit" versions, and mixed digits and letters in the versions, also for versions inside pre-releases and builds.
  • Order versions also according to the +build.X.Y.Z versions

So depending on the efforts, we might not support extra hyphens in the identifiers. I will update with the findings of the effort to try to change this.

@memsharded
Copy link
Member

I am proposing #14561, that will change the parsing to split in the first hyphen from the left, allowing the extra hyphens to be part of the pre-release.

However, inside the pre-release the extra hyphens will have the meaning of extra pre-releases, not a single identifier, and that can affect how the relative order of multiple pre-releases can be evaluated.

The proposal means:

  • It is generally discouraged to use more than 1 hyphen in versions
  • If used, be aware that they are defining extra nested pre-release levels inside the pre-release, and that will affect relative ordering and range resolution

As we don't aim to be fully conformant with semver, if this change creates any issues, problems, it will be reverted.

@antoinebardoz
Copy link
Author

Thanks, sounds like a good proposal to me!

@memsharded
Copy link
Member

We finally made it more compliant, the pre-releases will not have nested pre-releases, and will consider hyphens as pure identifiers. Will be in 2.0.10

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

Successfully merging a pull request may close this issue.

2 participants