diff options
author | Andy Lutomirski <luto@kernel.org> | 2019-09-27 13:46:34 -0700 |
---|---|---|
committer | Andy Lutomirski <luto@kernel.org> | 2019-09-27 13:47:47 -0700 |
commit | 8008a850db92304954660187a6dab3f4c6de1dbb (patch) | |
tree | b44a0e5a8abab3b96dc3b82e85e0255029fe4a10 | |
parent | 1a0c124b4f7eb1e0d7c08ed00f401e2485fc1cbb (diff) | |
download | virtme-8008a850db92304954660187a6dab3f4c6de1dbb.tar.gz |
Add a bunch more type annotations
mypy --check-untyped-defs -p virtme passes now
Signed-off-by: Andy Lutomirski <luto@kernel.org>
-rw-r--r-- | virtme/commands/configkernel.py | 4 | ||||
-rw-r--r-- | virtme/commands/run.py | 5 | ||||
-rw-r--r-- | virtme/guest_tools.py | 10 | ||||
-rw-r--r-- | virtme/mkinitramfs.py | 16 | ||||
-rw-r--r-- | virtme/modfinder.py | 6 |
5 files changed, 25 insertions, 16 deletions
diff --git a/virtme/commands/configkernel.py b/virtme/commands/configkernel.py index bd3d42f..489d6a7 100644 --- a/virtme/commands/configkernel.py +++ b/virtme/commands/configkernel.py @@ -5,6 +5,8 @@ # as a file called LICENSE with SHA-256 hash: # 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643 +from typing import Optional + import argparse import tempfile import os @@ -103,6 +105,8 @@ def main(): if shutil.which('%s-linux-gnu-gcc' % arch.gccname): conf.append('CONFIG_CROSS_COMPILE="%s-linux-gnu-"' % arch.gccname) + maketarget: Optional[str] + if args.allnoconfig: maketarget = 'allnoconfig' updatetarget = 'silentoldconfig' diff --git a/virtme/commands/run.py b/virtme/commands/run.py index 16422d1..263bdd2 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -475,11 +475,12 @@ def do_it(): if args.busybox is not None: config.busybox = args.busybox else: - config.busybox = mkinitramfs.find_busybox(args.root, is_native) - if config.busybox is None: + busybox = mkinitramfs.find_busybox(args.root, is_native) + if busybox is None: print('virtme-run: initramfs is needed, and no busybox was found', file=sys.stderr) return 1 + config.busybox = busybox if args.rw: config.access = 'rw' diff --git a/virtme/guest_tools.py b/virtme/guest_tools.py index b84f761..2505b49 100644 --- a/virtme/guest_tools.py +++ b/virtme/guest_tools.py @@ -22,7 +22,7 @@ def find_guest_tools(): # No luck. This is somewhat surprising. return None -def find_script(name): +def find_script(name) -> str: # If we're running out of a source checkout, we can find scripts through # the 'virtme/scripts' symlink. fn = pkg_resources.resource_filename(__name__, 'scripts/%s' % name) @@ -30,13 +30,13 @@ def find_script(name): return fn # Otherwise assume we're actually installed and in PATH. - fn = shutil.which(name) - if fn is not None: - return fn + guess = shutil.which(name) + if guess is not None: + return guess # No luck. This is somewhat surprising. raise Exception('could not find script %s' % name) -def run_script(name): +def run_script(name) -> None: fn = find_script(name) subprocess.check_call(executable=fn, args=[fn]) diff --git a/virtme/mkinitramfs.py b/virtme/mkinitramfs.py index dde504d..797fbfe 100644 --- a/virtme/mkinitramfs.py +++ b/virtme/mkinitramfs.py @@ -5,6 +5,8 @@ # as a file called LICENSE with SHA-256 hash: # 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643 +from typing import List, Dict, Optional + import shutil import io import os.path @@ -136,7 +138,7 @@ exec /bin/switch_root /newroot "$init" "$@" """ -def generate_init(config): +def generate_init(config) -> bytes: out = io.StringIO() out.write(_INIT.format( logfunc=_LOGFUNC, @@ -146,13 +148,13 @@ def generate_init(config): class Config: __slots__ = ['modfiles', 'virtme_data', 'virtme_init_path', 'busybox', 'access'] def __init__(self): - self.modfiles = [] - self.virtme_data = {} - self.virtme_init_path = None - self.busybox = None + self.modfiles: List[str] = [] + self.virtme_data: Dict[bytes, bytes] = {} + self.virtme_init_path: Optional[str] = None + self.busybox: Optional[str] = None self.access = 'ro' -def mkinitramfs(out, config): +def mkinitramfs(out, config) -> None: cw = cpiowriter.CpioWriter(out) make_base_layout(cw) make_dev_nodes(cw) @@ -166,7 +168,7 @@ def mkinitramfs(out, config): mode=0o755) cw.write_trailer() -def find_busybox(root, is_native): +def find_busybox(root, is_native) -> Optional[str]: for p in itertools.product(['usr/local', 'usr', ''], ['bin', 'sbin'], ['', '-static', '.static']): diff --git a/virtme/modfinder.py b/virtme/modfinder.py index f0a0601..d0269b0 100644 --- a/virtme/modfinder.py +++ b/virtme/modfinder.py @@ -11,6 +11,8 @@ sort of hotplug. Instead it generates a topological order and loads everything. The idea is to require very few modules. """ +from typing import List + import re import shutil import subprocess @@ -49,8 +51,8 @@ def resolve_dep(modalias, root=None, kver=None, moddir=None): return deps -def merge_mods(lists): - found = set() +def merge_mods(lists) -> List[str]: + found: set = set() mods = [] for mod in itertools.chain(*lists): if mod not in found: |