Skip to content

Commit a93f618

Browse files
authored
Merge pull request #1701 from MVrachev/lint-examples
Start linting the examples folder
2 parents dd5deee + d697f73 commit a93f618

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
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

-5
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ strict_equality = "True"
7676
disallow_untyped_defs = "True"
7777
disallow_untyped_calls = "True"
7878
show_error_codes = "True"
79-
files = [
80-
"tuf/api/",
81-
"tuf/ngclient",
82-
"tuf/exceptions.py"
83-
]
8479

8580
[[tool.mypy.overrides]]
8681
module = [

tox.ini

+5-4
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ commands =
3838

3939
[testenv:lint]
4040
changedir = {toxinidir}
41+
lint_dirs = tuf/api tuf/ngclient examples
4142
commands =
4243
# 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
44+
black --check --diff {[testenv:lint]lint_dirs}
45+
isort --check --diff {[testenv:lint]lint_dirs}
46+
pylint -j 0 --rcfile=pyproject.toml {[testenv:lint]lint_dirs}
4647

4748
# NOTE: Contrary to what the pylint docs suggest, ignoring full paths does
4849
# work, unfortunately each subdirectory has to be ignored explicitly.
4950
pylint -j 0 tuf --ignore=tuf/api,tuf/api/serialization,tuf/ngclient,tuf/ngclient/_internal
5051

51-
mypy
52+
mypy {[testenv:lint]lint_dirs} tuf/exceptions.py
5253

5354
bandit -r tuf
5455

0 commit comments

Comments
 (0)