diff --git a/examples/repo_example/basic_repo.py b/examples/repo_example/basic_repo.py index 480a109053..39855f71ef 100644 --- a/examples/repo_example/basic_repo.py +++ b/examples/repo_example/basic_repo.py @@ -28,6 +28,7 @@ from collections import OrderedDict from datetime import datetime, timedelta from pathlib import Path +from typing import Any, Dict from securesystemslib.keys import generate_ed25519_key from securesystemslib.signer import SSlibSigner @@ -48,7 +49,7 @@ from tuf.api.serialization.json import JSONSerializer -def _in(days): +def _in(days: float) -> datetime: """Adds 'days' to now and returns datetime object w/o microseconds.""" return datetime.utcnow().replace(microsecond=0) + timedelta(days=days) @@ -89,8 +90,8 @@ def _in(days): # Define containers for role objects and cryptographic keys created below. This # allows us to sign and write metadata in a batch more easily. -roles = {} -keys = {} +roles: Dict[str, Metadata] = {} +keys: Dict[str, Dict[str, Any]] = {} # Targets (integrity) @@ -117,7 +118,7 @@ def _in(days): local_path = Path(__file__).resolve() target_path = f"{local_path.parts[-2]}/{local_path.parts[-1]}" -target_file_info = TargetFile.from_file(target_path, local_path) +target_file_info = TargetFile.from_file(target_path, str(local_path)) roles["targets"].signed.targets[target_path] = target_file_info # Snapshot (consistency) @@ -332,7 +333,7 @@ def _in(days): del roles["targets"].signed.targets[target_path] # Increase expiry (delegators should be less volatile) -roles["targets"].expires = _in(365) +roles["targets"].signed.expires = _in(365) # Snapshot + Timestamp + Sign + Persist diff --git a/pyproject.toml b/pyproject.toml index 339f2416dc..e80efb4cf0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,11 +76,6 @@ strict_equality = "True" disallow_untyped_defs = "True" disallow_untyped_calls = "True" show_error_codes = "True" -files = [ - "tuf/api/", - "tuf/ngclient", - "tuf/exceptions.py" -] [[tool.mypy.overrides]] module = [ diff --git a/tox.ini b/tox.ini index a6e0d765d8..443cc9b710 100644 --- a/tox.ini +++ b/tox.ini @@ -38,17 +38,18 @@ commands = [testenv:lint] changedir = {toxinidir} +lint_dirs = tuf/api tuf/ngclient examples commands = # Use different configs for new (tuf/api/*) and legacy code - black --check --diff tuf/api tuf/ngclient - isort --check --diff tuf/api tuf/ngclient - pylint -j 0 tuf/api tuf/ngclient --rcfile=pyproject.toml + black --check --diff {[testenv:lint]lint_dirs} + isort --check --diff {[testenv:lint]lint_dirs} + pylint -j 0 --rcfile=pyproject.toml {[testenv:lint]lint_dirs} # NOTE: Contrary to what the pylint docs suggest, ignoring full paths does # work, unfortunately each subdirectory has to be ignored explicitly. pylint -j 0 tuf --ignore=tuf/api,tuf/api/serialization,tuf/ngclient,tuf/ngclient/_internal - mypy + mypy {[testenv:lint]lint_dirs} tuf/exceptions.py bandit -r tuf