Skip to content

Prefer better version matches#2008

Merged
gtristan merged 6 commits intomasterfrom
tristan/prefer-better-version-matches
May 13, 2025
Merged

Prefer better version matches#2008
gtristan merged 6 commits intomasterfrom
tristan/prefer-better-version-matches

Conversation

@gtristan
Copy link
Contributor

@gtristan gtristan commented May 7, 2025

This fixes the issue of parsing typically formulated release tarball URLs.

Consider the URL https://flying-ponies.com/releases/1.2/pony-flight-1.2.3.tgz.

Without this change, we only get the version 1.2 (the directory where we put all of the 1.2 releases).

After this change, we get 1.2.3.

This is achieved by explicitly supporting optional groups in the regex (which we already did, but in an not very specified way), and preferring more qualified matches by preferring matches which had more groups present in the match while iterating over all non-overlapping matches.

By causing the user to explicitly specify groups in the regex, we avoid the pitfall of relying on silly things like string length (where both strings "1.200" and "1.2.3" would be considered equally qualified).

@gtristan gtristan force-pushed the tristan/prefer-better-version-matches branch 2 times, most recently from 12e0b36 to 136f95d Compare May 7, 2025 09:47
@gtristan
Copy link
Contributor Author

gtristan commented May 7, 2025

FWIW with the increased complexity, and increased clarity on how the regex string works - I would be more happy now to make a well defined utils function to do the guess work and share that code with the plugin repos.

@gtristan gtristan force-pushed the tristan/prefer-better-version-matches branch from 136f95d to 39ef733 Compare May 7, 2025 09:53
Copy link
Contributor

@abderrahim abderrahim left a comment

Choose a reason for hiding this comment

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

This works fine, but I still think it's a bit too complicated.

I feel that extracting the basename from the URL and using just that for guessing the version is good enough. I went through all the buildstream projects I work on and couldn't find any instance where the version isn't in the basename.

That said, I won't block this.

gtristan added 6 commits May 12, 2025 16:25
This is implicitly required by adding the 2.5.0.dev0 tag.
This is public, and is used in buildstream-plugins-community, but this
was documented as an internal buildstream function.
This defines the API contract which a plugin has with the user who
provides a regular expression for version guessing.

This is a superior implementation to what we initially landed in
the downloadable file source, and addresses cases where a match
could be found multiple times, such as: https://example.com/releases/1.2/release-1.2.3.tgz
@gtristan gtristan force-pushed the tristan/prefer-better-version-matches branch from 39ef733 to 15e9f77 Compare May 12, 2025 08:45
@gtristan
Copy link
Contributor Author

FWIW with the increased complexity, and increased clarity on how the regex string works - I would be more happy now to make a well defined utils function to do the guess work and share that code with the plugin repos.

I have now:

  • Understood the regular expression nature a bit better
    • While it is possible to match repeating groups with a '*' wildcard, it is impossible to capture an arbitrary number of groups
  • I have now created utils.guess_version() which reduces the implementer load by:
    • Doing the match iteration and preferring the match with the greatest amount of captured groups
    • Providing a central location to define the API contract for specifying version-guess-pattern

@gtristan gtristan merged commit ad25c4b into master May 13, 2025
17 checks passed
@gtristan gtristan deleted the tristan/prefer-better-version-matches branch May 13, 2025 08:12
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.

2 participants