Skip to content

Commit 1ae6a22

Browse files
committed
Start linting the examples folder
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]>
1 parent d991362 commit 1ae6a22

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

examples/repo_example/basic_repo.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from collections import OrderedDict
2929
from datetime import datetime, timedelta
3030
from pathlib import Path
31+
from typing import Any, Dict
3132

3233
from securesystemslib.keys import generate_ed25519_key
3334
from securesystemslib.signer import SSlibSigner
@@ -48,7 +49,7 @@
4849
from tuf.api.serialization.json import JSONSerializer
4950

5051

51-
def _in(days):
52+
def _in(days: float) -> datetime:
5253
"""Adds 'days' to now and returns datetime object w/o microseconds."""
5354
return datetime.utcnow().replace(microsecond=0) + timedelta(days=days)
5455

@@ -89,8 +90,8 @@ def _in(days):
8990

9091
# Define containers for role objects and cryptographic keys created below. This
9192
# allows us to sign and write metadata in a batch more easily.
92-
roles = {}
93-
keys = {}
93+
roles: Dict[str, Metadata] = {}
94+
keys: Dict[str, Dict[str, Any]] = {}
9495

9596

9697
# Targets (integrity)
@@ -117,7 +118,7 @@ def _in(days):
117118
local_path = Path(__file__).resolve()
118119
target_path = f"{local_path.parts[-2]}/{local_path.parts[-1]}"
119120

120-
target_file_info = TargetFile.from_file(target_path, local_path)
121+
target_file_info = TargetFile.from_file(target_path, str(local_path))
121122
roles["targets"].signed.targets[target_path] = target_file_info
122123

123124
# Snapshot (consistency)
@@ -332,7 +333,7 @@ def _in(days):
332333
del roles["targets"].signed.targets[target_path]
333334

334335
# Increase expiry (delegators should be less volatile)
335-
roles["targets"].expires = _in(365)
336+
roles["targets"].signed.expires = _in(365)
336337

337338

338339
# Snapshot + Timestamp + Sign + Persist

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ show_error_codes = "True"
7979
files = [
8080
"tuf/api/",
8181
"tuf/ngclient",
82-
"tuf/exceptions.py"
82+
"tuf/exceptions.py",
83+
"examples/",
8384
]
8485

8586
[[tool.mypy.overrides]]

tox.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ commands =
4040
changedir = {toxinidir}
4141
commands =
4242
# Use different configs for new (tuf/api/*) and legacy code
43-
black --check --diff tuf/api tuf/ngclient
44-
isort --check --diff tuf/api tuf/ngclient
45-
pylint -j 0 tuf/api tuf/ngclient --rcfile=pyproject.toml
43+
black --check --diff tuf/api tuf/ngclient examples
44+
isort --check --diff tuf/api tuf/ngclient examples
45+
pylint -j 0 tuf/api tuf/ngclient --rcfile=pyproject.toml examples
4646

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

0 commit comments

Comments
 (0)