Skip to content

Commit fc46a04

Browse files
authored
Merge pull request #7486 from sylvestre/python
Python: add ruff check and fix the code
2 parents 4df6423 + b1c3175 commit fc46a04

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

.github/workflows/code-quality.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,23 @@ jobs:
167167

168168
- name: Check
169169
run: npx --yes @taplo/cli fmt --check
170+
171+
python:
172+
name: Style/Python
173+
runs-on: ubuntu-latest
174+
steps:
175+
- name: Clone repository
176+
uses: actions/checkout@v4
177+
with:
178+
persist-credentials: false
179+
180+
- name: ruff
181+
uses: astral-sh/ruff-action@v3
182+
with:
183+
src: "./util"
184+
185+
- name: ruff - format
186+
uses: astral-sh/ruff-action@v3
187+
with:
188+
src: "./util"
189+
args: format --check

util/analyze-gnu-results.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
Prints shell export statements for TOTAL, PASS, FAIL, SKIP, XPASS, and ERROR
3030
that can be evaluated in a shell environment.
3131
"""
32+
3233
import json
3334
import sys
3435
from collections import defaultdict

util/compare_gnu_result.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python3
22

33
"""
4-
Compare the current results to the last results gathered from the main branch to highlight
5-
if a PR is making the results better/worse.
4+
Compare the current results to the last results gathered from the main branch to
5+
highlight if a PR is making the results better/worse.
66
Don't exit with error code if all failing tests are in the ignore-intermittent.txt list.
77
"""
88

@@ -28,17 +28,19 @@
2828

2929
# Get an annotation to highlight changes
3030
print(
31-
f"::warning ::Changes from '{REPO_DEFAULT_BRANCH}': PASS {pass_d:+d} / FAIL {fail_d:+d} / ERROR {error_d:+d} / SKIP {skip_d:+d} "
31+
f"""::warning ::Changes from '{REPO_DEFAULT_BRANCH}': PASS {pass_d:+d} /
32+
FAIL {fail_d:+d} / ERROR {error_d:+d} / SKIP {skip_d:+d}"""
3233
)
3334

3435
# If results are worse, check if we should fail the job
3536
if pass_d < 0:
3637
print(
37-
f"::error ::PASS count is reduced from '{REPO_DEFAULT_BRANCH}': PASS {pass_d:+d} "
38+
f"""::error ::PASS count is reduced from
39+
'{REPO_DEFAULT_BRANCH}': PASS {pass_d:+d}"""
3840
)
3941

4042
# Check if all failing tests are intermittent based on the environment variable
41-
only_intermittent = ONLY_INTERMITTENT.lower() == 'true'
43+
only_intermittent = ONLY_INTERMITTENT.lower() == "true"
4244

4345
if only_intermittent:
4446
print("::notice ::All failing tests are in the ignored intermittent list")

util/gnu-json-result.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@
3737
except Exception as e:
3838
print(f"Error processing file {path}: {e}", file=sys.stderr)
3939

40-
4140
print(json.dumps(out, indent=2, sort_keys=True))

util/remaining-gnu-error.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
try:
1818
urllib.request.urlretrieve(
1919
"https://raw.githubusercontent.com/uutils/coreutils-tracking/main/gnu-full-result.json",
20-
result_json
20+
result_json,
2121
)
2222
except Exception as e:
2323
print(f"Failed to download the file: {e}")
@@ -39,9 +39,9 @@
3939
list_of_files = sorted(tests, key=lambda x: os.stat(x).st_size)
4040

4141

42-
def show_list(l):
42+
def show_list(list_test):
4343
# Remove the factor tests and reverse the list (bigger first)
44-
tests = list(filter(lambda k: "factor" not in k, l))
44+
tests = list(filter(lambda k: "factor" not in k, list_test))
4545

4646
for f in reversed(tests):
4747
if contains_require_root(f):

util/size-experiment.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def config(name, val):
2323

2424
sizes = {}
2525

26-
for (strip, panic, opt, lto) in product(
27-
STRIP_VALS, PANIC_VALS, OPT_LEVEL_VALS, LTO_VALS
28-
):
26+
for strip, panic, opt, lto in product(STRIP_VALS, PANIC_VALS, OPT_LEVEL_VALS, LTO_VALS):
2927
if RECOMPILE:
3028
cmd = [
3129
"cargo",
@@ -77,8 +75,9 @@ def collect_diff(idx, name):
7775
collect_diff(3, "lto")
7876

7977

80-
def analyze(l):
81-
return f"MIN: {float(min(l)):.3}, AVG: {float(sum(l)/len(l)):.3}, MAX: {float(max(l)):.3}"
78+
def analyze(change):
79+
return f"""MIN: {float(min(change)):.3},
80+
AVG: {float(sum(change) / len(change)):.3}, MAX: {float(max(change)):.3}"""
8281

8382

8483
print("Absolute changes")

0 commit comments

Comments
 (0)