Skip to content

Commit

Permalink
Merge pull request #2278 from fridex/pydocstyle-first-line-period-rebase
Browse files Browse the repository at this point in the history
Fix pydocstyle D400: first line should end with a period
  • Loading branch information
lukpueh authored Jan 26, 2023
2 parents 7f04a6e + 5d347b8 commit a6460c6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion tuf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright New York University and the TUF contributors
# SPDX-License-Identifier: MIT OR Apache-2.0

"""TUF
"""TUF.
"""

# This value is used in the requests user agent.
Expand Down
14 changes: 7 additions & 7 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright New York University and the TUF contributors
# SPDX-License-Identifier: MIT OR Apache-2.0

"""
"""The low-level Metadata API.
The low-level Metadata API in ``tuf.api.metadata`` module contains:
* Safe de/serialization of metadata to and from files.
Expand Down Expand Up @@ -550,13 +551,13 @@ def __eq__(self, other: Any) -> bool:

@abc.abstractmethod
def to_dict(self) -> Dict[str, Any]:
"""Serialize and return a dict representation of self"""
"""Serialize and return a dict representation of self."""
raise NotImplementedError

@classmethod
@abc.abstractmethod
def from_dict(cls, signed_dict: Dict[str, Any]) -> "Signed":
"""Deserialization helper, creates object from json/dict representation"""
"""Deserialization helper, creates object from json/dict representation."""
raise NotImplementedError

@classmethod
Expand Down Expand Up @@ -1003,7 +1004,7 @@ class BaseFile:
def _verify_hashes(
data: Union[bytes, IO[bytes]], expected_hashes: Dict[str, str]
) -> None:
"""Verify that the hash of ``data`` matches ``expected_hashes``"""
"""Verify that the hash of ``data`` matches ``expected_hashes``."""
is_bytes = isinstance(data, bytes)
for algo, exp_hash in expected_hashes.items():
try:
Expand Down Expand Up @@ -1032,7 +1033,7 @@ def _verify_hashes(
def _verify_length(
data: Union[bytes, IO[bytes]], expected_length: int
) -> None:
"""Verify that the length of ``data`` matches ``expected_length``"""
"""Verify that the length of ``data`` matches ``expected_length``."""
if isinstance(data, bytes):
observed_length = len(data)
else:
Expand Down Expand Up @@ -1541,8 +1542,7 @@ def to_dict(self) -> Dict[str, Any]:
}

def get_role_for_target(self, target_filepath: str) -> str:
"""Calculate the name of the delegated role responsible for
``target_filepath``.
"""Calculate the name of the delegated role responsible for ``target_filepath``.
The target at path ``target_filepath`` is assigned to a bin by casting
the left-most ``bit_length`` of bits of the file path hash digest to
Expand Down
2 changes: 1 addition & 1 deletion tuf/ngclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright New York University and the TUF contributors
# SPDX-License-Identifier: MIT OR Apache-2.0

"""TUF client public API
"""TUF client public API.
"""


Expand Down
8 changes: 3 additions & 5 deletions tuf/ngclient/_internal/requests_fetcher.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright 2021, New York University and the TUF contributors
# SPDX-License-Identifier: MIT OR Apache-2.0

"""Provides an implementation of ``FetcherInterface`` using the Requests
HTTP library.
"""Provides an implementation of ``FetcherInterface`` using the Requests HTTP library.
"""

# requests_fetcher is public but comes from _internal for now (because
Expand Down Expand Up @@ -56,7 +55,7 @@ def __init__(self) -> None:
self.chunk_size: int = 400000 # bytes

def _fetch(self, url: str) -> Iterator[bytes]:
"""Fetch the contents of HTTP/HTTPS url from a remote server
"""Fetch the contents of HTTP/HTTPS url from a remote server.
Args:
url: URL string that represents a file location.
Expand Down Expand Up @@ -114,8 +113,7 @@ def _chunks(self, response: "requests.Response") -> Iterator[bytes]:
response.close()

def _get_session(self, url: str) -> requests.Session:
"""Return a different customized requests.Session per schema+hostname
combination.
"""Return a different customized requests.Session per schema+hostname combination.
Raises:
exceptions.DownloadError: When there is a problem parsing the url.
Expand Down
24 changes: 12 additions & 12 deletions tuf/ngclient/_internal/trusted_metadata_set.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright the TUF contributors
# SPDX-License-Identifier: MIT OR Apache-2.0

"""Trusted collection of client-side TUF Metadata
"""Trusted collection of client-side TUF Metadata.
``TrustedMetadataSet`` keeps track of the current valid set of metadata for the
client, and handles almost every step of the "Detailed client workflow" (
Expand Down Expand Up @@ -71,15 +71,15 @@


class TrustedMetadataSet(abc.Mapping):
"""Internal class to keep track of trusted metadata in ``Updater``
"""Internal class to keep track of trusted metadata in ``Updater``.
``TrustedMetadataSet`` ensures that the collection of metadata in it is valid
and trusted through the whole client update workflow. It provides easy ways
to update the metadata with the caller making decisions on what is updated.
"""

