Skip to content

Commit

Permalink
osbuild: add "mypy-strict" check
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 authored and supakeen committed Jan 23, 2024
1 parent a56afcb commit d883515
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ test-all:

.PHONY: lint
lint:
tox run-parallel -e ruff,pylint,autopep8,isort,mypy
tox run-parallel -e ruff,pylint,autopep8,isort,mypy,mypy-strict

#
# Building packages
Expand Down
15 changes: 10 additions & 5 deletions osbuild/main_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
import json
import os
import sys
import typing
from typing import List

import osbuild
import osbuild.meta
import osbuild.monitor
from osbuild.meta import ValidationResult
from osbuild.objectstore import ObjectStore
from osbuild.pipeline import Manifest
from osbuild.util.parsing import parse_size
from osbuild.util.term import fmt as vt


def parse_manifest(path):
def parse_manifest(path: str) -> dict:
if path == "-":
manifest = json.load(sys.stdin)
else:
Expand All @@ -29,7 +33,7 @@ def parse_manifest(path):
return manifest


def show_validation(result, name):
def show_validation(result: ValidationResult, name: str) -> None:
if name == "-":
name = "<stdin>"

Expand All @@ -47,7 +51,7 @@ def show_validation(result, name):
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]
obj = store.get(pipeline.id)
dest = os.path.join(output_directory, name_or_id)
Expand All @@ -58,7 +62,8 @@ def export(name_or_id, output_directory, store, manifest):
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",
description="Build operating system images")

Expand Down Expand Up @@ -103,7 +108,7 @@ def parse_arguments(sys_argv):


# pylint: disable=too-many-branches,too-many-return-statements,too-many-statements
def osbuild_cli():
def osbuild_cli() -> int:
args = parse_arguments(sys.argv)
desc = parse_manifest(args.manifest_path)

Expand Down
10 changes: 9 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env_list =
labels =
test = py{36,37,38,39,310,311}
lint = ruff, isort, autopep8, pylint
type = mypy
type = mypy,mypy-strict

[testenv]
description = "run osbuild unit tests"
Expand All @@ -26,6 +26,7 @@ deps =
setenv =
LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/* stages/*.* stages/test/*.py test/ tools/
TYPEABLES = osbuild
TYPEABLES_STRICT = ./osbuild/main_cli.py

passenv =
TEST_CATEGORY
Expand Down Expand Up @@ -71,3 +72,10 @@ deps =

commands =
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}'

0 comments on commit d883515

Please sign in to comment.