diff options
author | Wyatt Hepler <hepler@google.com> | 2020-03-05 18:47:47 -0800 |
---|---|---|
committer | CQ Bot Account <commit-bot@chromium.org> | 2020-03-06 23:13:35 +0000 |
commit | e0aef0ab4e3593c1d6c285ed079f36c6c172c1f8 (patch) | |
tree | bbaf78b668f8620eeea5ad7603f53dc5cf2f3a07 /pw_cli | |
parent | 8fd8f9942a73ccf0c97df8da47a541c7bfb97aad (diff) | |
download | pigweed-e0aef0ab4e3593c1d6c285ed079f36c6c172c1f8.tar.gz |
pw_presubmit: Enable mypy and get it passing
- Fix several typing issues.
- Disable type checking in several places where mypy wasn't working
correctly.
- Enable mypy.
- Execute individual steps in the same order as they are provided with
--step.
Change-Id: I229cf8ee39a4db5067c1923b4acfc5fcd164f733
Diffstat (limited to 'pw_cli')
-rw-r--r-- | pw_cli/py/pw_cli/__main__.py | 3 | ||||
-rw-r--r-- | pw_cli/py/pw_cli/color.py | 2 | ||||
-rw-r--r-- | pw_cli/py/pw_cli/envparse.py | 9 | ||||
-rw-r--r-- | pw_cli/py/pw_cli/plugins.py | 5 | ||||
-rw-r--r-- | pw_cli/py/pw_cli/process.py | 19 |
5 files changed, 23 insertions, 15 deletions
diff --git a/pw_cli/py/pw_cli/__main__.py b/pw_cli/py/pw_cli/__main__.py index e95c7d8ff..cf43c3235 100644 --- a/pw_cli/py/pw_cli/__main__.py +++ b/pw_cli/py/pw_cli/__main__.py @@ -25,6 +25,7 @@ import sys import logging import importlib import pkgutil +from typing import NoReturn from pw_cli.color import colors import pw_cli.log @@ -41,7 +42,7 @@ _PIGWEED_BANNER = ''' class ArgumentParser(argparse.ArgumentParser): - def error(self, message: str) -> None: + def error(self, message: str) -> NoReturn: print(colors().magenta(_PIGWEED_BANNER), file=sys.stderr) self.print_usage(sys.stderr) self.exit(2, '%s: error: %s\n' % (self.prog, message)) diff --git a/pw_cli/py/pw_cli/color.py b/pw_cli/py/pw_cli/color.py index b5ca84b71..6559def24 100644 --- a/pw_cli/py/pw_cli/color.py +++ b/pw_cli/py/pw_cli/color.py @@ -66,7 +66,7 @@ def colors(enabled: Optional[bool] = None) -> Union[_Color, _NoColor]: if enabled and os.name == 'nt': # Enable ANSI color codes in Windows cmd.exe. - kernel32 = ctypes.windll.kernel32 + kernel32 = ctypes.windll.kernel32 # type: ignore kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7) return _Color() if enabled else _NoColor() diff --git a/pw_cli/py/pw_cli/envparse.py b/pw_cli/py/pw_cli/envparse.py index da38fe37c..c65330bec 100644 --- a/pw_cli/py/pw_cli/envparse.py +++ b/pw_cli/py/pw_cli/envparse.py @@ -77,7 +77,9 @@ class EnvironmentParser: def add_var( self, name: str, - type: TypeConversion[T] = str, # pylint: disable=redefined-builtin + # pylint: disable=redefined-builtin + type: TypeConversion[T] = str, # type: ignore + # pylint: enable=redefined-builtin default: Optional[T] = None, ) -> None: """Registers an environment variable. @@ -95,7 +97,10 @@ class EnvironmentParser: raise ValueError( f'Variable {name} does not have prefix {self._prefix}') - self._variables[name] = VariableDescriptor(name, type, default) + self._variables[name] = VariableDescriptor( + name, + type, # type: ignore + default) # type: ignore def parse_env(self, env: Optional[Mapping[str, str]] = None) -> EnvNamespace: diff --git a/pw_cli/py/pw_cli/plugins.py b/pw_cli/py/pw_cli/plugins.py index dfde79238..f2f0d3e2b 100644 --- a/pw_cli/py/pw_cli/plugins.py +++ b/pw_cli/py/pw_cli/plugins.py @@ -15,11 +15,10 @@ import argparse import logging -from typing import Callable -from typing import NamedTuple +from typing import Any, Callable, NamedTuple _LOG = logging.getLogger(__name__) -DefineArgsFunction = Callable[[argparse.ArgumentParser], None] +DefineArgsFunction = Callable[[argparse.ArgumentParser], Any] class Plugin(NamedTuple): diff --git a/pw_cli/py/pw_cli/process.py b/pw_cli/py/pw_cli/process.py index 7467df8df..cfb2d6368 100644 --- a/pw_cli/py/pw_cli/process.py +++ b/pw_cli/py/pw_cli/process.py @@ -29,21 +29,24 @@ _LOG = logging.getLogger(__name__) PW_SUBPROCESS_ENV = 'PW_SUBPROCESS' -async def run_async(*args: str, silent: bool = False) -> int: +async def run_async(program: str, *args: str, silent: bool = False) -> int: """Runs a command, capturing and logging its output. Returns the exit status of the command. """ - command = args[0] - _LOG.debug('Running `%s`', shlex.join(command)) + _LOG.debug('Running `%s`', shlex.join([program, *args])) env = os.environ.copy() env[PW_SUBPROCESS_ENV] = '1' stdout = asyncio.subprocess.DEVNULL if silent else asyncio.subprocess.PIPE process = await asyncio.create_subprocess_exec( - *command, stdout=stdout, stderr=asyncio.subprocess.STDOUT, env=env) + program, + *args, + stdout=stdout, + stderr=asyncio.subprocess.STDOUT, + env=env) if process.stdout is not None: while True: @@ -57,13 +60,13 @@ async def run_async(*args: str, silent: bool = False) -> int: status = await process.wait() if status == 0: - _LOG.info('%s exited successfully', command[0]) + _LOG.info('%s exited successfully', program) else: - _LOG.error('%s exited with status %d', command[0], status) + _LOG.error('%s exited with status %d', program, status) return status -def run(*args: str, silent: bool = False) -> int: +def run(program: str, *args: str, silent: bool = False) -> int: """Synchronous wrapper for run_async.""" - return asyncio.run(run_async(args, silent)) + return asyncio.run(run_async(program, *args, silent=silent)) |