Skip to content

Commit 208f703

Browse files
authored
Merge pull request #132 from nathanchance/update-ruff-toml
2 parents df4e2fe + 3744a88 commit 208f703

File tree

5 files changed

+39
-61
lines changed

5 files changed

+39
-61
lines changed

boot-qemu.py

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
#!/usr/bin/env python3
22
# pylint: disable=invalid-name
33

4-
from argparse import ArgumentParser
5-
from collections.abc import Sequence
64
import contextlib
75
import os
8-
from pathlib import Path
96
import platform
107
import re
118
import shlex
129
import shutil
1310
import subprocess
1411
import sys
12+
from argparse import ArgumentParser
13+
from collections.abc import Sequence
14+
from pathlib import Path
1515
from typing import Any, Union
1616

1717
import utils
1818

19-
2019
SUPPORTED_ARCHES = [
2120
'arm',
2221
'arm32_v5',
@@ -108,9 +107,7 @@ def _get_default_smp_value(self) -> int:
108107
# * <kernel_dir>/../../../.config (if the image is in arch/*/boot/)
109108
# * <kernel_dir>/config (if the image is in a TuxMake folder)
110109
possible_locations = ['.config', '../../../.config', 'config']
111-
configuration = utils.find_first_file(
112-
self.kernel_dir, possible_locations, required=False
113-
)
110+
configuration = utils.find_first_file(self.kernel_dir, possible_locations, required=False)
114111

115112
config_nr_cpus = 8 # sensible default based on treewide defaults,
116113
if configuration != utils.UNINIT_PATH:
@@ -129,21 +126,19 @@ def _get_kernel_ver_tuple(self, decomp_prog: str) -> tuple[int, ...]:
129126
raise RuntimeError('No kernel set?')
130127

131128
utils.check_cmd(decomp_prog)
132-
if decomp_prog in ('gzip',):
129+
if decomp_prog == 'gzip':
133130
decomp_cmd = [decomp_prog, '-c', '-d', self.kernel]
134131
else:
135132
raise RuntimeError(f"Unsupported decompression program ('{decomp_prog}')?")
136133
decomp = subprocess.run(decomp_cmd, capture_output=True, check=True)
137134

138135
utils.check_cmd('strings')
139-
strings = subprocess.run(
140-
'strings', capture_output=True, check=True, input=decomp.stdout
141-
)
136+
strings = subprocess.run('strings', capture_output=True, check=True, input=decomp.stdout)
142137
strings_stdout = strings.stdout.decode(encoding='utf-8', errors='ignore')
143138

144139
if not (
145140
match := re.search(
146-
r'^Linux version (\d+\.\d+\.\d+)', strings_stdout, flags=re.M
141+
r'^Linux version (\d+\.\d+\.\d+)', strings_stdout, flags=re.MULTILINE
147142
)
148143
):
149144
raise RuntimeError(f"Could not find Linux version in {self.kernel}?")
@@ -505,7 +500,9 @@ def __init__(self) -> None:
505500
bios = Path(utils.BOOT_UTILS, 'images', self._initrd_arch, 'QEMU_EFI.fd')
506501
if not bios.exists():
507502
bios.parent.mkdir(exist_ok=True, parents=True)
508-
firmware_url = f"https://github.com/loongson/Firmware/raw/main/LoongArchVirtMachine/{bios.name}"
503+
firmware_url = (
504+
f"https://github.com/loongson/Firmware/raw/main/LoongArchVirtMachine/{bios.name}"
505+
)
509506
utils.green(f"Downloading LoongArch firmware from {firmware_url}...")
510507
curl_cmd = ['curl', '-LSs', '-o', bios, firmware_url]
511508
subprocess.run(curl_cmd, check=True)
@@ -694,9 +691,7 @@ def run(self) -> None:
694691
Path('OVMF/OVMF_VARS.fd'), # Debian and Ubuntu
695692
]
696693
ovmf_vars = utils.find_first_file(usr_share, ovmf_vars_locations)
697-
self._efi_vars = Path(
698-
utils.BOOT_UTILS, 'images', self._initrd_arch, ovmf_vars.name
699-
)
694+
self._efi_vars = Path(utils.BOOT_UTILS, 'images', self._initrd_arch, ovmf_vars.name)
700695
# This file is in /usr/share, so it must be copied in order to be
701696
# modified.
702697
shutil.copyfile(ovmf_vars, self._efi_vars)
@@ -720,12 +715,8 @@ def guess_arch(kernel_arg: Path) -> str:
720715
#
721716
# Note: 'required=False' just to provide our own exception.
722717
vmlinux_locations = ['vmlinux', '../../../vmlinux']
723-
if not (
724-
vmlinux := utils.find_first_file(kernel_dir, vmlinux_locations, required=False)
725-
):
726-
raise RuntimeError(
727-
'Architecture was not provided and vmlinux could not be found!'
728-
)
718+
if not (vmlinux := utils.find_first_file(kernel_dir, vmlinux_locations, required=False)):
719+
raise RuntimeError('Architecture was not provided and vmlinux could not be found!')
729720

