Drastically lowers LinuxDistribution._distro_release_info complexity#327
Merged
HorlogeSkynet merged 1 commit intomasterfrom Feb 18, 2022
Merged
Drastically lowers LinuxDistribution._distro_release_info complexity#327HorlogeSkynet merged 1 commit intomasterfrom
LinuxDistribution._distro_release_info complexity#327HorlogeSkynet merged 1 commit intomasterfrom
Conversation
hartwork
reviewed
Feb 15, 2022
dbb9964 to
9e50a5d
Compare
Member
Author
|
@hartwork This is the diff I've just amended, to simplify your review 😇 More simplifications, and your documentation-related ideas. diff --git a/src/distro/distro.py b/src/distro/distro.py
index 8209256..4d08067 100755
--- a/src/distro/distro.py
+++ b/src/distro/distro.py
@@ -1250,7 +1250,12 @@ class LinuxDistribution:
match = _DISTRO_RELEASE_BASENAME_PATTERN.match(basename)
else:
try:
- basenames = os.listdir(self.etc_dir)
+ basenames = [
+ basename
+ for basename in os.listdir(self.etc_dir)
+ if basename not in _DISTRO_RELEASE_IGNORE_BASENAMES
+ and os.path.isfile(os.path.join(self.etc_dir, basename))
+ ]
# We sort for repeatability in cases where there are multiple
# distro specific files; e.g. CentOS, Oracle, Enterprise all
# containing `redhat-release` on top of their own.
@@ -1262,10 +1267,8 @@ class LinuxDistribution:
# error is handled in `_parse_distro_release_file()`.
basenames = _DISTRO_RELEASE_BASENAMES
for basename in basenames:
- if basename in _DISTRO_RELEASE_IGNORE_BASENAMES:
- continue
match = _DISTRO_RELEASE_BASENAME_PATTERN.match(basename)
- if not match:
+ if match is None:
continue
filepath = os.path.join(self.etc_dir, basename)
distro_info = self._parse_distro_release_file(filepath)
@@ -1274,13 +1277,13 @@ class LinuxDistribution:
continue
self.distro_release_file = filepath
break
- else:
+ else: # the loop didn't "break": no candidate.
return {}
if match is not None:
distro_info["id"] = match.group(1)
- # manually set id for CloudLinux
+ # CloudLinux < 7: manually enrich info with proper id.
if "cloudlinux" in distro_info.get("name", "").lower():
distro_info["id"] = "cloudlinux"
|
hartwork
approved these changes
Feb 17, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.