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.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -456,6 +456,64 @@ class MissingCheckers(AncillaryMethods): · 455 unmodified lines | |||
| 456 | 456 | ||
| 457 | return True | 457 | return True |
| 458 | 458 | ||
| 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 | |||
| 459 | class SphinxDependencyChecker(MissingCheckers): | 517 | class SphinxDependencyChecker(MissingCheckers): |
| 460 | 518 | ||
| 461 | def __init__(self, args): | 519 | def __init__(self, args): |
| @@ -499,7 +557,7 @@ class SphinxDependencyChecker(MissingCheckers): · 37 unmodified lines | |||
| 499 | self.need_pip = 0 | 557 | self.need_pip = 0 |
| 500 | self.rec_sphinx_upgrade = 0 | 558 | self.rec_sphinx_upgrade = 0 |
| 501 | 559 | ||
| 502 | self.system_release = "" | 560 | self.system_release = self.get_system_release() |
| 503 | self.python_cmd = "" | 561 | self.python_cmd = "" |
| 504 | self.activate_cmd = "" | 562 | self.activate_cmd = "" |
| 505 | 563 | ||
| @@ -1193,7 +1251,6 @@ class SphinxDependencyChecker(MissingCheckers): · 687 unmodified lines | |||
| 1193 | "\thttps://github.com/sphinx-doc/sphinx/pull/8313") | 1251 | "\thttps://github.com/sphinx-doc/sphinx/pull/8313") |
| 1194 | 1252 | ||
| 1195 | def check_needs(self): | 1253 | def check_needs(self): |
| 1196 | self.get_system_release() | ||
| 1197 | self.python_cmd = sys.executable | 1254 | self.python_cmd = sys.executable |
| 1198 | 1255 | ||
| 1199 | # Check if Sphinx is already accessible from current environment | 1256 | # Check if Sphinx is already accessible from current environment |
| @@ -1270,60 +1327,6 @@ class SphinxDependencyChecker(MissingCheckers): · 70 unmodified lines | |||
| 1270 | 1327 | ||
| 1271 | print("Needed package dependencies are met.") | 1328 | print("Needed package dependencies are met.") |
| 1272 | 1329 | ||
| 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 | |||
| 1327 | DESCRIPTION = """ | 1330 | DESCRIPTION = """ |
| 1328 | Process some flags related to Sphinx installation and documentation build. | 1331 | Process some flags related to Sphinx installation and documentation build. |
| 1329 | """ | 1332 | """ |