Skip to content

Commit ad69b8d

Browse files
committed
misc-scripts: Switch to ruff for Python formatting
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent 1cc6aa8 commit ad69b8d

2 files changed

Lines changed: 33 additions & 32 deletions

File tree

distro-clang/get-distro-clang.py

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,32 @@
2020

2121
def print_cmd(args, command):
2222
if not args.quiet:
23-
print(f"$ {' '.join([shlex.quote(str(elem)) for elem in command])}",
24-
flush=True)
23+
print(f"$ {' '.join([shlex.quote(str(elem)) for elem in command])}", flush=True)
2524

2625

2726
def chronic(*args, **kwargs):
2827
try:
29-
return subprocess.run(*args,
30-
**kwargs,
31-
capture_output=True,
32-
check=True,
33-
text=True)
28+
return subprocess.run(*args, **kwargs, capture_output=True, check=True, text=True)
3429
except subprocess.CalledProcessError as err:
3530
print(err.stdout)
3631
print(err.stderr)
3732
raise err
3833

3934

4035
PARSER = ArgumentParser(
41-
description=
42-
'Get clang version from various Linux distributions through docker/podman)'
36+
description='Get clang version from various Linux distributions through docker/podman)'
4337
)
44-
PARSER.add_argument('-m',
45-
'--markdown',
46-
action='store_true',
47-
help='Output results as a Markdown table')
48-
PARSER.add_argument('-q',
49-
'--quiet',
50-
action='store_true',
51-
help='Do not print commands being run')
38+
PARSER.add_argument(
39+
'-m', '--markdown', action='store_true', help='Output results as a Markdown table'
40+
)
41+
PARSER.add_argument('-q', '--quiet', action='store_true', help='Do not print commands being run')
5242
ARGS = PARSER.parse_args()
5343

5444
for MANAGER in (MANAGERS := ['podman', 'docker']):
5545
if shutil.which(MANAGER):
5646
break
5747
else:
58-
raise RuntimeError(
59-
f"Neither {' nor '.join(MANAGERS)} could be found on your system!")
48+
raise RuntimeError(f"Neither {' nor '.join(MANAGERS)} could be found on your system!")
6049

6150
# This list should only include versions that are actively being supported.
6251
#
@@ -70,8 +59,10 @@ def chronic(*args, **kwargs):
7059
# * https://www.debian.org/releases/
7160
# * https://wiki.debian.org/LTS
7261
# * https://hub.docker.com/_/debian
73-
*[('debian', f"{ver}-slim") for ver in
74-
['oldoldstable', 'oldstable', 'stable', 'testing', 'unstable']],
62+
*[
63+
('debian', f"{ver}-slim")
64+
for ver in ['oldoldstable', 'oldstable', 'stable', 'testing', 'unstable']
65+
],
7566
# Fedora:
7667
# * https://fedoraproject.org/wiki/Releases
7768
# * https://fedoraproject.org/wiki/End_of_life
@@ -86,8 +77,7 @@ def chronic(*args, **kwargs):
8677
# Ubuntu:
8778
# * https://wiki.ubuntu.com/Releases
8879
# * https://hub.docker.com/_/ubuntu
89-
*[('ubuntu', ver)
90-
for ver in ['focal', 'jammy', 'noble', 'latest', 'rolling', 'devel']],
80+
*[('ubuntu', ver) for ver in ['focal', 'jammy', 'noble', 'latest', 'rolling', 'devel']],
9181
]
9282

9383
RESULTS = {}
@@ -139,25 +129,32 @@ def chronic(*args, **kwargs):
139129
RESULT = chronic(RUN_CMD)
140130

141131
# Locate clang version in output and add it to results
142-
if not (match := re.search(
132+
if not (
133+
match := re.search(
143134
r'^[A-Za-z ]*?clang version [0-9]+\.[0-9]+\.[0-9]+.*$',
144135
RESULT.stdout,
145-
flags=re.M)):
136+
flags=re.M,
137+
)
138+
):
146139
raise RuntimeError('Could not find clang version in output?')
147140
RESULTS[IMAGE] = match[0]
148141

149142
print()
150143

151144
# Pretty print results
152145
if ARGS.markdown:
153-
MD_DATA = [{
154-
"Container image": f"`{key}`",
155-
"Compiler version": f"`{value}`",
156-
} for key, value in RESULTS.items()]
146+
MD_DATA = [
147+
{
148+
"Container image": f"`{key}`",
149+
"Compiler version": f"`{value}`",
150+
}
151+
for key, value in RESULTS.items()
152+
]
157153
print(
158-
markdown_table(MD_DATA).set_params(padding_weight='right',
159-
quote=False,
160-
row_sep='markdown').get_markdown())
154+
markdown_table(MD_DATA)
155+
.set_params(padding_weight='right', quote=False, row_sep='markdown')
156+
.get_markdown()
157+
)
161158
else:
162159
WIDTH = len(max(RESULTS.keys(), key=len))
163160
for IMAGE, VERSION in RESULTS.items():

ruff.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
target-version = 'py38'
2+
line-length = 100
3+
4+
[format]
5+
quote-style = 'preserve'
26

37
# https://docs.astral.sh/ruff/rules/
48
[lint]

0 commit comments

Comments
 (0)