Skip to content

Commit

Permalink
Start linting the examples folder
Browse files Browse the repository at this point in the history
The examples folder currently contains a repository example and it's
good if we start linting its content and as a result add type
annotations.

Signed-off-by: Martin Vrachev <[email protected]>
  • Loading branch information
MVrachev committed Dec 1, 2021
1 parent 5c8a866 commit 481f45c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions examples/repo_example/basic_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ show_error_codes = "True"
files = [
"tuf/api/",
"tuf/ngclient",
"tuf/exceptions.py"
"tuf/exceptions.py",
"examples/",
]

[[tool.mypy.overrides]]
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ commands =
changedir = {toxinidir}
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 tuf/api tuf/ngclient examples
isort --check --diff tuf/api tuf/ngclient examples
pylint -j 0 tuf/api tuf/ngclient --rcfile=pyproject.toml examples

# NOTE: Contrary to what the pylint docs suggest, ignoring full paths does
# work, unfortunately each subdirectory has to be ignored explicitly.
Expand Down

0 comments on commit 481f45c

Please sign in to comment.