aportgen: more type hinting (MR 2252)

Thanks WhyNotHugo for the recommendations.
This commit is contained in:
Caleb Connolly 2024-06-08 21:40:16 +02:00 committed by Oliver Smith
parent 866e5bcfab
commit 8e18b16370
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
6 changed files with 18 additions and 18 deletions

View file

@ -55,7 +55,7 @@ def properties(pkgname):
raise ValueError("No generator available for " + pkgname + "!") raise ValueError("No generator available for " + pkgname + "!")
def generate(pkgname, fork_alpine): def generate(pkgname: str, fork_alpine: bool):
if fork_alpine: if fork_alpine:
prefix, folder, options = (pkgname, "temp", prefix, folder, options = (pkgname, "temp",
{"confirm_overwrite": True}) {"confirm_overwrite": True})

View file

@ -5,13 +5,12 @@ import pmb.aportgen.core
import pmb.build import pmb.build
import pmb.chroot.apk import pmb.chroot.apk
import pmb.chroot.apk_static import pmb.chroot.apk_static
from pmb.types import PmbArgs
import pmb.helpers.run import pmb.helpers.run
import pmb.parse.apkindex import pmb.parse.apkindex
from pmb.core import Chroot, get_context from pmb.core import Chroot, get_context
def generate(pkgname): def generate(pkgname: str):
arch = pkgname.split("-")[2] arch = pkgname.split("-")[2]
context = get_context() context = get_context()

View file

