kunit: tool: fix pre-existing mypy --strict errors and update run_checks.py
Basically, get this command to be happy and make run_checks.py happy $ mypy --strict --exclude '_test.py$' --exclude qemu_configs/ ./tools/testing/kunit/ Primarily the changes are * add `-> None` return type annotations * add all the missing argument type annotations Previously, we had false positives from mypy in `main()`, see commit09641f7c7d("kunit: tool: surface and address more typing issues"). But after commit2dc9d6ca52("kunit: kunit.py extract handlers") refactored things, the variable name reuse mypy hated is gone. Note: mypy complains we don't annotate the types the unused args in our signal handler. That's silly. But to make it happy, I've copy-pasted an appropriate annotation from https://github.com/python/typing/discussions/1042#discussioncomment-2013595. Reported-by: Johannes Berg <johannes.berg@intel.com> Link: https://lore.kernel.org/linux-kselftest/9a172b50457f4074af41fe1dc8e55dcaf4795d7e.camel@sipsolutions.net/ Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
committed by
Shuah Khan
parent
126901ba34
commit
1da2e6220e
@@ -16,6 +16,7 @@ import shutil
|
||||
import signal
|
||||
import threading
|
||||
from typing import Iterator, List, Optional, Tuple
|
||||
from types import FrameType
|
||||
|
||||
import kunit_config
|
||||
import qemu_config
|
||||
@@ -56,7 +57,7 @@ class LinuxSourceTreeOperations:
|
||||
def make_arch_config(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig:
|
||||
return base_kunitconfig
|
||||
|
||||
def make_olddefconfig(self, build_dir: str, make_options) -> None:
|
||||
def make_olddefconfig(self, build_dir: str, make_options: Optional[List[str]]) -> None:
|
||||
command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, 'olddefconfig']
|
||||
if self._cross_compile:
|
||||
command += ['CROSS_COMPILE=' + self._cross_compile]
|
||||
@@ -70,7 +71,7 @@ class LinuxSourceTreeOperations:
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise ConfigError(e.output.decode())
|
||||
|
||||
def make(self, jobs, build_dir: str, make_options) -> None:
|
||||
def make(self, jobs: int, build_dir: str, make_options: Optional[List[str]]) -> None:
|
||||
command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, '--jobs=' + str(jobs)]
|
||||
if make_options:
|
||||
command.extend(make_options)
|
||||
@@ -132,7 +133,7 @@ class LinuxSourceTreeOperationsQemu(LinuxSourceTreeOperations):
|
||||
class LinuxSourceTreeOperationsUml(LinuxSourceTreeOperations):
|
||||
"""An abstraction over command line operations performed on a source tree."""
|
||||
|
||||
def __init__(self, cross_compile=None):
|
||||
def __init__(self, cross_compile: Optional[str]=None):
|
||||
super().__init__(linux_arch='um', cross_compile=cross_compile)
|
||||
|
||||
def make_arch_config(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig:
|
||||
@@ -215,7 +216,7 @@ def _get_qemu_ops(config_path: str,
|
||||
|
||||
if not hasattr(config, 'QEMU_ARCH'):
|
||||
raise ValueError('qemu_config module missing "QEMU_ARCH": ' + config_path)
|
||||
params: qemu_config.QemuArchParams = config.QEMU_ARCH # type: ignore
|
||||
params: qemu_config.QemuArchParams = config.QEMU_ARCH
|
||||
if extra_qemu_args:
|
||||
params.extra_qemu_params.extend(extra_qemu_args)
|
||||
return params.linux_arch, LinuxSourceTreeOperationsQemu(
|
||||
@@ -229,10 +230,10 @@ class LinuxSourceTree:
|
||||
build_dir: str,
|
||||
kunitconfig_paths: Optional[List[str]]=None,
|
||||
kconfig_add: Optional[List[str]]=None,
|
||||
arch=None,
|
||||
cross_compile=None,
|
||||
qemu_config_path=None,
|
||||
extra_qemu_args=None) -> None:
|
||||
arch: Optional[str]=None,
|
||||
cross_compile: Optional[str]=None,
|
||||
qemu_config_path: Optional[str]=None,
|
||||
extra_qemu_args: Optional[List[str]]=None) -> None:
|
||||
signal.signal(signal.SIGINT, self.signal_handler)
|
||||
if qemu_config_path:
|
||||
self._arch, self._ops = _get_qemu_ops(qemu_config_path, extra_qemu_args, cross_compile)
|
||||
@@ -275,7 +276,7 @@ class LinuxSourceTree:
|
||||
logging.error(message)
|
||||
return False
|
||||
|
||||
def build_config(self, build_dir: str, make_options) -> bool:
|
||||
def build_config(self, build_dir: str, make_options: Optional[List[str]]) -> bool:
|
||||
kconfig_path = get_kconfig_path(build_dir)
|
||||
if build_dir and not os.path.exists(build_dir):
|
||||
os.mkdir(build_dir)
|
||||
@@ -303,7 +304,7 @@ class LinuxSourceTree:
|
||||
old_kconfig = kunit_config.parse_file(old_path)
|
||||
return old_kconfig != self._kconfig
|
||||
|
||||
def build_reconfig(self, build_dir: str, make_options) -> bool:
|
||||
def build_reconfig(self, build_dir: str, make_options: Optional[List[str]]) -> bool:
|
||||
"""Creates a new .config if it is not a subset of the .kunitconfig."""
|
||||
kconfig_path = get_kconfig_path(build_dir)
|
||||
if not os.path.exists(kconfig_path):
|
||||
@@ -319,7 +320,7 @@ class LinuxSourceTree:
|
||||
os.remove(kconfig_path)
|
||||
return self.build_config(build_dir, make_options)
|
||||
|
||||
def build_kernel(self, jobs, build_dir: str, make_options) -> bool:
|
||||
def build_kernel(self, jobs: int, build_dir: str, make_options: Optional[List[str]]) -> bool:
|
||||
try:
|
||||
self._ops.make_olddefconfig(build_dir, make_options)
|
||||
self._ops.make(jobs, build_dir, make_options)
|
||||
@@ -328,7 +329,7 @@ class LinuxSourceTree:
|
||||
return False
|
||||
return self.validate_config(build_dir)
|
||||
|
||||
def run_kernel(self, args=None, build_dir='', filter_glob='', timeout=None) -> Iterator[str]:
|
||||
def run_kernel(self, args: Optional[List[str]]=None, build_dir: str='', filter_glob: str='', timeout: Optional[int]=None) -> Iterator[str]:
|
||||
if not args:
|
||||
args = []
|
||||
if filter_glob:
|
||||
@@ -339,7 +340,7 @@ class LinuxSourceTree:
|
||||
assert process.stdout is not None # tell mypy it's set
|
||||
|
||||
# Enforce the timeout in a background thread.
|
||||
def _wait_proc():
|
||||
def _wait_proc() -> None:
|
||||
try:
|
||||
process.wait(timeout=timeout)
|
||||
except Exception as e:
|
||||
@@ -365,6 +366,6 @@ class LinuxSourceTree:
|
||||
waiter.join()
|
||||
subprocess.call(['stty', 'sane'])
|
||||
|
||||
def signal_handler(self, unused_sig, unused_frame) -> None:
|
||||
def signal_handler(self, unused_sig: int, unused_frame: Optional[FrameType]) -> None:
|
||||
logging.error('Build interruption occurred. Cleaning console.')
|
||||
subprocess.call(['stty', 'sane'])
|
||||
|
||||
Reference in New Issue
Block a user