def __init__(self, root_data: bytes):
"""Initialize ``TrustedMetadataSet`` by loading trusted root metadata
"""Initialize ``TrustedMetadataSet`` by loading trusted root metadata.
Args:
root_data: Trusted root metadata as bytes. Note that this metadata
Expand All @@ -99,36 +99,36 @@ def __init__(self, root_data: bytes):
self._load_trusted_root(root_data)

def __getitem__(self, role: str) -> Metadata:
"""Return current ``Metadata`` for ``role``"""
"""Return current ``Metadata`` for ``role``."""
return self._trusted_set[role]

def __len__(self) -> int:
"""Return number of ``Metadata`` objects in ``TrustedMetadataSet``"""
"""Return number of ``Metadata`` objects in ``TrustedMetadataSet``."""
return len(self._trusted_set)

def __iter__(self) -> Iterator[Metadata]:
"""Return iterator over ``Metadata`` objects in ``TrustedMetadataSet``"""
"""Return iterator over ``Metadata`` objects in ``TrustedMetadataSet``."""
return iter(self._trusted_set.values())

# Helper properties for top level metadata
@property
def root(self) -> Metadata[Root]:
"""Get current root ``Metadata``"""
"""Get current root ``Metadata``."""
return self._trusted_set[Root.type]

@property
def timestamp(self) -> Metadata[Timestamp]:
"""Get current timestamp ``Metadata``"""
"""Get current timestamp ``Metadata``."""
return self._trusted_set[Timestamp.type]

@property
def snapshot(self) -> Metadata[Snapshot]:
"""Get current snapshot ``Metadata``"""
"""Get current snapshot ``Metadata``."""
return self._trusted_set[Snapshot.type]

@property
def targets(self) -> Metadata[Targets]:
"""Get current top-level targets ``Metadata``"""
"""Get current top-level targets ``Metadata``."""
return self._trusted_set[Targets.type]

# Methods for updating metadata
Expand Down Expand Up @@ -251,7 +251,7 @@ def update_timestamp(self, data: bytes) -> Metadata[Timestamp]:
return new_timestamp

def _check_final_timestamp(self) -> None:
"""Raise if timestamp is expired"""
"""Raise if timestamp is expired."""

if self.timestamp.signed.is_expired(self.reference_time):
raise exceptions.ExpiredMetadataError("timestamp.json is expired")
Expand Down Expand Up @@ -345,7 +345,7 @@ def update_snapshot(
return new_snapshot

def _check_final_snapshot(self) -> None:
"""Raise if snapshot is expired or meta version does not match"""
"""Raise if snapshot is expired or meta version does not match."""

if self.snapshot.signed.is_expired(self.reference_time):
raise exceptions.ExpiredMetadataError("snapshot.json is expired")
Expand Down
2 changes: 1 addition & 1 deletion tuf/ngclient/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2021, New York University and the TUF contributors
# SPDX-License-Identifier: MIT OR Apache-2.0

"""Configuration options for ``Updater`` class
"""Configuration options for ``Updater`` class.
"""

from dataclasses import dataclass
Expand Down
12 changes: 6 additions & 6 deletions tuf/ngclient/updater.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020, New York University and the TUF contributors
# SPDX-License-Identifier: MIT OR Apache-2.0

"""Client update workflow implementation
"""Client update workflow implementation.
The ``Updater`` class provides an implementation of the
`TUF client workflow
Expand Down Expand Up @@ -177,7 +177,7 @@ def find_cached_target(
targetinfo: TargetFile,
filepath: Optional[str] = None,
) -> Optional[str]:
"""Check whether a local file is an up to date target
"""Check whether a local file is an up to date target.
Args:
targetinfo: ``TargetFile`` from ``get_targetinfo()``.
Expand Down Expand Up @@ -266,7 +266,7 @@ def download_target(
def _download_metadata(
self, rolename: str, length: int, version: Optional[int] = None
) -> bytes:
"""Download a metadata file and return it as bytes"""
"""Download a metadata file and return it as bytes."""
encoded_name = parse.quote(rolename, "")
if version is None:
url = f"{self._metadata_base_url}{encoded_name}.json"
Expand Down Expand Up @@ -330,7 +330,7 @@ def _load_root(self) -> None:
break

def _load_timestamp(self) -> None:
"""Load local and remote timestamp metadata"""
"""Load local and remote timestamp metadata."""
try:
data = self._load_local_metadata(Timestamp.type)
self._trusted_set.update_timestamp(data)
Expand All @@ -352,7 +352,7 @@ def _load_timestamp(self) -> None:
self._persist_metadata(Timestamp.type, data)

def _load_snapshot(self) -> None:
"""Load local (and if needed remote) snapshot metadata"""
"""Load local (and if needed remote) snapshot metadata."""
try:
data = self._load_local_metadata(Snapshot.type)
self._trusted_set.update_snapshot(data, trusted=True)
Expand Down Expand Up @@ -483,5 +483,5 @@ def _preorder_depth_first_walk(


def _ensure_trailing_slash(url: str) -> str:
"""Return url guaranteed to end in a slash"""
"""Return url guaranteed to end in a slash."""
return url if url.endswith("/") else f"{url}/"

0 comments on commit a6460c6

Please sign in to comment.