mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-13 19:39:51 +03:00
Merge branch 'newbyte/perflint' into 'master'
pmb: Enable Perflint and Refurb checks See merge request postmarketOS/pmbootstrap!2611
This commit is contained in:
commit
5cde983b5b
20 changed files with 40 additions and 57 deletions
|
@ -67,7 +67,6 @@ def generate(pkgname: str) -> None:
|
||||||
rm .PKGINFO .SIGN.*
|
rm .PKGINFO .SIGN.*
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
for line in apkbuild.split("\n"):
|
handle.writelines(line[12:].replace(" " * 4, "\t") + "\n" for line in apkbuild.split("\n"))
|
||||||
handle.write(line[12:].replace(" " * 4, "\t") + "\n")
|
|
||||||
|
|
||||||
pmb.aportgen.core.generate_checksums(tempdir, apkbuild_path)
|
pmb.aportgen.core.generate_checksums(tempdir, apkbuild_path)
|
||||||
|
|
|
@ -106,7 +106,7 @@ def rewrite(
|
||||||
path = get_context().config.work / "aportgen/APKBUILD"
|
path = get_context().config.work / "aportgen/APKBUILD"
|
||||||
with open(path, "r+", encoding="utf-8") as handle:
|
with open(path, "r+", encoding="utf-8") as handle:
|
||||||
skip_in_func = False
|
skip_in_func = False
|
||||||
for line in handle.readlines():
|
for line in handle:
|
||||||
# Skip maintainer/contributor
|
# Skip maintainer/contributor
|
||||||
if line.startswith(("# Maintainer", "# Contributor")):
|
if line.startswith(("# Maintainer", "# Contributor")):
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -252,8 +252,7 @@ def generate_deviceinfo(
|
||||||
pmb.helpers.run.user(["mkdir", "-p", work / "aportgen"])
|
pmb.helpers.run.user(["mkdir", "-p", work / "aportgen"])
|
||||||
path = work / "aportgen/deviceinfo"
|
path = work / "aportgen/deviceinfo"
|
||||||
with open(path, "w", encoding="utf-8") as handle:
|
with open(path, "w", encoding="utf-8") as handle:
|
||||||
for line in content.rstrip().split("\n"):
|
handle.writelines(line.lstrip() + "\n" for line in content.rstrip().split("\n"))
|
||||||
handle.write(line.lstrip() + "\n")
|
|
||||||
|
|
||||||
|
|
||||||
def generate_modules_initfs() -> None:
|
def generate_modules_initfs() -> None:
|
||||||
|
@ -274,8 +273,7 @@ def generate_modules_initfs() -> None:
|
||||||
pmb.helpers.run.user(["mkdir", "-p", work / "aportgen"])
|
pmb.helpers.run.user(["mkdir", "-p", work / "aportgen"])
|
||||||
path = work / "aportgen/modules-initfs"
|
path = work / "aportgen/modules-initfs"
|
||||||
with open(path, "w", encoding="utf-8") as handle:
|
with open(path, "w", encoding="utf-8") as handle:
|
||||||
for line in content.rstrip().split("\n"):
|
handle.writelines(line.lstrip() + "\n" for line in content.rstrip().split("\n"))
|
||||||
handle.write(line.lstrip() + "\n")
|
|
||||||
|
|
||||||
|
|
||||||
def generate_apkbuild(pkgname: str, name: str, arch: Arch, flash_method: str) -> None:
|
def generate_apkbuild(pkgname: str, name: str, arch: Arch, flash_method: str) -> None:
|
||||||
|
@ -324,8 +322,9 @@ def generate_apkbuild(pkgname: str, name: str, arch: Arch, flash_method: str) ->
|
||||||
pmb.helpers.run.user(["mkdir", "-p", work / "aportgen"])
|
pmb.helpers.run.user(["mkdir", "-p", work / "aportgen"])
|
||||||
path = work / "aportgen/APKBUILD"
|
path = work / "aportgen/APKBUILD"
|
||||||
with open(path, "w", encoding="utf-8") as handle:
|
with open(path, "w", encoding="utf-8") as handle:
|
||||||
for line in content.rstrip().split("\n"):
|
handle.writelines(
|
||||||
handle.write(line[8:].replace(" " * 4, "\t") + "\n")
|
line[8:].replace(" " * 4, "\t") + "\n" for line in content.rstrip().split("\n")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def generate(pkgname: str) -> None:
|
def generate(pkgname: str) -> None:
|
||||||
|
|
|
@ -56,7 +56,6 @@ def generate(pkgname: str) -> None:
|
||||||
rm .PKGINFO .SIGN.*
|
rm .PKGINFO .SIGN.*
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
for line in apkbuild.split("\n"):
|
handle.writelines(line[12:].replace(" " * 4, "\t") + "\n" for line in apkbuild.split("\n"))
|
||||||
handle.write(line[12:].replace(" " * 4, "\t") + "\n")
|
|
||||||
|
|
||||||
pmb.aportgen.core.generate_checksums(tempdir, apkbuild_path)
|
pmb.aportgen.core.generate_checksums(tempdir, apkbuild_path)
|
||||||
|
|
|
@ -91,7 +91,6 @@ def generate(pkgname: str) -> None:
|
||||||
done
|
done
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
for line in apkbuild.split("\n"):
|
handle.writelines(line[12:].replace(" " * 4, "\t") + "\n" for line in apkbuild.split("\n"))
|
||||||
handle.write(line[12:].replace(" " * 4, "\t") + "\n")
|
|
||||||
|
|
||||||
pmb.aportgen.core.generate_checksums(tempdir, apkbuild_path)
|
pmb.aportgen.core.generate_checksums(tempdir, apkbuild_path)
|
||||||
|
|
|
@ -109,8 +109,7 @@ def override_source(
|
||||||
|
|
||||||
# Write and log append file
|
# Write and log append file
|
||||||
with open(append_path_outside, "w", encoding="utf-8") as handle:
|
with open(append_path_outside, "w", encoding="utf-8") as handle:
|
||||||
for line in append.split("\n"):
|
handle.writelines(line[13:].replace(" " * 4, "\t") + "\n" for line in append.split("\n"))
|
||||||
handle.write(line[13:].replace(" " * 4, "\t") + "\n")
|
|
||||||
pmb.chroot.user(["cat", append_path], chroot)
|
pmb.chroot.user(["cat", append_path], chroot)
|
||||||
|
|
||||||
# Append it to the APKBUILD
|
# Append it to the APKBUILD
|
||||||
|
|
|
@ -22,11 +22,8 @@ def list_chroot(suffix: Chroot, remove_prefix: bool = True) -> list[str]:
|
||||||
|
|
||||||
|
|
||||||
def list_aports() -> list[str]:
|
def list_aports() -> list[str]:
|
||||||
ret = []
|
|
||||||
prefix = pmb.config.initfs_hook_prefix
|
prefix = pmb.config.initfs_hook_prefix
|
||||||
for path in pkgrepo_iglob(f"*/{prefix}*"):
|
return [os.path.basename(path)[len(prefix) :] for path in pkgrepo_iglob(f"*/{prefix}*")]
|
||||||
ret.append(os.path.basename(path)[len(prefix) :])
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def ls(suffix: Chroot) -> None:
|
def ls(suffix: Chroot) -> None:
|
||||||
|
|
|
@ -13,10 +13,7 @@ class Pull(commands.Command):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
failed = []
|
failed = [repo for repo in pmb.config.git_repos.keys() if pmb.helpers.git.pull(repo) < 0]
|
||||||
for repo in pmb.config.git_repos.keys():
|
|
||||||
if pmb.helpers.git.pull(repo) < 0:
|
|
||||||
failed.append(repo)
|
|
||||||
|
|
||||||
if not failed:
|
if not failed:
|
||||||
return
|
return
|
||||||
|
|
|
@ -367,8 +367,7 @@ def ask_for_provider_select(apkbuild: dict[str, Any], providers_cfg: dict[str, s
|
||||||
for pkgname, pkg in providers:
|
for pkgname, pkg in providers:
|
||||||
# Strip provider prefix if possible
|
# Strip provider prefix if possible
|
||||||
short = pkgname
|
short = pkgname
|
||||||
if short.startswith(f"{select}-"):
|
short = short.removeprefix(f"{select}-")
|
||||||
short = short[len(f"{select}-") :]
|
|
||||||
|
|
||||||
# Allow selecting the package using both short and long name
|
# Allow selecting the package using both short and long name
|
||||||
providers_short[pkgname] = pkgname
|
providers_short[pkgname] = pkgname
|
||||||
|
|
|
@ -138,11 +138,9 @@ def read_config(
|
||||||
|
|
||||||
def all_channels() -> list[str]:
|
def all_channels() -> list[str]:
|
||||||
"""Get a list of all channels for all pkgrepos."""
|
"""Get a list of all channels for all pkgrepos."""
|
||||||
ret = set()
|
ret = {read_config(repo)["channel"] for repo in pkgrepo_paths()}
|
||||||
for repo in pkgrepo_paths():
|
|
||||||
ret.add(read_config(repo)["channel"])
|
|
||||||
|
|
||||||
logging.verbose(f"all_chanels: {ret}")
|
logging.verbose(f"all_channels: {ret}")
|
||||||
return list(ret)
|
return list(ret)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,7 @@ GITLAB_HOSTS = [
|
||||||
|
|
||||||
|
|
||||||
def init_req_headers() -> None:
|
def init_req_headers() -> None:
|
||||||
global req_headers
|
global req_headers, req_headers_github
|
||||||
global req_headers_github
|
|
||||||
# Only initialize them once
|
# Only initialize them once
|
||||||
if req_headers and req_headers_github:
|
if req_headers and req_headers_github:
|
||||||
return
|
return
|
||||||
|
|
|
@ -64,7 +64,7 @@ def init(args: PmbArgs) -> PmbArgs:
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override config at runtime with command line arguments
|
# Override config at runtime with command line arguments
|
||||||
for key, _ in vars(config).items():
|
for key in vars(config).keys():
|
||||||
if key.startswith("_") or key == "user":
|
if key.startswith("_") or key == "user":
|
||||||
continue
|
continue
|
||||||
value = getattr(args, key, None)
|
value = getattr(args, key, None)
|
||||||
|
|
|
@ -94,7 +94,7 @@ def check(pkgnames: Sequence[str]) -> None:
|
||||||
|
|
||||||
# For each pkgrepo run the linter on the relevant packages
|
# For each pkgrepo run the linter on the relevant packages
|
||||||
has_failed = False
|
has_failed = False
|
||||||
for pkgrepo, apkbuild_paths in apkbuilds.items():
|
for apkbuild_paths in apkbuilds.values():
|
||||||
# We search for the pkgnames in both the normal and systemd repository,
|
# We search for the pkgnames in both the normal and systemd repository,
|
||||||
# so unless the pkgname exists in both the apkbuild_paths is empty for
|
# so unless the pkgname exists in both the apkbuild_paths is empty for
|
||||||
# one of them and needs to be skipped here. This is not very elegant,
|
# one of them and needs to be skipped here. This is not very elegant,
|
||||||
|
|
|
@ -77,8 +77,7 @@ def urls(
|
||||||
|
|
||||||
# Local user repository (for packages compiled with pmbootstrap)
|
# Local user repository (for packages compiled with pmbootstrap)
|
||||||
if user_repository:
|
if user_repository:
|
||||||
for channel in pmb.config.pmaports.all_channels():
|
ret.extend(str(user_repository / channel) for channel in pmb.config.pmaports.all_channels())
|
||||||
ret.append(str(user_repository / channel))
|
|
||||||
|
|
||||||
if mirrors_exclude is True:
|
if mirrors_exclude is True:
|
||||||
return ret
|
return ret
|
||||||
|
@ -137,15 +136,19 @@ def apkindex_files(
|
||||||
if not arch:
|
if not arch:
|
||||||
arch = Arch.native()
|
arch = Arch.native()
|
||||||
|
|
||||||
ret = []
|
ret: list[Path] = []
|
||||||
# Local user repository (for packages compiled with pmbootstrap)
|
# Local user repository (for packages compiled with pmbootstrap)
|
||||||
if user_repository:
|
if user_repository:
|
||||||
for channel in pmb.config.pmaports.all_channels():
|
ret.extend(
|
||||||
ret.append(get_context().config.work / "packages" / channel / arch / "APKINDEX.tar.gz")
|
get_context().config.work / "packages" / channel / arch / "APKINDEX.tar.gz"
|
||||||
|
for channel in pmb.config.pmaports.all_channels()
|
||||||
|
)
|
||||||
|
|
||||||
# Resolve the APKINDEX.$HASH.tar.gz files
|
# Resolve the APKINDEX.$HASH.tar.gz files
|
||||||
for url in urls(False, exclude_mirrors):
|
ret.extend(
|
||||||
ret.append(get_context().config.work / f"cache_apk_{arch}" / apkindex_hash(url))
|
get_context().config.work / f"cache_apk_{arch}" / apkindex_hash(url)
|
||||||
|
for url in urls(False, exclude_mirrors)
|
||||||
|
)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,7 @@ def flat_cmd(
|
||||||
# Merge env and cmd into escaped list
|
# Merge env and cmd into escaped list
|
||||||
escaped = [f"{key}={shlex.quote(os.fspath(value))}" for key, value in env.items()]
|
escaped = [f"{key}={shlex.quote(os.fspath(value))}" for key, value in env.items()]
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
for i in range(len(cmd)):
|
escaped.extend(shlex.quote(os.fspath(cmd[i])) for i in range(len(cmd)))
|
||||||
escaped.append(shlex.quote(os.fspath(cmd[i])))
|
|
||||||
escaped.append(";")
|
escaped.append(";")
|
||||||
|
|
||||||
# Prepend working dir
|
# Prepend working dir
|
||||||
|
|
|
@ -423,11 +423,7 @@ def _parse_comment_tags(lines: list[str], tag: str) -> list[str]:
|
||||||
:returns: array of values of the tag, one per line
|
:returns: array of values of the tag, one per line
|
||||||
"""
|
"""
|
||||||
prefix = f"# {tag}:"
|
prefix = f"# {tag}:"
|
||||||
ret = []
|
return [line[len(prefix) :].strip() for line in lines if line.startswith(prefix)]
|
||||||
for line in lines:
|
|
||||||
if line.startswith(prefix):
|
|
||||||
ret.append(line[len(prefix) :].strip())
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def maintainers(path: Path) -> list[str] | None:
|
def maintainers(path: Path) -> list[str] | None:
|
||||||
|
|
|
@ -24,7 +24,7 @@ def is_set(config: str, option: str) -> bool:
|
||||||
:param option: name of the option to check, e.g. EXT4_FS
|
:param option: name of the option to check, e.g. EXT4_FS
|
||||||
:returns: True if the check passed, False otherwise
|
:returns: True if the check passed, False otherwise
|
||||||
"""
|
"""
|
||||||
return re.search("^CONFIG_" + option + "=[ym]$", config, re.M) is not None
|
return re.search("^CONFIG_" + option + "=[ym]$", config, re.MULTILINE) is not None
|
||||||
|
|
||||||
|
|
||||||
def is_set_str(config: str, option: str, string: str) -> bool:
|
def is_set_str(config: str, option: str, string: str) -> bool:
|
||||||
|
@ -36,7 +36,7 @@ def is_set_str(config: str, option: str, string: str) -> bool:
|
||||||
:param string: the expected string
|
:param string: the expected string
|
||||||
:returns: True if the check passed, False otherwise
|
:returns: True if the check passed, False otherwise
|
||||||
"""
|
"""
|
||||||
match = re.search("^CONFIG_" + option + '="(.*)"$', config, re.M)
|
match = re.search("^CONFIG_" + option + '="(.*)"$', config, re.MULTILINE)
|
||||||
if match:
|
if match:
|
||||||
return string == match.group(1)
|
return string == match.group(1)
|
||||||
else:
|
else:
|
||||||
|
@ -52,7 +52,7 @@ def is_in_array(config: str, option: str, string: str) -> bool:
|
||||||
:param string: the string expected to be an element of the array
|
:param string: the string expected to be an element of the array
|
||||||
:returns: True if the check passed, False otherwise
|
:returns: True if the check passed, False otherwise
|
||||||
"""
|
"""
|
||||||
match = re.search("^CONFIG_" + option + '="(.*)"$', config, re.M)
|
match = re.search("^CONFIG_" + option + '="(.*)"$', config, re.MULTILINE)
|
||||||
if match:
|
if match:
|
||||||
values = match.group(1).split(",")
|
values = match.group(1).split(",")
|
||||||
return string in values
|
return string in values
|
||||||
|
|
|
@ -71,9 +71,7 @@ def ssh_install_apks(args: PmbArgs, user: str, host: str, port: str, paths: list
|
||||||
:param paths: list of absolute paths to locally stored apks
|
:param paths: list of absolute paths to locally stored apks
|
||||||
"""
|
"""
|
||||||
|
|
||||||
remote_paths = []
|
remote_paths = [os.path.join("/tmp", os.path.basename(path)) for path in paths]
|
||||||
for path in paths:
|
|
||||||
remote_paths.append(os.path.join("/tmp", os.path.basename(path)))
|
|
||||||
|
|
||||||
logging.info(f"Copying packages to {user}@{host}")
|
logging.info(f"Copying packages to {user}@{host}")
|
||||||
command: list[PathString] = ["scp", "-P", port, *paths, f"{user}@{host}:/tmp"]
|
command: list[PathString] = ["scp", "-P", port, *paths, f"{user}@{host}:/tmp"]
|
||||||
|
|
|
@ -34,10 +34,13 @@ line-length=100
|
||||||
target-version = "py310"
|
target-version = "py310"
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
|
# FURB101, FURB103: Easier to do if str gets replaced with Path in more places.
|
||||||
|
# PERF203: Negligible performance improvement on Python 3.11 and newer, and
|
||||||
|
# not worth the required rework.
|
||||||
# RUF021: Could be fixed if someone cares about this.
|
# RUF021: Could be fixed if someone cares about this.
|
||||||
# RUF052: Needs a lot of changes, feel free to fix and then remove this ignore.
|
# RUF052: Needs a lot of changes, feel free to fix and then remove this ignore.
|
||||||
extend-ignore = ["RUF021", "RUF052"]
|
extend-ignore = ["FURB101", "FURB103", "PERF203", "RUF021", "RUF052"]
|
||||||
extend-select = ["CPY001", "N", "PIE", "RUF", "UP"]
|
extend-select = ["CPY001", "FURB", "N", "PERF", "PIE", "RUF", "UP"]
|
||||||
preview = true
|
preview = true
|
||||||
|
|
||||||
[tool.ruff.format]
|
[tool.ruff.format]
|
||||||
|
|
|
@ -178,8 +178,7 @@ def random_valid_deviceinfo(tmp_path):
|
||||||
|
|
||||||
# Now write it all out to a file
|
# Now write it all out to a file
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as f:
|
||||||
for key, value in info.items():
|
f.writelines(f'deviceinfo_{key}="{value}"\n' for key, value in info.items())
|
||||||
f.write(f'deviceinfo_{key}="{value}"\n')
|
|
||||||
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue