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

Metadata API: remove dateutil requirement #1726

Merged
merged 1 commit into from
Dec 14, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# pinned tuf runtime dependencies (should auto-update and -trigger ci/cd)
-r requirements-pinned.txt

# tuf.api tests use python-dateutil
python-dateutil

# additional test tools for linting and coverage measurement
coverage
black
Expand All @@ -14,4 +11,3 @@ pylint
mypy
bandit
types-requests
types-python-dateutil
10 changes: 0 additions & 10 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from datetime import datetime, timedelta
from typing import ClassVar, Dict

from dateutil.relativedelta import relativedelta
from securesystemslib import hash as sslib_hash
from securesystemslib.interface import (
import_ed25519_privatekey_from_file,
Expand Down Expand Up @@ -333,15 +332,6 @@ def test_metadata_timestamp(self) -> None:
timestamp.signed.bump_expiration(timedelta(days=365))
self.assertEqual(timestamp.signed.expires, datetime(2031, 1, 2, 0, 0))

# Test whether dateutil.relativedelta works, this provides a much
# easier to use interface for callers
delta = relativedelta(days=1)
timestamp.signed.bump_expiration(delta)
self.assertEqual(timestamp.signed.expires, datetime(2031, 1, 3, 0, 0))
delta = relativedelta(years=5)
timestamp.signed.bump_expiration(delta)
self.assertEqual(timestamp.signed.expires, datetime(2036, 1, 3, 0, 0))

Comment on lines -336 to -344
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test code is removed as if we don't make timedelta argument of Signed a Union[timedelta, relativedelta] then mypy complains.

# Create a MetaFile instance representing what we expect
# the updated data to be.
hashes = {
Expand Down
5 changes: 1 addition & 4 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
cast,
)

from dateutil.relativedelta import relativedelta
from securesystemslib import exceptions as sslib_exceptions
from securesystemslib import hash as sslib_hash
from securesystemslib import keys as sslib_keys
Expand Down Expand Up @@ -501,9 +500,7 @@ def is_expired(self, reference_time: Optional[datetime] = None) -> bool:
return reference_time >= self.expires

# Modification.
def bump_expiration(
self, delta: Union[timedelta, relativedelta] = timedelta(days=1)
) -> None:
def bump_expiration(self, delta: timedelta = timedelta(days=1)) -> None:
"""Increments the expires attribute by the passed timedelta."""
self.expires += delta

Expand Down