Merge pull request #7486 from sylvestre/python

Python: add ruff check and fix the code
This commit is contained in:
Daniel Hofstetter 2025-03-19 08:07:43 +01:00 committed by GitHub
commit fc46a041f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 35 additions and 14 deletions

View file

@ -167,3 +167,23 @@ jobs:
- name: Check
run: npx --yes @taplo/cli fmt --check
python:
name: Style/Python
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: ruff
uses: astral-sh/ruff-action@v3
with:
src: "./util"
- name: ruff - format
uses: astral-sh/ruff-action@v3
with:
src: "./util"
args: format --check

View file

@ -29,6 +29,7 @@ Output:
Prints shell export statements for TOTAL, PASS, FAIL, SKIP, XPASS, and ERROR
that can be evaluated in a shell environment.
"""
import json
import sys
from collections import defaultdict

View file

@ -1,8 +1,8 @@
#!/usr/bin/env python3
"""
Compare the current results to the last results gathered from the main branch to highlight
if a PR is making the results better/worse.
Compare the current results to the last results gathered from the main branch to
highlight if a PR is making the results better/worse.
Don't exit with error code if all failing tests are in the ignore-intermittent.txt list.
"""
@ -28,17 +28,19 @@ skip_d = int(current["skip"]) - int(last["skip"])
# Get an annotation to highlight changes
print(
f"::warning ::Changes from '{REPO_DEFAULT_BRANCH}': PASS {pass_d:+d} / FAIL {fail_d:+d} / ERROR {error_d:+d} / SKIP {skip_d:+d} "
f"""::warning ::Changes from '{REPO_DEFAULT_BRANCH}': PASS {pass_d:+d} /
FAIL {fail_d:+d} / ERROR {error_d:+d} / SKIP {skip_d:+d}"""
)
# If results are worse, check if we should fail the job
if pass_d < 0:
print(
f"::error ::PASS count is reduced from '{REPO_DEFAULT_BRANCH}': PASS {pass_d:+d} "
f"""::error ::PASS count is reduced from
'{REPO_DEFAULT_BRANCH}': PASS {pass_d:+d}"""
)
# Check if all failing tests are intermittent based on the environment variable
only_intermittent = ONLY_INTERMITTENT.lower() == 'true'
only_intermittent = ONLY_INTERMITTENT.lower() == "true"
if only_intermittent:
print("::notice ::All failing tests are in the ignored intermittent list")

View file

@ -37,5 +37,4 @@ for filepath in test_dir.glob("**/*.log"):
except Exception as e:
print(f"Error processing file {path}: {e}", file=sys.stderr)
print(json.dumps(out, indent=2, sort_keys=True))

View file

@ -17,7 +17,7 @@ result_json = "result.json"
try:
urllib.request.urlretrieve(
"https://raw.githubusercontent.com/uutils/coreutils-tracking/main/gnu-full-result.json",
result_json
result_json,
)
except Exception as e:
print(f"Failed to download the file: {e}")
@ -39,9 +39,9 @@ for files in types:
list_of_files = sorted(tests, key=lambda x: os.stat(x).st_size)
def show_list(l):
def show_list(list_test):
# Remove the factor tests and reverse the list (bigger first)
tests = list(filter(lambda k: "factor" not in k, l))
tests = list(filter(lambda k: "factor" not in k, list_test))
for f in reversed(tests):
if contains_require_root(f):

View file

@ -23,9 +23,7 @@ def config(name, val):
sizes = {}
for (strip, panic, opt, lto) in product(
STRIP_VALS, PANIC_VALS, OPT_LEVEL_VALS, LTO_VALS
):
for strip, panic, opt, lto in product(STRIP_VALS, PANIC_VALS, OPT_LEVEL_VALS, LTO_VALS):
if RECOMPILE:
cmd = [
"cargo",
@ -77,8 +75,9 @@ collect_diff(2, "opt-level")
collect_diff(3, "lto")
def analyze(l):
return f"MIN: {float(min(l)):.3}, AVG: {float(sum(l)/len(l)):.3}, MAX: {float(max(l)):.3}"
def analyze(change):
return f"""MIN: {float(min(change)):.3},
AVG: {float(sum(change) / len(change)):.3}, MAX: {float(max(change)):.3}"""
print("Absolute changes")