Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Simeon Ehrig <[email protected]>
  • Loading branch information
YuriiPerets and SimeonEhrig authored Sep 5, 2024
1 parent 858eb8c commit 8345e9e
Showing 1 changed file with 42 additions and 16 deletions.
58 changes: 42 additions & 16 deletions src/bashi/filter_software_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

0 comments on commit 8345e9e

Please sign in to comment.