Skip to content

Commit

Permalink
[scripts] Blacken scripts en enforce it
Browse files Browse the repository at this point in the history
Add a step to run black on our python scripts.

Signed-off-by: Manu Bretelle <chantr4@gmail.com>
  • Loading branch information
chantra committed Oct 26, 2023
1 parent 28c764c commit 1eed97e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
8 changes: 3 additions & 5 deletions .github/scripts/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ def get_tests(config):
# Set run_veristat to false by default.
matrix[idx]["run_veristat"] = matrix[idx].get("run_veristat", False)
# Feel in the tests
matrix[idx]["tests"] = {"include": [
generate_test_config(test)
for test in get_tests(matrix[idx])
]
matrix[idx]["tests"] = {
"include": [generate_test_config(test) for test in get_tests(matrix[idx])]
}

# Only a few repository within "kernel-patches" use self-hosted runners.
Expand All @@ -136,4 +134,4 @@ def get_tests(config):

build_matrix = {"include": matrix}

set_output("build_matrix", dumps(build_matrix))
set_output("build_matrix", dumps(build_matrix))
51 changes: 23 additions & 28 deletions .github/scripts/veristat-compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,22 @@
SUMMARY_HEADERS = ["File", "Program", "Verdict", "States Diff (%)"]

# expected format: +0 (+0.00%) / -0 (-0.00%)
TOTAL_STATES_DIFF_REGEX = \
TOTAL_STATES_DIFF_REGEX = (
r"(?P<absolute_diff>[+-]\d+) \((?P<percentage_diff>[+-]\d+\.\d+)\%\)"
)


TEXT_SUMMARY_TEMPLATE: Final[str] = """
TEXT_SUMMARY_TEMPLATE: Final[
str
] = """
# {title}
{table}
""".strip()

HTML_SUMMARY_TEMPLATE: Final[str] = """
HTML_SUMMARY_TEMPLATE: Final[
str
] = """
# {title}
<details>
Expand Down Expand Up @@ -135,21 +140,17 @@ def get_results_summary(self, markup: bool = False) -> str:


def get_state_diff(value: str) -> float:
if value == 'N/A':
if value == "N/A":
return 0.0

matches = re.match(TOTAL_STATES_DIFF_REGEX, value)
if not matches:
raise ValueError(
f"Failed to parse total states diff field value '{value}'"
)
raise ValueError(f"Failed to parse total states diff field value '{value}'")

if percentage_diff := matches.group("percentage_diff"):
return float(percentage_diff)

raise ValueError(
f"Invalid {VeristatFields.TOTAL_STATES_DIFF} field value: {value}"
)
raise ValueError(f"Invalid {VeristatFields.TOTAL_STATES_DIFF} field value: {value}")


def parse_table(csv_file):
Expand Down Expand Up @@ -190,18 +191,16 @@ def parse_table(csv_file):
if not add:
continue

table.append([
record[VeristatFields.FILE_NAME],
record[VeristatFields.PROG_NAME],
verdict,
f"{diff:+.2f} %"
])

return VeristatInfo(
table=table,
changes=changes,
new_failures=new_failures
)
table.append(
[
record[VeristatFields.FILE_NAME],
record[VeristatFields.PROG_NAME],
verdict,
f"{diff:+.2f} %",
]
)

return VeristatInfo(table=table, changes=changes, new_failures=new_failures)


def github_markup_decorate(input_str: str) -> str:
Expand All @@ -219,8 +218,7 @@ def format_table(headers: List[str], rows: List[List[str]]) -> str:
# Row template string in the following format:
# "{0:8}|{1:10}|{2:15}|{3:7}|{4:10}"
row_template = "|".join(
f"{{{idx}:{width}}}"
for idx, width in enumerate(column_width)
f"{{{idx}:{width}}}" for idx, width in enumerate(column_width)
)
row_template_nl = f"|{row_template}|\n"

Expand All @@ -237,10 +235,7 @@ def format_table(headers: List[str], rows: List[List[str]]) -> str:
return out.getvalue()


def main(
compare_csv_filename: os.PathLike,
output_filename: os.PathLike
) -> None:
def main(compare_csv_filename: os.PathLike, output_filename: os.PathLike) -> None:
with open(compare_csv_filename, newline="", encoding="utf-8") as csv_file:
veristat_results = parse_table(csv_file)

Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ jobs:
env:
SHELLCHECK_OPTS: --severity=warning --exclude=SC1091

# Ensure some consistency in the formatting.
lint:
if: ${{ github.repository == 'kernel-patches/vmtest' }}
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Run black
uses: psf/black@stable
with:
src: ./.github/scripts

validate_matrix:
if: ${{ github.repository == 'kernel-patches/vmtest' }}
name: Validate matrix.py
Expand Down

0 comments on commit 1eed97e

Please sign in to comment.