730721
if not (file := shutil.which('file')):
731722
raise RuntimeError("Architecture was not provided and 'file' is not installed!")
@@ -783,9 +774,7 @@ def parse_arguments():
783774
help="The architecture to boot. If omitted, value will be guessed based on 'vmlinux' if available. Possible values are: %(choices)s",
784775
metavar='ARCH',
785776
)
786-
parser.add_argument(
787-
'--efi', action='store_true', help='Boot kernel via UEFI (x86_64 only)'
788-
)
777+
parser.add_argument('--efi', action='store_true', help='Boot kernel via UEFI (x86_64 only)')
789778
parser.add_argument(
790779
'-g',
791780
'--gdb',
@@ -855,9 +844,7 @@ def parse_arguments():
855844
args = parse_arguments()
856845

857846
if not (kernel_location := Path(args.kernel_location).resolve()).exists():
858-
raise FileNotFoundError(
859-
f"Supplied kernel location ('{kernel_location}') does not exist!"
860-
)
847+
raise FileNotFoundError(f"Supplied kernel location ('{kernel_location}') does not exist!")
861848

862849
if not (arch := args.architecture):
863850
arch = guess_arch(kernel_location)
@@ -900,9 +887,7 @@ def parse_arguments():
900887
if args.efi:
901888
runner.efi = runner.supports_efi
902889
if not runner.efi:
903-
utils.yellow(
904-
f"EFI boot requested on unsupported architecture ('{arch}'), ignoring..."
905-
)
890+
utils.yellow(f"EFI boot requested on unsupported architecture ('{arch}'), ignoring...")
906891

907892
if args.gdb:
908893
runner.gdb = True
@@ -921,13 +906,9 @@ def parse_arguments():
921906

922907
if args.modules:
923908
if not (modules := Path(args.modules).resolve()).exists():
924-
raise FileNotFoundError(
925-
f"Supplied modules .cpio ('{modules}') does not exist?"
926-
)
909+
raise FileNotFoundError(f"Supplied modules .cpio ('{modules}') does not exist?")
927910
if not args.memory:
928-
utils.yellow(
929-
'Memory not specified, the default may be too small for modules...'
930-
)
911+
utils.yellow('Memory not specified, the default may be too small for modules...')
931912
runner.modules = modules
932913

933914
if args.no_kvm:

boot-uml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# pylint: disable=invalid-name
33

44
import argparse
5-
from pathlib import Path
65
import subprocess
6+
from pathlib import Path
77

88
import utils
99

buildroot/rebuild.py

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

3-
from argparse import ArgumentParser
43
import datetime
54
import os
6-
from pathlib import Path
75
import shutil
86
import subprocess
7+
from argparse import ArgumentParser
8+
from pathlib import Path
99

1010
BUILDROOT_VERSION = '2024.02.8'
1111
SUPPORTED_ARCHES = [
@@ -175,9 +175,7 @@ def parse_arguments():
175175
if not shutil.which('zstd'):
176176
raise RuntimeError('zstd could not be found on your system, please install it!')
177177

178-
architectures = (
179-
SUPPORTED_ARCHES if 'all' in args.architectures else args.architectures
180-
)
178+
architectures = SUPPORTED_ARCHES if 'all' in args.architectures else args.architectures
181179

182180
download_and_extract_buildroot()
183181
for arch in architectures:

ruff.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
target-version = 'py39'
2+
line-length = 100
23

34
[format]
45
quote-style = 'preserve'
@@ -10,8 +11,13 @@ select = [
1011
'ARG', # flake8-unused-arguments
1112
'B', # flake8-bugbear
1213
'C4', # flake8-comprehensions
14+
'DTZ', # flake8-datetimes
1315
'E', # pycodestyle
1416
'F', # pyflakes
17+
'FURB', # refurb
18+
'I', # isort
19+
'N', # pep8-naming
20+
'PERF', # perflint
1521
'PIE', # flake8-pie
1622
'PL', # pylint
1723
'PTH', # flake8-use-pathlib
@@ -20,6 +26,8 @@ select = [
2026
'S', # flake8-bandit
2127
'SIM', # flake8-simplify
2228
'SLF', # flake8-self
29+
'TC', # flake8-type-checking
30+
'TRY', # tryceratops
2331
'UP', # pyupgrade
2432
'W', # pycodestyle
2533
]
@@ -32,4 +40,5 @@ ignore = [
3240
'PLR2004', # magic-value-comparison
3341
'S603', # subprocess-without-shell-equals-true
3442
'S607', # start-process-with-partial-path
43+
'TRY003', # raise-vanilla-args
3544
]

utils.py

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

3-
from collections.abc import Iterable
43
import json
54
import os
6-
from pathlib import Path
7-
import subprocess
85
import shutil
6+
import subprocess
97
import sys
8+
from collections.abc import Iterable
9+
from pathlib import Path
1010
from typing import Any, NoReturn, Optional, Union
1111

1212
BOOT_UTILS = Path(__file__).resolve().parent
@@ -128,9 +128,7 @@ def get_full_kernel_path(
128128
elif arch:
129129
kernel = kernel_location.joinpath("arch", arch, "boot", image)
130130
else:
131-
die(
132-
f"Kernel image ('{image}') is in the arch/ directory but 'arch' was not provided!"
133-
)
131+
die(f"Kernel image ('{image}') is in the arch/ directory but 'arch' was not provided!")
134132

135133
if not kernel.exists():
136134
die(f"Kernel ('{kernel}') does not exist!")
@@ -160,13 +158,9 @@ def get_gh_json(endpoint: str) -> dict[str, Any]:
160158
curl_cmd.append(endpoint)
161159

162160
try:
163-
curl_out = subprocess.run(
164-
curl_cmd, capture_output=True, check=True, text=True
165-
).stdout
161+
curl_out = subprocess.run(curl_cmd, capture_output=True, check=True, text=True).stdout
166162
except subprocess.CalledProcessError as err:
167-
raise RuntimeError(
168-
f"Failed to query GitHub API at {endpoint}: {err.stderr}"
169-
) from err
163+
raise RuntimeError(f"Failed to query GitHub API at {endpoint}: {err.stderr}") from err
170164

171165
return json.loads(curl_out)
172166

@@ -201,9 +195,7 @@ def prepare_initrd(
201195
# querying the GitHub API at all.
202196
if gh_json_file and gh_json_file != UNINIT_PATH:
203197
if not gh_json_file.exists():
204-
raise FileNotFoundError(
205-
f"Provided GitHub JSON file ('{gh_json_file}') does not exist!"
206-
)
198+
raise FileNotFoundError(f"Provided GitHub JSON file ('{gh_json_file}') does not exist!")
207199
gh_json_rel = json.loads(gh_json_file.read_text(encoding='utf-8'))
208200
else:
209201
# Make sure that the current user is not rate limited by GitHub,
@@ -214,9 +206,7 @@ def prepare_initrd(
214206
# and cached the result, we can query for the latest release to make sure
215207
# that we are up to date.
216208
if (remaining := gh_json_rl['resources']['core']['remaining']) > 0:
217-
gh_json_rel = get_gh_json(
218-
f"https://api.github.com/repos/{REPO}/releases/latest"
219-
)
209+
gh_json_rel = get_gh_json(f"https://api.github.com/repos/{REPO}/releases/latest")
220210
elif not src.exists():
221211
limit = gh_json_rl['resources']['core']['limit']
222212
raise RuntimeError(

0 commit comments

Comments
 (0)