From fa57a9b8bfbc417855411bd40008d0807b6adb72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 17 Sep 2023 15:26:27 +0300 Subject: [PATCH 1/4] Remove dependency on pytz --- poetry.lock | 22 ---------------------- pyproject.toml | 2 -- simplipy/util/dt.py | 8 +++----- tests/system/test_v3.py | 7 +++---- tests/test_websocket.py | 5 ++--- 5 files changed, 8 insertions(+), 36 deletions(-) diff --git a/poetry.lock b/poetry.lock index 5ac0a090..f4542a2d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1416,17 +1416,6 @@ pytest = ">=4.6" [package.extras] testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtualenv"] -[[package]] -name = "pytz" -version = "2023.3.post1" -description = "World timezone definitions, modern and historical" -optional = false -python-versions = "*" -files = [ - {file = "pytz-2023.3.post1-py2.py3-none-any.whl", hash = "sha256:ce42d816b81b68506614c11e8937d3aa9e41007ceb50bfdcb0749b921bf646c7"}, - {file = "pytz-2023.3.post1.tar.gz", hash = "sha256:7b4fddbeb94a1eba4b557da24f19fdf9db575192544270a9101d8509f9f43d7b"}, -] - [[package]] name = "pyupgrade" version = "3.10.1" @@ -1931,17 +1920,6 @@ files = [ {file = "tomlkit-0.12.1.tar.gz", hash = "sha256:38e1ff8edb991273ec9f6181244a6a391ac30e9f5098e7535640ea6be97a7c86"}, ] -[[package]] -name = "types-pytz" -version = "2023.3.0.1" -description = "Typing stubs for pytz" -optional = false -python-versions = "*" -files = [ - {file = "types-pytz-2023.3.0.1.tar.gz", hash = "sha256:1a7b8d4aac70981cfa24478a41eadfcd96a087c986d6f150d77e3ceb3c2bdfab"}, - {file = "types_pytz-2023.3.0.1-py3-none-any.whl", hash = "sha256:65152e872137926bb67a8fe6cc9cfd794365df86650c5d5fdc7b167b0f38892e"}, -] - [[package]] name = "typing-extensions" version = "4.7.1" diff --git a/pyproject.toml b/pyproject.toml index 6eb38075..977184da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,6 @@ backoff = ">=1.11.1" beautifulsoup4 = ">=4.11.1" certifi = ">=2023.07.22" python = "^3.9.0" -pytz = ">=2019.3" voluptuous = ">=0.11.7" websockets = ">=8.1" @@ -96,7 +95,6 @@ requests = ">=2.31.0" ruff = ">=0.0.261,<0.0.290" safety = "^2.3.1" sphinx-rtd-theme = "^1.0.0" -types-pytz = ">=2022.1,<2024.0" vulture = "^2.6" yamllint = "^1.28.0" diff --git a/simplipy/util/dt.py b/simplipy/util/dt.py index 3952efa6..969050fc 100644 --- a/simplipy/util/dt.py +++ b/simplipy/util/dt.py @@ -1,9 +1,7 @@ """Define datetime utilities.""" -from datetime import datetime +from datetime import datetime, timezone -import pytz - -UTC = pytz.utc +UTC = timezone.utc def utc_from_timestamp(timestamp: float) -> datetime: @@ -15,4 +13,4 @@ def utc_from_timestamp(timestamp: float) -> datetime: Returns: A parsed ``datetime.datetime`` object. """ - return UTC.localize(datetime.utcfromtimestamp(timestamp)) + return datetime.fromtimestamp(timestamp, tz=UTC) diff --git a/tests/system/test_v3.py b/tests/system/test_v3.py index 1a82bfd4..0bfd055a 100644 --- a/tests/system/test_v3.py +++ b/tests/system/test_v3.py @@ -1,13 +1,12 @@ """Define tests for v3 System objects.""" # pylint: disable=too-many-lines import logging -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from typing import Any, cast from unittest.mock import Mock import aiohttp import pytest -import pytz from aresponses import ResponsesMockServer from simplipy import API @@ -54,7 +53,7 @@ async def test_as_dict( "category": "error", "code": "2000", "timestamp": 1581823228, - "received_dt": datetime(2020, 2, 16, 3, 20, 28, tzinfo=pytz.UTC), + "received_dt": datetime(2020, 2, 16, 3, 20, 28, tzinfo=timezone.utc), "link": "http://link.to.info", "link_label": "More Info", } @@ -1680,7 +1679,7 @@ async def test_system_notifications( assert notification1.category == "error" assert notification1.code == "2000" assert notification1.received_dt == datetime( - 2020, 2, 16, 3, 20, 28, tzinfo=pytz.UTC + 2020, 2, 16, 3, 20, 28, tzinfo=timezone.utc ) assert notification1.link == "http://link.to.info" assert notification1.link_label == "More Info" diff --git a/tests/test_websocket.py b/tests/test_websocket.py index 6ab40778..5e27259c 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -4,13 +4,12 @@ import asyncio import logging from collections import deque -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from time import time from typing import Any from unittest.mock import AsyncMock, Mock import pytest -import pytz from aiohttp.client_exceptions import ( ClientError, ServerDisconnectedError, @@ -142,7 +141,7 @@ def test_create_event(ws_message_event: dict[str, Any]) -> None: assert event.event_type == EVENT_DISARMED_BY_MASTER_PIN assert event.info == "System Disarmed by Master PIN" assert event.system_id == 12345 - assert event.timestamp == datetime(2021, 9, 29, 23, 14, 46, tzinfo=pytz.UTC) + assert event.timestamp == datetime(2021, 9, 29, 23, 14, 46, tzinfo=timezone.utc) assert event.changed_by == "Master PIN" assert event.sensor_name == "" assert event.sensor_serial == "abcdef12" From 113950fffa24c4c623c26580e7d9877511d5ef26 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Mon, 18 Sep 2023 12:16:21 -0600 Subject: [PATCH 2/4] Simplify --- simplipy/util/dt.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/simplipy/util/dt.py b/simplipy/util/dt.py index 969050fc..b1aca5bc 100644 --- a/simplipy/util/dt.py +++ b/simplipy/util/dt.py @@ -1,8 +1,6 @@ """Define datetime utilities.""" from datetime import datetime, timezone -UTC = timezone.utc - def utc_from_timestamp(timestamp: float) -> datetime: """Return a UTC time from a timestamp. @@ -13,4 +11,4 @@ def utc_from_timestamp(timestamp: float) -> datetime: Returns: A parsed ``datetime.datetime`` object. """ - return datetime.fromtimestamp(timestamp, tz=UTC) + return datetime.fromtimestamp(timestamp, tz=timezone.utc) From 49e1ee45635384515d40db035b37c50ffde33f44 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Mon, 18 Sep 2023 12:19:13 -0600 Subject: [PATCH 3/4] Fix CI --- tests/system/test_v3.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/system/test_v3.py b/tests/system/test_v3.py index 0bfd055a..f0bb5ad3 100644 --- a/tests/system/test_v3.py +++ b/tests/system/test_v3.py @@ -53,7 +53,9 @@ async def test_as_dict( "category": "error", "code": "2000", "timestamp": 1581823228, - "received_dt": datetime(2020, 2, 16, 3, 20, 28, tzinfo=timezone.utc), + "received_dt": datetime( + 2020, 2, 16, 3, 20, 28, tzinfo=timezone.utc + ), "link": "http://link.to.info", "link_label": "More Info", } From f984d4bb5b6ab2ad327b051488e9544d4aa51c51 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Mon, 18 Sep 2023 12:21:39 -0600 Subject: [PATCH 4/4] Update lock --- poetry.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 4c5f8bb7..749e1d95 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. [[package]] name = "aiohttp" @@ -2279,4 +2279,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.9.0" -content-hash = "d35e0e77b183d7b0556f7d5ddabdee0b3c4eb018c972bbde482a5823e28e0092" +content-hash = "df73244dd3ef6061831a1d69f5ae7adbcb67225711da653f3a66fcc8800bc33c"