-
Notifications
You must be signed in to change notification settings - Fork 66
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
Fix Armbian release info #366
Fix Armbian release info #366
Conversation
Hi @pedrolamas and thanks for your PR. Moreover, if this distro is firstly detected as Debian thanks to Bye 👋 |
Granted, that probably would also work, but there is currently nothing parsing I opted for a similar approach to the "cloudlinux" case just below it, where it is checking the "name" - in this case, I am checking the "id" (the extra check for "#" is just to narrow the case further down, the reality is that it is probably not even needed for "armbian" as they always have that comment on the top).
That would be the case if the files weren't ordered alphabetically, and so "armbian-release" will be found before "os-release" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @pedrolamas 👋
I took the liberty of pushing some changes to your branch; Please tell me whether you're okay with them 🙏
Hi @HorlogeSkynet, I just checked and it looks perfectly fine! Thank you! 🙂 |
Hello @pedrolamas, dear @python-distro/maintainers, Before merging this, what do you think about adding Armbian version to distro release info ? diff --git a/src/distro/distro.py b/src/distro/distro.py
index 1e01a68..0db2736 100755
--- a/src/distro/distro.py
+++ b/src/distro/distro.py
@@ -906,6 +906,9 @@ class LinuxDistribution:
elif self.id() == "debian" or "debian" in self.like().split():
# On Debian-like, add debian_version file content to candidates list.
versions.append(self._debian_version)
+ if self._distro_release_info.get("id") == "armbian":
+ # On Armbian, add version from armbian-release file to candidates list.
+ versions.append(self._armbian_version)
version = ""
if best:
# This algorithm uses the last version in priority order that has
@@ -1226,6 +1229,16 @@ class LinuxDistribution:
except FileNotFoundError:
return ""
+ @cached_property
+ def _armbian_version(self) -> str:
+ try:
+ with open(
+ os.path.join(self.etc_dir, "armbian-release"), encoding="ascii"
+ ) as fp:
+ return self._parse_os_release_content(fp).get("version", "")
+ except FileNotFoundError:
+ return ""
+
@staticmethod
def _parse_uname_content(lines: Sequence[str]) -> Dict[str, str]:
if not lines:
@@ -1309,6 +1322,7 @@ class LinuxDistribution:
"name", ""
).startswith("#"):
distro_info["name"] = "Armbian"
+ distro_info["version"] = self._armbian_version
# CloudLinux < 7: manually enrich info with proper id.
if "cloudlinux" in distro_info.get("name", "").lower():
diff --git a/tests/test_distro.py b/tests/test_distro.py
index d362d59..4b492f7 100644
--- a/tests/test_distro.py
+++ b/tests/test_distro.py
@@ -1928,7 +1928,7 @@ class TestOverall(DistroTestCase):
"like": "",
"version": "10",
"pretty_version": "10 (buster)",
- "best_version": "10",
+ "best_version": "23.02.2",
"major_version": "10",
"minor_version": "",
}
@@ -1937,6 +1937,7 @@ class TestOverall(DistroTestCase):
desired_info = {
"id": "armbian",
"name": "Armbian",
+ "version": "23.02.2",
}
self._test_release_file_info("armbian-release", desired_info)
@@ -2383,6 +2384,12 @@ class TestRepr:
repr_str = repr(distro._distro)
assert "LinuxDistribution" in repr_str
for attr in MODULE_DISTRO.__dict__.keys():
- if attr in ("root_dir", "etc_dir", "usr_lib_dir", "_debian_version"):
+ if attr in (
+ "root_dir",
+ "etc_dir",
+ "usr_lib_dir",
+ "_debian_version",
+ "_armbian_version",
+ ):
continue
assert f"{attr}=" in repr_str Calling Thanks. bye 👋 |
Thanks @HorlogeSkynet, I've taken a look and looks great, but should that be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @HorlogeSkynet, I've taken a look and looks great, but should that be version_id instead of version?
You're perfectly right ! Updated and pushed. I'd like to see a review from another @python-distro/maintainers before merging this 🙂
Thanks, bye 👋
Dear @python-distro/maintainers, up please 🙏 |
Up @python-distro/maintainers please 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, assuming that we go with this very armbian-specific implementation, I think that it's fine.
My problem with such a distro-specific implementation is really a conceptual one.
When I started writing distro
I wanted to find the most common patterns the different distributions used, which kept the implementation extremely clean. Everything revolved around generic files used by different distributions, so that if we found such type of file, we could parse it generically, and then any distribution that used the same pattern would receive the same treatment.
So, on one hand, I'd love it if we didn't specifically address "armbian" in the code, but rather address the TYPE of pattern they use, and then it would automatically understand that it's "armbian" that we're talking about, just like it does when we use os-release
.
However (!), nothing in software is pure (it's incredible that the world works at all), so I'm also willing to accept the fact that we need a specific implementation for a specific use case, and if we identify a generic case, we can always change.
Adds small fix for Armbian releases, as
armbian_release
files are not standard format and normally start with a comment.(related to fluidd-core/fluidd#1385)