From 8345e9e30144487222e35c7df119f42e541c1d92 Mon Sep 17 00:00:00 2001 From: YuriiPerets <163062897+YuriiPerets@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:41:44 +0300 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Simeon Ehrig --- src/bashi/filter_software_dependency.py | 58 ++++++++++++++++++------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/src/bashi/filter_software_dependency.py b/src/bashi/filter_software_dependency.py index 05b5069..6a8494d 100644 --- a/src/bashi/filter_software_dependency.py +++ b/src/bashi/filter_software_dependency.py @@ -14,6 +14,37 @@ from bashi.globals import DEVICE_COMPILER, HOST_COMPILER, GCC, UBUNTU from bashi.utils import reason +def __ubuntu_version_to_string(version: pkv.Version) -> str: + """Returns the Ubuntu version representation correctly. Ubuntu versions + use a leading 0 in their version scheme for months before October. pkv.parse()` + parses e.g. the 04 from 20.04 to 4. Therefore the string representation of + str(pkv.parse(“20.04”)) is `20.4`. This function returns the correct version scheme. + For Ubuntu `20.04` it is `20.04`. + + Args: + version (pkv.Version): Ubuntu version + + Returns: + str: string representation of the Ubuntu version + """ + return f"{version.major}.{version.minor:02}" + + +def __pretty_name_compiler(constant: str) -> str: + """Returns the string representation of the constants HOST_COMPILER and DEVICE_COMPILER in a + human-readable version. + + Args: + constant (str): Ether HOST_COMPILER or DEVICE_COMPILER + + Returns: + str: human-readable string representation of HOST_COMPILER or DEVICE_COMPILER + """ + if constant == HOST_COMPILER: + return "host compiler" + if constant == DEVICE_COMPILER: + return "device compiler" + return "unknown compiler type" @typechecked def software_dependency_filter_typechecked( @@ -44,22 +75,17 @@ def software_dependency_filter( bool: True, if parameter-value-tuple is valid. """ + # Rule: d1 + # GCC 6 and older is not available in Ubuntu 20.04 and newer if UBUNTU in row and row[UBUNTU].version >= pkv.parse("20.04"): - if DEVICE_COMPILER in row and row[DEVICE_COMPILER].name == GCC: - if row[DEVICE_COMPILER].version <= pkv.parse("6"): - reason( - output, - f"Device compiler GCC {row[DEVICE_COMPILER].version}" - f" is not available in Ubuntu {row[UBUNTU].version}", - ) - return False - if HOST_COMPILER in row and row[HOST_COMPILER].name == GCC: - if row[HOST_COMPILER].version <= pkv.parse("6"): - reason( - output, - f"Host compiler GCC {row[HOST_COMPILER].version}" - f" is not available in Ubuntu {row[UBUNTU].version}", - ) - return False + for compiler_type in (HOST_COMPILER, DEVICE_COMPILER): + if compiler_type in row and row[compiler_type].name == GCC: + if row[compiler_type].version <= pkv.parse("6"): + reason( + output, + f"{__pretty_name_compiler(compiler_type)} GCC {row[compiler_type].version} " + f"is not available in Ubuntu {__ubuntu_version_to_string(row[UBUNTU].version)}", + ) + return False return True