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
For Debian >= 10 distro can't get the minor version.
This worked for Debian <= 9 at least when you have the lsb-release Debian package installed with distro.version(best=True) because lsb_release -a returned the major and minor version in the Release key:
For Debian >= 10 the only source for the minor version is file /etc/debian_version.
The /etc/debian_version file exists for years, even on older Debian versions, with a stable format (major.minor, with the exception that Debian <= 6 has major.minor.patch).
So maybe you can consider to parse /etc/debian_version to get the minor version.
Whereas a small patch (see below) could bring this support to distro, one could argue that this will breakversion output on Debian platforms.
From this response, "Debian version" actually corresponds to what you currently get from /etc/os-release or lsb_release.
For "normalization" and consistency purposes, distro honors OS-RELEASE VERSION_ID attribute (if available), as it [identifies] the operating system version.
Thanks, bye 👋
diff --git a/src/distro/distro.py b/src/distro/distro.py
index c731e8c..1635737 100755
--- a/src/distro/distro.py+++ b/src/distro/distro.py@@ -895,7 +895,16 @@ class LinuxDistribution:
).get("version_id", ""),
self.uname_attr("release"),
]
- if self.uname_attr("id").startswith("aix"):+ if self.id() == "debian":+ # On Debian, prefer debian_version file content.+ try:+ with open(+ os.path.join(self.etc_dir, "debian_version"), encoding="ascii"+ ) as fp:+ versions.insert(0, fp.readline().rstrip())+ except FileNotFoundError:+ pass+ elif self.uname_attr("id").startswith("aix"):
# On AIX platforms, prefer oslevel command output.
versions.insert(0, self.oslevel_info())
version = ""
I also think the changes in your PR are a better solution because this only changes the output for version(best=True) but not for version().
Also applying this to Debian-like systems makes also sense.
On Raspbian we would also get the minor version, because Raspbian behaves exactly like Debian (/etc/os-release only contains the major version and /etc/debian_version contains the minor version).
On Devuan and Ubuntu /etc/debian_version contains bullseye/sid or bookworm/sid, but this is not a problem because versions are only considered for version(best=True) if they contain a . (dot).
Activity
HorlogeSkynet commentedon Jun 3, 2022
Hey @netsandbox,
Whereas a small patch (see below) could bring this support to distro, one could argue that this will break
versionoutput on Debian platforms.From this response, "Debian version" actually corresponds to what you currently get from
/etc/os-releaseorlsb_release.For "normalization" and consistency purposes, distro honors OS-RELEASE
VERSION_IDattribute (if available), as it[identifies] the operating system version.Thanks, bye 👋
Supports `debian_version` file content for `version(best=True)` calls
HorlogeSkynet commentedon Jun 5, 2022
I've (maybe) came across a better patch, please see #333 🙇
netsandbox commentedon Jun 5, 2022
I also think the changes in your PR are a better solution because this only changes the output for
version(best=True)but not forversion().Also applying this to Debian-like systems makes also sense.
On Raspbian we would also get the minor version, because Raspbian behaves exactly like Debian (/etc/os-release only contains the major version and /etc/debian_version contains the minor version).
On Devuan and Ubuntu
/etc/debian_versioncontainsbullseye/sidorbookworm/sid, but this is not a problem because versions are only considered forversion(best=True)if they contain a.(dot).netsandbox commentedon Jun 7, 2022
@HorlogeSkynet thanks for your quick fix.
Can this fix also be included in the
python2.7-supportbranch?Because Ansible (and maybe other tools) still supports Python 2.7.
HorlogeSkynet commentedon Jun 7, 2022
@netsandbox please see #339
HorlogeSkynet commentedon Jun 21, 2022
@netsandbox #339 has been merged, you will be able to fetch latest
python2.7-supportbranch. Cheers 👋netsandbox commentedon Jun 21, 2022
@HorlogeSkynet Thank for your help and great support.