fix linter issues

This commit is contained in:
InsanePrawn 2025-03-29 20:25:03 +01:00
parent 35ef46332b
commit b8c072e5ee
10 changed files with 33 additions and 30 deletions

View file

@ -254,10 +254,10 @@ class Chroot(AbstractChroot):
# make sure paths start with '/'. Important: also copies the collection and casts to list, which will be sorted!
mounts = [make_abs_path(path) for path in relative_paths]
mounts.sort(reverse=True)
for mount in mounts:
if mount == "/proc":
for _mount in mounts:
if _mount == "/proc":
continue
self.umount(mount)
self.umount(_mount)
if "/proc" in mounts:
self.umount("/proc")

View file

@ -84,7 +84,7 @@ def get_device_chroot(
**kwargs,
) -> DeviceChroot:
name = f"rootfs_{device}-{flavour}"
repos: dict[str, RepoInfo] = (
repos: dict[str, RepoInfo] = dict(
get_kupfer_local(arch).repos
if use_local_repos
else get_kupfer_https(arch).repos

View file

@ -57,14 +57,14 @@ def prompt_config(
to_check or to_check is zero
) # can't do == due to boolean<->int casting
if type(None) == field_type:
if type(None) is field_type:
field_type = str
if field_type == dict:
if field_type is dict:
raise Exception(
"Dictionaries not supported by config_prompt, this is likely a bug in kupferbootstrap"
)
elif field_type == list:
elif field_type is list:
default = list_to_comma_str(default)
value_conv = comma_str_to_list
else:
@ -83,7 +83,7 @@ def prompt_config(
show_choices=show_choices,
) # type: ignore
changed = result != (
original_default if field_type == list else default
original_default if field_type is list else default
) and (true_or_zero(default) or true_or_zero(result))
if changed and echo_changes:
print(f'value changed: "{text}" = "{result}"')
@ -411,7 +411,7 @@ def cmd_config_set(
key: str = split_pair[0]
value: Any = split_pair[1]
value_type = type(config_dot_name_get(key, CONFIG_DEFAULTS))
if value_type != list:
if value_type is not list:
value = click.types.convert_type(value_type)(value)
else:
value = comma_str_to_list(value, default=[])

View file

@ -95,7 +95,7 @@ def resolve_profile(
for key, value in PROFILE_DEFAULTS_DICT.items():
if key not in full.keys():
full[key] = value # type: ignore[literal-required]
if type(value) == list:
if type(value) is list:
full[key] = [] # type: ignore[literal-required]
full["size_extra_mb"] = int(full["size_extra_mb"] or 0)

View file

@ -274,7 +274,7 @@ class ConfigStateHolder:
raise ConfigLoadException(Exception(m))
ex = self.file_state.exception
if ex:
if type(ex) == FileNotFoundError:
if isinstance(ex, FileNotFoundError):
ex = Exception(
"Config file doesn't exist. Try running `kupferbootstrap config init` first?"
)

View file

@ -50,7 +50,7 @@ def resolve_dict_hints(hints: Any) -> Generator[tuple[Any, ...], None, None]:
for hint in flatten_hints(hints):
t_origin = get_origin(hint)
t_args = get_args(hint)
if t_origin == dict:
if t_origin is dict:
yield t_args
continue
if t_origin in [NoneType, Optional, Union, UnionType] and t_args:
@ -294,7 +294,7 @@ class DictScheme(Munch):
hints_flat = list(flatten_hints(_hints))
subclass = DictScheme
for hint in hints_flat:
if get_origin(hint) == dict:
if get_origin(hint) is dict:
_valtype = get_args(hint)[1]
_subhints = {n: _valtype for n in v.keys()}
break

View file

@ -71,7 +71,7 @@ def chmod(
octal = octal.rjust(4, "0")
try:
os.chmod(path, mode=octal) # type: ignore
except:
except Exception:
cmd = ["chmod", octal, path]
result = run_cmd(cmd, switch_user="root" if privileged else None)
assert isinstance(result, subprocess.CompletedProcess)
@ -177,7 +177,7 @@ def remove_file(path: str, recursive=False):
try:
rm = rmtree if recursive else os.unlink
rm(path) # type: ignore
except:
except Exception:
cmd = ["rm"] + (["-r"] if recursive else []) + [path]
rc = run_root_cmd(cmd).returncode
if rc:
@ -197,7 +197,7 @@ def makedir(
os.makedirs(path, exist_ok=True)
else:
os.mkdir(path)
except:
except Exception:
run_root_cmd(["mkdir"] + (["-p"] if parents else []) + [path])
if mode is not None:
chmod(path, mode=mode)
@ -212,7 +212,7 @@ def symlink(source, target):
"Create a symlink at `target`, pointing at `source`"
try:
os.symlink(source, target)
except:
except Exception:
result = run_root_cmd(["ln", "-s", source, target])
assert isinstance(result, subprocess.CompletedProcess)
if result.returncode:

View file

@ -78,16 +78,17 @@ def get_fs_size(partition: str) -> tuple[int, int]:
blocks_cmd.stdout.decode("utf-8") if blocks_cmd.stdout else ""
)
try:
fs_blocks = int(
re.search(
"\\nBlock count:[ ]+([0-9]+)\\n",
blocks_text,
flags=re.MULTILINE,
).group(1)
) # type: ignore[union-attr]
fs_block_size = int(
re.search("\\nBlock size:[ ]+([0-9]+)\\n", blocks_text).group(1)
) # type: ignore[union-attr]
re_blocks = re.search(
"\\nBlock count:[ ]+([0-9]+)\\n",
blocks_text,
flags=re.MULTILINE,
)
assert re_blocks, "Block output should contain block count"
fs_blocks = int(re_blocks.group(1))
re_blocksize = re.search("\\nBlock size:[ ]+([0-9]+)\\n", blocks_text)
assert re_blocksize, "Block output should contain block size"
fs_block_size = int(re_blocksize.group(1))
except Exception as ex:
logging.debug(f"dumpe2fs stdout:\n {blocks_text}")
logging.debug(f"dumpe2fs stderr:\n: {blocks_cmd.stderr}")
@ -133,6 +134,7 @@ def shrink_fs(loop_device: str, file: str, sector_size: int):
), # type: ignore
stdin=subprocess.PIPE,
)
assert child_proccess.stdin is not None
child_proccess.stdin.write(
"\n".join(
[ # type: ignore

View file

@ -747,7 +747,7 @@ def build_package(
failed_deps = [
name
for name, res in dep_install.items()
if res.returncode != 0
if (res.returncode if not isinstance(res, int) else res) != 0
] # type: ignore[union-attr]
if failed_deps:
raise Exception(
@ -1092,7 +1092,8 @@ def build_enable_qemu_binfmt(
.packages
)
pkgfiles = [
os.path.join(crossrepo[pkg].resolved_url.split("file://")[1])
# we want this to crash on unresolved URL
os.path.join((crossrepo[pkg].resolved_url or "").split("file://")[1])
for pkg in QEMU_BINFMT_PKGS
] # type: ignore
runcmd = run_root_cmd

View file

@ -34,7 +34,7 @@ try:
integration_enabled = bool(
int(os.environ.get(INTEGRATION_TESTS_ENABLE_ENV_VAR, 0)) > 0
)
except:
except Exception:
pass