osbuild: add "mypy-strict" check
This commit is contained in:
parent
a56afcb280
commit
d8835150c2
3 changed files with 20 additions and 7 deletions
2
Makefile
2
Makefile
|
|
@ -248,7 +248,7 @@ test-all:
|
||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint:
|
lint:
|
||||||
tox run-parallel -e ruff,pylint,autopep8,isort,mypy
|
tox run-parallel -e ruff,pylint,autopep8,isort,mypy,mypy-strict
|
||||||
|
|
||||||
#
|
#
|
||||||
# Building packages
|
# Building packages
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,20 @@ import argparse
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import typing
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import osbuild
|
import osbuild
|
||||||
import osbuild.meta
|
import osbuild.meta
|
||||||
import osbuild.monitor
|
import osbuild.monitor
|
||||||
|
from osbuild.meta import ValidationResult
|
||||||
from osbuild.objectstore import ObjectStore
|
from osbuild.objectstore import ObjectStore
|
||||||
|
from osbuild.pipeline import Manifest
|
||||||
from osbuild.util.parsing import parse_size
|
from osbuild.util.parsing import parse_size
|
||||||
from osbuild.util.term import fmt as vt
|
from osbuild.util.term import fmt as vt
|
||||||
|
|
||||||
|
|
||||||
def parse_manifest(path):
|
def parse_manifest(path: str) -> dict:
|
||||||
if path == "-":
|
if path == "-":
|
||||||
manifest = json.load(sys.stdin)
|
manifest = json.load(sys.stdin)
|
||||||
else:
|
else:
|
||||||
|
|
@ -29,7 +33,7 @@ def parse_manifest(path):
|
||||||
return manifest
|
return manifest
|
||||||
|
|
||||||
|
|
||||||
def show_validation(result, name):
|
def show_validation(result: ValidationResult, name: str) -> None:
|
||||||
if name == "-":
|
if name == "-":
|
||||||
name = "<stdin>"
|
name = "<stdin>"
|
||||||
|
|
||||||
|
|
@ -47,7 +51,7 @@ def show_validation(result, name):
|
||||||
print(f" {error.message}\n")
|
print(f" {error.message}\n")
|
||||||
|
|
||||||
|
|
||||||
def export(name_or_id, output_directory, store, manifest):
|
def export(name_or_id: str, output_directory: str, store: ObjectStore, manifest: Manifest) -> None:
|
||||||
pipeline = manifest[name_or_id]
|
pipeline = manifest[name_or_id]
|
||||||
obj = store.get(pipeline.id)
|
obj = store.get(pipeline.id)
|
||||||
dest = os.path.join(output_directory, name_or_id)
|
dest = os.path.join(output_directory, name_or_id)
|
||||||
|
|
@ -58,7 +62,8 @@ def export(name_or_id, output_directory, store, manifest):
|
||||||
obj.export(dest, skip_preserve_owner=skip_preserve_owner)
|
obj.export(dest, skip_preserve_owner=skip_preserve_owner)
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments(sys_argv):
|
@typing.no_type_check # see https://github.com/python/typeshed/issues/3107
|
||||||
|
def parse_arguments(sys_argv: List[str]) -> argparse.Namespace:
|
||||||
parser = argparse.ArgumentParser(prog="osbuild",
|
parser = argparse.ArgumentParser(prog="osbuild",
|
||||||
description="Build operating system images")
|
description="Build operating system images")
|
||||||
|
|
||||||
|
|
@ -103,7 +108,7 @@ def parse_arguments(sys_argv):
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-branches,too-many-return-statements,too-many-statements
|
# pylint: disable=too-many-branches,too-many-return-statements,too-many-statements
|
||||||
def osbuild_cli():
|
def osbuild_cli() -> int:
|
||||||
args = parse_arguments(sys.argv)
|
args = parse_arguments(sys.argv)
|
||||||
desc = parse_manifest(args.manifest_path)
|
desc = parse_manifest(args.manifest_path)
|
||||||
|
|
||||||
|
|
|
||||||
10
tox.ini
10
tox.ini
|
|
@ -7,7 +7,7 @@ env_list =
|
||||||
labels =
|
labels =
|
||||||
test = py{36,37,38,39,310,311}
|
test = py{36,37,38,39,310,311}
|
||||||
lint = ruff, isort, autopep8, pylint
|
lint = ruff, isort, autopep8, pylint
|
||||||
type = mypy
|
type = mypy,mypy-strict
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
description = "run osbuild unit tests"
|
description = "run osbuild unit tests"
|
||||||
|
|
@ -26,6 +26,7 @@ deps =
|
||||||
setenv =
|
setenv =
|
||||||
LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/* stages/*.* stages/test/*.py test/ tools/
|
LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/* stages/*.* stages/test/*.py test/ tools/
|
||||||
TYPEABLES = osbuild
|
TYPEABLES = osbuild
|
||||||
|
TYPEABLES_STRICT = ./osbuild/main_cli.py
|
||||||
|
|
||||||
passenv =
|
passenv =
|
||||||
TEST_CATEGORY
|
TEST_CATEGORY
|
||||||
|
|
@ -71,3 +72,10 @@ deps =
|
||||||
|
|
||||||
commands =
|
commands =
|
||||||
bash -c 'python -m mypy {env:TYPEABLES}'
|
bash -c 'python -m mypy {env:TYPEABLES}'
|
||||||
|
|
||||||
|
[testenv:mypy-strict]
|
||||||
|
deps =
|
||||||
|
mypy==1.2.0
|
||||||
|
|
||||||
|
commands =
|
||||||
|
bash -c 'python -m mypy --follow-imports=skip --disallow-untyped-calls --disallow-untyped-defs --disallow-incomplete-defs {env:TYPEABLES_STRICT}'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue