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

Posix.get_package_information fails to parse package version if it does not follow semver #3625

Open
trungams opened this issue Feb 3, 2025 · 1 comment

Comments

@trungams
Copy link
Member

trungams commented Feb 3, 2025

The current implementation of Posix.get_package_information uses the package manager for a distro to query for a package information, then uses some regexes to force parse the package version into semver. This logic fails if a package does not follow semantic versioning for their versioning scheme. Example for Azure Linux (which uses rpm):

>>> import re
>>> r = re.compile(
           r"(?P<package_name>[a-zA-Z0-9\-_]+)-"
           r"(?P<major>[0-9]+)\."
           r"(?P<minor>[0-9]+)\.?"
           r"(?P<patch>[0-9]+)?"
           r"(?P<build>-[a-zA-Z0-9-_\.]+)?"
       )
>>> print(r.search("systemd-255-20.azl3.x86_64"))
None

Suggestion: query the version directly using a distro's package tool/manager (dpkg/apt, rpm, etc), then return the raw version string as part of the result. If there is any logic to check versioning of a package, that logic can be implemented for each distro. Here is an example of how one can query a package version for debian and rpm based systems:

  • Debian: dpkg-query -f '${Version}' -W <pkg>
  • RPM: rpm --queryformat '%{VERSION}-%{RELEASE}' -q

I demoed this change in commit 365ce35, adding a new function _query_package since I don't want to change existing code yet. Please let me know your thoughts.

@squirrelsc
Copy link
Member

Thank you, @trungams . Replied in the PR.

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

No branches or pull requests

2 participants