History

scripts: sphinx-pre-install: move get_system_release()

The code at get_system_release() is actually a helper function, independent from the actual Sphinx verification checker. Move it to MissingCheckers class, where other checkers are present. With that, the entire distro-specific handler logic, with all its complexity is confined at SphinxDependencyChecker class.

Mauro Carvalho Chehab committed 1 year ago

Commit fb22e431 parent 9bb5f0d1 file · +59 −56Browse files

Unified · Split

scripts/sphinx-pre-install.py+59−56
@@ -456,6 +456,64 @@ class MissingCheckers(AncillaryMethods): · 455 unmodified lines
456456
457457 return True
458458
459+ def get_system_release(self):
460+ """
461+ Determine the system type. There's no unique way that would work
462+ with all distros with a minimal package install. So, several
463+ methods are used here.
464+
465+ By default, it will use lsb_release function. If not available, it will
466+ fail back to reading the known different places where the distro name
467+ is stored.
468+
469+ Several modern distros now have /etc/os-release, which usually have
470+ a decent coverage.
471+ """
472+
473+ system_release = ""
474+
475+ if self.which("lsb_release"):
476+ result = self.run(["lsb_release", "-d"], capture_output=True, text=True)
477+ system_release = result.stdout.replace("Description:", "").strip()
478+
479+ release_files = [
480+ "/etc/system-release",
481+ "/etc/redhat-release",
482+ "/etc/lsb-release",
483+ "/etc/gentoo-release",
484+ ]
485+
486+ if not system_release:
487+ for f in release_files:
488+ system_release = self.catcheck(f)
489+ if system_release:
490+ break
491+
492+ # This seems more common than LSB these days
493+ if not system_release:
494+ os_var = {}
495+ try:
496+ with open("/etc/os-release", "r", encoding="utf-8") as f:
497+ for line in f:
498+ match = re.match(r"^([\w\d\_]+)=\"?([^\"]*)\"?\n", line)
499+ if match:
500+ os_var[match.group(1)] = match.group(2)
501+
502+ system_release = os_var.get("NAME", "")
503+ if "VERSION_ID" in os_var:
504+ system_release += " " + os_var["VERSION_ID"]
505+ elif "VERSION" in os_var:
506+ system_release += " " + os_var["VERSION"]
507+ except IOError:
508+ pass
509+
510+ if not system_release:
511+ system_release = self.catcheck("/etc/issue")
512+
513+ system_release = system_release.strip()
514+
515+ return system_release
516+
459517 class SphinxDependencyChecker(MissingCheckers):
460518
461519 def __init__(self, args):
@@ -499,7 +557,7 @@ class SphinxDependencyChecker(MissingCheckers): · 37 unmodified lines
499557 self.need_pip = 0
500558 self.rec_sphinx_upgrade = 0
501559
502− self.system_release = ""
560+ self.system_release = self.get_system_release()
503561 self.python_cmd = ""
504562 self.activate_cmd = ""
505563
@@ -1193,7 +1251,6 @@ class SphinxDependencyChecker(MissingCheckers): · 687 unmodified lines
11931251 "\thttps://github.com/sphinx-doc/sphinx/pull/8313")
11941252
11951253 def check_needs(self):
1196− self.get_system_release()
11971254 self.python_cmd = sys.executable
11981255
11991256 # Check if Sphinx is already accessible from current environment
@@ -1270,60 +1327,6 @@ class SphinxDependencyChecker(MissingCheckers): · 70 unmodified lines
12701327
12711328 print("Needed package dependencies are met.")
12721329
1273− def get_system_release(self):
1274− """
1275− Determine the system type. There's no unique way that would work
1276− with all distros with a minimal package install. So, several
1277− methods are used here.
1278−
1279− By default, it will use lsb_release function. If not available, it will
1280− fail back to reading the known different places where the distro name
1281− is stored.
1282−
1283− Several modern distros now have /etc/os-release, which usually have
1284− a decent coverage.
1285− """
1286−
1287− if self.which("lsb_release"):
1288− result = self.run(["lsb_release", "-d"], capture_output=True, text=True)
1289− self.system_release = result.stdout.replace("Description:", "").strip()
1290−
1291− release_files = [
1292− "/etc/system-release",
1293− "/etc/redhat-release",
1294− "/etc/lsb-release",
1295− "/etc/gentoo-release",
1296− ]
1297−
1298− if not self.system_release:
1299− for f in release_files:
1300− self.system_release = self.catcheck(f)
1301− if self.system_release:
1302− break
1303−
1304− # This seems more common than LSB these days
1305− if not self.system_release:
1306− os_var = {}
1307− try:
1308− with open("/etc/os-release", "r", encoding="utf-8") as f:
1309− for line in f:
1310− match = re.match(r"^([\w\d\_]+)=\"?([^\"]*)\"?\n", line)
1311− if match:
1312− os_var[match.group(1)] = match.group(2)
1313−
1314− self.system_release = os_var.get("NAME", "")
1315− if "VERSION_ID" in os_var:
1316− self.system_release += " " + os_var["VERSION_ID"]
1317− elif "VERSION" in os_var:
1318− self.system_release += " " + os_var["VERSION"]
1319− except IOError:
1320− pass
1321−
1322− if not self.system_release:
1323− self.system_release = self.catcheck("/etc/issue")
1324−
1325− self.system_release = self.system_release.strip()
1326−
13271330 DESCRIPTION = """
13281331 Process some flags related to Sphinx installation and documentation build.
13291332 """

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t