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

feat: remove python-dateutil dependency #221

Merged
merged 3 commits into from
Jun 23, 2023
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
6 changes: 3 additions & 3 deletions hcloud/actions/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain

Expand Down Expand Up @@ -52,8 +52,8 @@ def __init__(

self.status = status
self.progress = progress
self.started = isoparse(started) if started else None
self.finished = isoparse(finished) if finished else None
self.started = datetime.fromisoformat(started) if started else None
self.finished = datetime.fromisoformat(finished) if finished else None
self.resources = resources
self.error = error

Expand Down
12 changes: 8 additions & 4 deletions hcloud/certificates/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain, DomainIdentityMixin

Expand Down Expand Up @@ -59,9 +59,13 @@ def __init__(
self.certificate = certificate
self.domain_names = domain_names
self.fingerprint = fingerprint
self.not_valid_before = isoparse(not_valid_before) if not_valid_before else None
self.not_valid_after = isoparse(not_valid_after) if not_valid_after else None
self.created = isoparse(created) if created else None
self.not_valid_before = (
datetime.fromisoformat(not_valid_before) if not_valid_before else None
)
self.not_valid_after = (
datetime.fromisoformat(not_valid_after) if not_valid_after else None
)
self.created = datetime.fromisoformat(created) if created else None
self.labels = labels
self.status = status

Expand Down
6 changes: 3 additions & 3 deletions hcloud/deprecation/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain

Expand All @@ -25,7 +25,7 @@ def __init__(
announced=None,
unavailable_after=None,
):
self.announced = isoparse(announced) if announced else None
self.announced = datetime.fromisoformat(announced) if announced else None
self.unavailable_after = (
isoparse(unavailable_after) if unavailable_after else None
datetime.fromisoformat(unavailable_after) if unavailable_after else None
)
4 changes: 2 additions & 2 deletions hcloud/firewalls/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain

Expand Down Expand Up @@ -30,7 +30,7 @@ def __init__(
self.rules = rules
self.applied_to = applied_to
self.labels = labels
self.created = isoparse(created) if created else None
self.created = datetime.fromisoformat(created) if created else None


class FirewallRule:
Expand Down
4 changes: 2 additions & 2 deletions hcloud/floating_ips/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain

Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(
self.blocked = blocked
self.protection = protection
self.labels = labels
self.created = isoparse(created) if created else None
self.created = datetime.fromisoformat(created) if created else None
self.name = name


Expand Down
6 changes: 3 additions & 3 deletions hcloud/images/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain, DomainIdentityMixin

Expand Down Expand Up @@ -85,11 +85,11 @@ def __init__(
self.id = id
self.name = name
self.type = type
self.created = isoparse(created) if created else None
self.created = datetime.fromisoformat(created) if created else None
self.description = description
self.image_size = image_size
self.disk_size = disk_size
self.deprecated = isoparse(deprecated) if deprecated else None
self.deprecated = datetime.fromisoformat(deprecated) if deprecated else None
self.bound_to = bound_to
self.os_flavor = os_flavor
self.os_version = os_version
Expand Down
4 changes: 2 additions & 2 deletions hcloud/isos/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain, DomainIdentityMixin

Expand Down Expand Up @@ -36,4 +36,4 @@ def __init__(
self.type = type
self.architecture = architecture
self.description = description
self.deprecated = isoparse(deprecated) if deprecated else None
self.deprecated = datetime.fromisoformat(deprecated) if deprecated else None
4 changes: 2 additions & 2 deletions hcloud/load_balancers/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain

Expand Down Expand Up @@ -76,7 +76,7 @@ def __init__(
):
self.id = id
self.name = name
self.created = isoparse(created) if created else None
self.created = datetime.fromisoformat(created) if created else None
self.public_net = public_net
self.private_net = private_net
self.location = location
Expand Down
4 changes: 2 additions & 2 deletions hcloud/networks/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain

Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(
):
self.id = id
self.name = name
self.created = isoparse(created) if created else None
self.created = datetime.fromisoformat(created) if created else None
self.ip_range = ip_range
self.subnets = subnets
self.routes = routes
Expand Down
4 changes: 2 additions & 2 deletions hcloud/placement_groups/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain

Expand Down Expand Up @@ -35,7 +35,7 @@ def __init__(
self.labels = labels
self.servers = servers
self.type = type
self.created = isoparse(created) if created else None
self.created = datetime.fromisoformat(created) if created else None


class CreatePlacementGroupResponse(BaseDomain):
Expand Down
4 changes: 2 additions & 2 deletions hcloud/primary_ips/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain

Expand Down Expand Up @@ -74,7 +74,7 @@ def __init__(
self.blocked = blocked
self.protection = protection
self.labels = labels
self.created = isoparse(created) if created else None
self.created = datetime.fromisoformat(created) if created else None
self.name = name
self.assignee_id = assignee_id
self.assignee_type = assignee_type
Expand Down
4 changes: 2 additions & 2 deletions hcloud/servers/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain

Expand Down Expand Up @@ -113,7 +113,7 @@ def __init__(
self.id = id
self.name = name
self.status = status
self.created = isoparse(created) if created else None
self.created = datetime.fromisoformat(created) if created else None
self.public_net = public_net
self.server_type = server_type
self.datacenter = datacenter
Expand Down
4 changes: 2 additions & 2 deletions hcloud/ssh_keys/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain, DomainIdentityMixin

Expand Down Expand Up @@ -36,4 +36,4 @@ def __init__(
self.fingerprint = fingerprint
self.public_key = public_key
self.labels = labels
self.created = isoparse(created) if created else None
self.created = datetime.fromisoformat(created) if created else None
4 changes: 2 additions & 2 deletions hcloud/volumes/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dateutil.parser import isoparse
from datetime import datetime

from hcloud.core.domain import BaseDomain, DomainIdentityMixin

Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(
self.id = id
self.name = name
self.server = server
self.created = isoparse(created) if created else None
self.created = datetime.fromisoformat(created) if created else None
self.location = location
self.size = size
self.linux_device = linux_device
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
],
python_requires=">=3.7",
install_requires=[
"python-dateutil>=2.7.5",
"requests>=2.20",
],
extras_require={
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/actions/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

from dateutil.tz import tzoffset
from datetime import timezone

from hcloud.actions.domain import Action

Expand All @@ -11,8 +10,8 @@ def test_started_finished_is_datetime(self):
id=1, started="2016-01-30T23:50+00:00", finished="2016-03-30T23:50+00:00"
)
assert action.started == datetime.datetime(
2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0)
2016, 1, 30, 23, 50, tzinfo=timezone.utc
)
assert action.finished == datetime.datetime(
2016, 3, 30, 23, 50, tzinfo=tzoffset(None, 0)
2016, 3, 30, 23, 50, tzinfo=timezone.utc
)
9 changes: 4 additions & 5 deletions tests/unit/certificates/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

from dateutil.tz import tzoffset
from datetime import timezone

from hcloud.certificates.domain import Certificate

Expand All @@ -14,11 +13,11 @@ def test_created_is_datetime(self):
not_valid_before="2016-01-30T23:50+00:00",
)
assert certificate.created == datetime.datetime(
2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0)
2016, 1, 30, 23, 50, tzinfo=timezone.utc
)
assert certificate.not_valid_after == datetime.datetime(
2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0)
2016, 1, 30, 23, 50, tzinfo=timezone.utc
)
assert certificate.not_valid_before == datetime.datetime(
2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0)
2016, 1, 30, 23, 50, tzinfo=timezone.utc
)
7 changes: 4 additions & 3 deletions tests/unit/core/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime

import pytest
from dateutil.parser import isoparse

from hcloud.core.domain import (
BaseDomain,
Expand Down Expand Up @@ -101,7 +102,7 @@ class ActionDomain(BaseDomain, DomainIdentityMixin):
def __init__(self, id, name="name1", started=None):
self.id = id
self.name = name
self.started = isoparse(started) if started else None
self.started = datetime.fromisoformat(started) if started else None


class TestBaseDomain:
Expand All @@ -125,7 +126,7 @@ class TestBaseDomain:
{
"id": 4,
"name": "name-name3",
"started": isoparse("2016-01-30T23:50+00:00"),
"started": datetime.fromisoformat("2016-01-30T23:50+00:00"),
},
),
],
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/firewalls/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

from dateutil.tz import tzoffset
from datetime import timezone

from hcloud.firewalls.domain import Firewall

Expand All @@ -9,5 +8,5 @@ class TestFirewall:
def test_created_is_datetime(self):
firewall = Firewall(id=1, created="2016-01-30T23:50+00:00")
assert firewall.created == datetime.datetime(
2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0)
2016, 1, 30, 23, 50, tzinfo=timezone.utc
)
5 changes: 2 additions & 3 deletions tests/unit/floating_ips/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

from dateutil.tz import tzoffset
from datetime import timezone

from hcloud.floating_ips.domain import FloatingIP

Expand All @@ -9,5 +8,5 @@ class TestFloatingIP:
def test_created_is_datetime(self):
floatingIP = FloatingIP(id=1, created="2016-01-30T23:50+00:00")
assert floatingIP.created == datetime.datetime(
2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0)
2016, 1, 30, 23, 50, tzinfo=timezone.utc
)
6 changes: 3 additions & 3 deletions tests/unit/images/test_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
from datetime import timezone
from unittest import mock

import pytest
from dateutil.tz import tzoffset

from hcloud.actions.client import BoundAction
from hcloud.images.client import BoundImage, ImagesClient
Expand All @@ -26,14 +26,14 @@ def test_bound_image_init(self, image_response):
assert bound_image.image_size == 2.3
assert bound_image.disk_size == 10
assert bound_image.created == datetime.datetime(
2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0)
2016, 1, 30, 23, 50, tzinfo=timezone.utc
)
assert bound_image.os_flavor == "ubuntu"
assert bound_image.os_version == "16.04"
assert bound_image.architecture == "x86"
assert bound_image.rapid_deploy is False
assert bound_image.deprecated == datetime.datetime(
2018, 2, 28, 0, 0, tzinfo=tzoffset(None, 0)
2018, 2, 28, 0, 0, tzinfo=timezone.utc
)

assert isinstance(bound_image.created_from, BoundServer)
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/images/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

from dateutil.tz import tzoffset
from datetime import timezone

from hcloud.images.domain import Image

Expand All @@ -9,5 +8,5 @@ class TestImage:
def test_created_is_datetime(self):
image = Image(id=1, created="2016-01-30T23:50+00:00")
assert image.created == datetime.datetime(
2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0)
2016, 1, 30, 23, 50, tzinfo=timezone.utc
)
4 changes: 2 additions & 2 deletions tests/unit/isos/test_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
from datetime import timezone
from unittest import mock

import pytest
from dateutil.tz import tzoffset

from hcloud.isos.client import BoundIso, IsosClient

Expand All @@ -21,7 +21,7 @@ def test_bound_iso_init(self, iso_response):
assert bound_iso.type == "public"
assert bound_iso.architecture == "x86"
assert bound_iso.deprecated == datetime.datetime(
2018, 2, 28, 0, 0, tzinfo=tzoffset(None, 0)
2018, 2, 28, 0, 0, tzinfo=timezone.utc
)


Expand Down
Loading