Skip to content

Commit

Permalink
Debug parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
druzsan committed Feb 7, 2024
1 parent eca286e commit 17edfe9
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,32 @@ def parse_base_matrix(input_matrix: str) -> dict:
return matrix


def parse_include_exclude(input_include_exclude: str) -> list:
include_exclude = yaml.load(input_include_exclude, Loader=yaml.loader.BaseLoader)
if include_exclude is None:
return []
if not isinstance(include_exclude, list):
def assert_valid_extra(extra: Any) -> None:
"""
Validate strategy include/exclude.
"""
if not isinstance(extra, list):
raise TypeError(
f"Include/exclude must be a list, but {type(include_exclude)} received."
f"Include/exclude must be a sequence (Python list), but Python "
f"{type(extra)} received."
)
for combination in include_exclude:
for combination in extra:
if not isinstance(combination, dict):
raise TypeError(
f"Each include/exclude combination must a dict, but "
f"{type(combination)} received."
f"Each include/exclude combination must a mapping (Python "
f"dict), but Python {type(combination)} received."
)
for variable, value in combination.items():
if not isinstance(variable, str):
raise TypeError(
f"Include/exclude combination variables must be strings, "
f"but variable of type {type(variable)} received."
f"Include/exclude variables must be strings, but "
f"Python {type(variable)} received."
)
if not isinstance(value, str):
raise TypeError(
f"Include/exclude combination values must be strings, but "
f"Each include/exclude value must be a string, but Python "
f"{type(value)} received for variable '{variable}'."
)
return include_exclude


def assert_valid_extra(extra: Any) -> None:
"""
Validate strategy include/exclude.
"""
if not isinstance(extra, list):
raise TypeError(
f"Include/exclude must be an array (Python list), but Python "
f"{type(extra)} received."
)
# for combination in extra:
# if not isinstance(combination, dict):
# raise TypeError(
# f"Each include/exclude combination must a dict, but "
# f"{type(combination)} received."
# )


def assert_valid_matrix(matrix: Any) -> None:
Expand All @@ -103,10 +86,23 @@ def assert_valid_matrix(matrix: Any) -> None:
for variable, values in matrix.items():
if not isinstance(variable, str):
raise TypeError(
f"Matrix variables must be strings, but {type(variable)} received."
f"Matrix variables must be strings, but Python "
f"{type(variable)} received."
)
if variable in ("include", "exclude"):
assert_valid_extra(values)
else:
if not isinstance(values, list):
raise TypeError(
f"Matrix values must be sequences (Python lists), but "
f"Python {type(values)} received for variable '{variable}'."
)
for value in values:
if not isinstance(value, str):
raise TypeError(
f"Each matrix value must be a string, but Python "
f"{type(value)} received for variable '{variable}'."
)


def parse_matrix(input_matrix: str) -> dict:
Expand All @@ -125,7 +121,7 @@ def parse_matrix(input_matrix: str) -> dict:
print(yaml.dump({"matrix": matrix}))

# output_matrix = json.dumps(matrix)
output_matrix = "{'include':[['a','b']]}"
output_matrix = "{'os':[]}"

output("matrix", output_matrix)
setenv("MATRIX", output_matrix)

0 comments on commit 17edfe9

Please sign in to comment.