Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop python3.6 and remove the usage of OrderedDict #1783

Merged
merged 2 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# Run regular TUF tests on each OS/Python combination, plus special tests
# (sslib master) and linters on Linux/Python3.x only.
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10"]
os: [ubuntu-latest, macos-latest, windows-latest]
toxenv: [py]
include:
Expand Down
34 changes: 14 additions & 20 deletions examples/repo_example/basic_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"""
import os
import tempfile
from collections import OrderedDict
from datetime import datetime, timedelta
from pathlib import Path
from typing import Any, Dict
Expand Down Expand Up @@ -103,7 +102,7 @@ def _in(days: float) -> datetime:
signed=Targets(
version=1, spec_version=SPEC_VERSION, expires=_in(7), targets={}
),
signatures=OrderedDict(),
signatures={},
)

# For the purpose of this example we use the top-level targets role to protect
Expand Down Expand Up @@ -134,7 +133,7 @@ def _in(days: float) -> datetime:
expires=_in(7),
meta={"targets.json": MetaFile(version=1)},
),
OrderedDict(),
{},
)

# Timestamp (freshness)
Expand All @@ -156,7 +155,7 @@ def _in(days: float) -> datetime:
expires=_in(1),
snapshot_meta=MetaFile(version=1),
),
OrderedDict(),
{},
)

# Root (root of trust)
Expand Down Expand Up @@ -195,7 +194,7 @@ def _in(days: float) -> datetime:
},
consistent_snapshot=True,
),
signatures=OrderedDict(),
signatures={},
)

# NOTE: We only need the public part to populate root, so it is possible to use
Expand Down Expand Up @@ -292,7 +291,7 @@ def _in(days: float) -> datetime:
expires=_in(7),
targets={target_path: target_file_info},
),
signatures=OrderedDict(),
signatures={},
)


Expand All @@ -313,20 +312,15 @@ def _in(days: float) -> datetime:
keys[delegatee_name]
)
},
roles=OrderedDict(
[
(
delegatee_name,
DelegatedRole(
name=delegatee_name,
keyids=[keys[delegatee_name]["keyid"]],
threshold=1,
terminating=True,
paths=["*.py"],
),
)
]
),
roles={
delegatee_name: DelegatedRole(
name=delegatee_name,
keyids=[keys[delegatee_name]["keyid"]],
threshold=1,
terminating=True,
paths=["*.py"],
),
},
)

# Remove target file info from top-level targets (delegatee is now responsible)
Expand Down
7 changes: 3 additions & 4 deletions examples/repo_example/hashed_bin_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import hashlib
import os
import tempfile
from collections import OrderedDict
from datetime import datetime, timedelta
from pathlib import Path
from typing import Any, Dict, Iterator, List, Tuple
Expand Down Expand Up @@ -160,10 +159,10 @@ def find_hash_bin(path: str) -> str:
keys["bin-n"]
)
},
roles=OrderedDict(),
roles={},
),
),
signatures=OrderedDict(),
signatures={},
)

# The hash bin generator yields an ordered list of incremental hash bin names
Expand All @@ -190,7 +189,7 @@ def find_hash_bin(path: str) -> str:
signed=Targets(
version=1, spec_version=SPEC_VERSION, expires=_in(7), targets={}
),
signatures=OrderedDict(),
signatures={},
)

# Add target file
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# 1. Use this script to create a pinned requirements file for each Python
# version
# ```
# for v in 3.6 3.7 3.8 3.9; do
# for v in 3.7 3.8 3.9; do
# mkvirtualenv tuf-env-${v} -p python${v};
# python3 -m pip install pip-tools;
# pip-compile --no-header -o requirements-${v}.txt requirements.txt;
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ classifiers =
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Expand All @@ -37,7 +36,7 @@ packages = find:
scripts =
tuf/scripts/repo.py
tuf/scripts/client.py
python_requires = ~=3.6
python_requires = ~=3.7
install_requires =
requests>=2.19.1
securesystemslib>=0.20.0
Expand Down
13 changes: 6 additions & 7 deletions tests/repository_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import logging
import os
import tempfile
from collections import OrderedDict
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from typing import Dict, Iterator, List, Optional, Tuple
Expand Down Expand Up @@ -167,15 +166,15 @@ def _initialize(self) -> None:
"""Setup a minimal valid repository."""

targets = Targets(1, SPEC_VER, self.safe_expiry, {}, None)
self.md_targets = Metadata(targets, OrderedDict())
self.md_targets = Metadata(targets, {})

meta = {"targets.json": MetaFile(targets.version)}
snapshot = Snapshot(1, SPEC_VER, self.safe_expiry, meta)
self.md_snapshot = Metadata(snapshot, OrderedDict())
self.md_snapshot = Metadata(snapshot, {})

snapshot_meta = MetaFile(snapshot.version)
timestamp = Timestamp(1, SPEC_VER, self.safe_expiry, snapshot_meta)
self.md_timestamp = Metadata(timestamp, OrderedDict())
self.md_timestamp = Metadata(timestamp, {})

roles = {role_name: Role([], 1) for role_name in TOP_LEVEL_ROLE_NAMES}
root = Root(1, SPEC_VER, self.safe_expiry, {}, roles, True)
Expand All @@ -185,7 +184,7 @@ def _initialize(self) -> None:
root.add_key(role, key)
self.add_signer(role, signer)

self.md_root = Metadata(root, OrderedDict())
self.md_root = Metadata(root, {})
self.publish_root()

def publish_root(self) -> None:
Expand Down Expand Up @@ -357,7 +356,7 @@ def add_delegation(

# Create delegation
if delegator.delegations is None:
delegator.delegations = Delegations({}, OrderedDict())
delegator.delegations = Delegations({}, {})
# put delegation last by default
delegator.delegations.roles[role.name] = role

Expand All @@ -368,7 +367,7 @@ def add_delegation(

# Add metadata for the role
if role.name not in self.md_delegates:
self.md_delegates[role.name] = Metadata(targets, OrderedDict())
self.md_delegates[role.name] = Metadata(targets, {})

def write(self) -> None:
"""Dump current repository metadata to self.dump_dir
Expand Down
9 changes: 4 additions & 5 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io
import logging
import tempfile
from collections import OrderedDict
from datetime import datetime
from typing import (
IO,
Expand Down Expand Up @@ -113,7 +112,7 @@ class Metadata(Generic[T]):
signing the canonical serialized representation of 'signed'.
"""

def __init__(self, signed: T, signatures: "OrderedDict[str, Signature]"):
def __init__(self, signed: T, signatures: Dict[str, Signature]):
self.signed: T = signed
self.signatures = signatures

Expand Down Expand Up @@ -150,7 +149,7 @@ def from_dict(cls, metadata: Dict[str, Any]) -> "Metadata[T]":
raise ValueError(f'unrecognized metadata type "{_type}"')

# Make sure signatures are unique
signatures: "OrderedDict[str, Signature]" = OrderedDict()
signatures: Dict[str, Signature] = {}
for sig_dict in metadata.pop("signatures"):
sig = Signature.from_dict(sig_dict)
if sig.keyid in signatures:
Expand Down Expand Up @@ -1211,7 +1210,7 @@ class Delegations:
def __init__(
self,
keys: Dict[str, Key],
roles: "OrderedDict[str, DelegatedRole]",
roles: Dict[str, DelegatedRole],
unrecognized_fields: Optional[Mapping[str, Any]] = None,
):
self.keys = keys
Expand All @@ -1233,7 +1232,7 @@ def from_dict(cls, delegations_dict: Dict[str, Any]) -> "Delegations":
for keyid, key_dict in keys.items():
keys_res[keyid] = Key.from_dict(keyid, key_dict)
roles = delegations_dict.pop("roles")
roles_res: "OrderedDict[str, DelegatedRole]" = OrderedDict()
roles_res: Dict[str, DelegatedRole] = {}
for role_dict in roles:
new_role = DelegatedRole.from_dict(role_dict)
if new_role.name in roles_res:
Expand Down