Skip to content

Add lexicographic versioning scheme - #160

Merged
pombredanne merged 3 commits into
aboutcode-org:mainfrom
immqu:lexicographic-versioning-scheme
Nov 12, 2025
Merged

Add lexicographic versioning scheme#160
pombredanne merged 3 commits into
aboutcode-org:mainfrom
immqu:lexicographic-versioning-scheme

Conversation

@immqu

@immqu immqu commented Jul 16, 2025

Copy link
Copy Markdown
Collaborator

This PR introduces a simple string versioning scheme that compares strings based on lexicographical order (UTF-8 encoded).

Addresses package-url/vers-spec#24

immqu added 3 commits August 21, 2025 10:10
Signed-off-by: Kunz, Immanuel <immanuel.kunz@aisec.fraunhofer.de>
Signed-off-by: Kunz, Immanuel <immanuel.kunz@aisec.fraunhofer.de>
Signed-off-by: Kunz, Immanuel <immanuel.kunz@aisec.fraunhofer.de>
@immqu
immqu force-pushed the lexicographic-versioning-scheme branch from 13e36ad to 9064438 Compare August 21, 2025 08:14
Comment thread src/univers/versions.py
return remove_spaces(str(string))

def __lt__(self, other):
return self.value.encode("utf-8") < other.value.encode("utf-8")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reference docs that explain how two UTF-8 byte strings are compared, so we can get that working beyond Python?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this conforms with rfc 3629 which states

UTF-8 encodes UCS characters as a varying number of octets, where the number of octets, and the value of each, depend on the integer value assigned to the character in ISO/IEC 10646 (the character number, a.k.a. code position, code point or Unicode scalar value). This encoding form has the following characteristics (all values are in hexadecimal):
...

  • The byte-value lexicographic sorting order of UTF-8 strings is the same as if ordered by character numbers. Of course this is of limited interest since a sort order based on character numbers is almost never culturally valid.

https://www.rfc-editor.org/rfc/rfc3629.txt

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for checking!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np. Thank you for making the PR and following this through, it seems like a good general purpose version scheme to have available. 👍

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also consider using JSON tests in the same style as https://github.com/package-url/vers-spec/blob/main/tests/conan_version_cmp_test.json

@immqu

immqu commented Sep 11, 2025

Copy link
Copy Markdown
Collaborator Author

It is now further specified here: package-url/vers-spec#37

@immqu

immqu commented Oct 13, 2025

Copy link
Copy Markdown
Collaborator Author

Since package-url/vers-spec#37 is now merged, is this PR also good to merge @pombredanne ?

@immqu
immqu requested a review from pombredanne October 16, 2025 14:29

@darakian darakian left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for clarity I approve of adding this to the spec

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge!

@pombredanne
pombredanne merged commit 6955566 into aboutcode-org:main Nov 12, 2025
10 checks passed
@pombredanne

Copy link
Copy Markdown
Member

@immqu Thank you ++ for carrying this through!

@immqu
immqu deleted the lexicographic-versioning-scheme branch November 21, 2025 10:11
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.

3 participants