@ -156,7 +156,7 @@ def rewrite(pkgname, path_original="", fields={}, replace_pkgname=None,
handle.truncate() handle.truncate()
def get_upstream_aport(pkgname, arch=None): def get_upstream_aport(pkgname: str, arch=None):
""" """
Perform a git checkout of Alpine's aports and get the path to the aport. Perform a git checkout of Alpine's aports and get the path to the aport.

View file

@ -1,9 +1,9 @@
# Copyright 2023 Oliver Smith # Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from pmb.core import get_context from pmb.core import get_context
from pmb.core.arch import Arch
from pmb.helpers import logging from pmb.helpers import logging
import os import os
from pmb.types import PmbArgs
import pmb.helpers.cli import pmb.helpers.cli
import pmb.helpers.run import pmb.helpers.run
import pmb.aportgen.core import pmb.aportgen.core
@ -12,7 +12,7 @@ import pmb.parse
def ask_for_architecture(): def ask_for_architecture():
architectures = Arch.supported() architectures = [str(a) for a in Arch.supported()]
# Don't show armhf, new ports shouldn't use this architecture # Don't show armhf, new ports shouldn't use this architecture
if "armhf" in architectures: if "armhf" in architectures:
architectures.remove("armhf") architectures.remove("armhf")
@ -20,7 +20,7 @@ def ask_for_architecture():
ret = pmb.helpers.cli.ask("Device architecture", architectures, ret = pmb.helpers.cli.ask("Device architecture", architectures,
"aarch64", complete=architectures) "aarch64", complete=architectures)
if ret in architectures: if ret in architectures:
return ret return Arch.from_str(ret)
logging.fatal("ERROR: Invalid architecture specified. If you want to" logging.fatal("ERROR: Invalid architecture specified. If you want to"
" add a new architecture, edit" " add a new architecture, edit"
" build_device_architectures in" " build_device_architectures in"
@ -60,12 +60,12 @@ def ask_for_chassis():
complete=types) complete=types)
def ask_for_keyboard(): def ask_for_keyboard() -> bool:
return pmb.helpers.cli.confirm("Does the device have a hardware" return pmb.helpers.cli.confirm("Does the device have a hardware"
" keyboard?") " keyboard?")
def ask_for_external_storage(): def ask_for_external_storage() -> bool:
return pmb.helpers.cli.confirm("Does the device have a sdcard or" return pmb.helpers.cli.confirm("Does the device have a sdcard or"
" other external storage medium?") " other external storage medium?")
@ -178,9 +178,9 @@ def generate_deviceinfo_fastboot_content(bootimg=None):
return content return content
def generate_deviceinfo(pkgname, name, manufacturer, year, arch, def generate_deviceinfo(pkgname: str, name: str, manufacturer: str, year: str, arch: Arch,
chassis, has_keyboard, has_external_storage, chassis: str, has_keyboard: bool, has_external_storage: bool,
flash_method, bootimg=None): flash_method: str, bootimg=None):
codename = "-".join(pkgname.split("-")[1:]) codename = "-".join(pkgname.split("-")[1:])
external_storage = "true" if has_external_storage else "false" external_storage = "true" if has_external_storage else "false"
# Note: New variables must be added to pmb/config/__init__.py as well # Note: New variables must be added to pmb/config/__init__.py as well
@ -246,7 +246,7 @@ def generate_deviceinfo(pkgname, name, manufacturer, year, arch,
handle.write(line.lstrip() + "\n") handle.write(line.lstrip() + "\n")
def generate_modules_initfs(): def generate_modules_initfs() -> None:
content = """\ content = """\
# Remove this file if unnecessary (CHANGEME!) # Remove this file if unnecessary (CHANGEME!)
# This file shall contain a list of modules to be included in the initramfs, # This file shall contain a list of modules to be included in the initramfs,
@ -268,7 +268,7 @@ def generate_modules_initfs():
handle.write(line.lstrip() + "\n") handle.write(line.lstrip() + "\n")
def generate_apkbuild(pkgname, name, arch, flash_method): def generate_apkbuild(pkgname: str, name: str, arch: Arch, flash_method: str):
# Dependencies # Dependencies
depends = ["postmarketos-base", depends = ["postmarketos-base",
"linux-" + "-".join(pkgname.split("-")[1:])] "linux-" + "-".join(pkgname.split("-")[1:])]
@ -319,7 +319,7 @@ def generate_apkbuild(pkgname, name, arch, flash_method):
handle.write(line[8:].replace(" " * 4, "\t") + "\n") handle.write(line[8:].replace(" " * 4, "\t") + "\n")
def generate(pkgname): def generate(pkgname: str):
arch = ask_for_architecture() arch = ask_for_architecture()
manufacturer = ask_for_manufacturer() manufacturer = ask_for_manufacturer()
name = ask_for_name(manufacturer) name = ask_for_name(manufacturer)

View file

@ -7,7 +7,7 @@ import pmb.helpers.git
import pmb.helpers.run import pmb.helpers.run
def generate(pkgname): def generate(pkgname: str):
# Copy original aport # Copy original aport
prefix = pkgname.split("-")[0] prefix = pkgname.split("-")[0]
arch = pkgname.split("-")[1] arch = pkgname.split("-")[1]

View file

@ -1,5 +1,6 @@
# Copyright 2023 Oliver Smith # Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from typing import List
from pmb.core import get_context from pmb.core import get_context
from pmb.parse.deviceinfo import Deviceinfo from pmb.parse.deviceinfo import Deviceinfo
import pmb.helpers.run import pmb.helpers.run
@ -7,7 +8,7 @@ import pmb.aportgen.core
import pmb.parse.apkindex import pmb.parse.apkindex
def generate_apkbuild(pkgname, deviceinfo: Deviceinfo, patches): def generate_apkbuild(pkgname: str, deviceinfo: Deviceinfo, patches: List[str]):
device = "-".join(pkgname.split("-")[1:]) device = "-".join(pkgname.split("-")[1:])
carch = deviceinfo.arch.kernel() carch = deviceinfo.arch.kernel()
@ -110,7 +111,7 @@ def generate_apkbuild(pkgname, deviceinfo: Deviceinfo, patches):
hndl.write(line[8:].replace(" " * 4, "\t") + "\n") hndl.write(line[8:].replace(" " * 4, "\t") + "\n")
def generate(pkgname): def generate(pkgname: str):
device = "-".join(pkgname.split("-")[1:]) device = "-".join(pkgname.split("-")[1:])
deviceinfo = pmb.parse.deviceinfo(device) deviceinfo = pmb.parse.deviceinfo(device)
work = get_context().config.work work = get_context().config.work