Skip to content

Commit

Permalink
Remove pytz dependency (#10)
Browse files Browse the repository at this point in the history
* Remove pytz dependency

`datetime.timezone.utc` exists since at least 3.5, so guaranteed to be in 3.7

Also removed `dateutil.parser` from tests in favor of direct datetime creation (tried to remove whole dateutil, but `datetime.fromisoformat` isn't good enough, and dragging in `ciso8601` is a bit of overkill.
  • Loading branch information
dmaone authored Oct 11, 2021
1 parent 52f1963 commit 0630f8d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All major changes in each released version of the archfx-cloud plugin are listed here.

## 0.13.0

- Removed unneed pytz dependency

## 0.12.0

- Support `ArchFXFlexibleDictionaryReport` direct upload
Expand Down
3 changes: 1 addition & 2 deletions archfx_cloud/reports/flexible_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import datetime
from io import BytesIO
from typing import List, Union
import pytz
import msgpack
from ..utils.slugs import ArchFxDeviceSlug
from .exceptions import DataError
Expand Down Expand Up @@ -135,7 +134,7 @@ def _encode_datetime(obj):
"""Pack a datetime into an isoformat string."""
if isinstance(obj, datetime.datetime):
if obj.tzinfo:
obj = obj.astimezone(pytz.timezone('UTC'))
obj = obj.astimezone(datetime.timezone.utc)
dt_str = obj.isoformat()
if dt_str[-6] in ['-', '+']:
return dt_str
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
install_requires=[
'requests>=2.21.0',
'python-dateutil',
'pytz',
'msgpack>=1.0.2,<1.1',
'typedargs>=1.1.2,<2',
],
Expand Down
9 changes: 4 additions & 5 deletions tests/test_flexible_report.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime, timezone
import unittest

import dateutil.parser
import msgpack
import requests_mock

Expand Down Expand Up @@ -90,7 +89,7 @@ def test_report_usage(self):
events = []

reading = ArchFXDataPoint(
timestamp=dateutil.parser.parse('2021-01-20T00:00:00.100000Z'),
timestamp=datetime(2021, 1, 20, 0, 0, 0, 100000, timezone.utc),
stream='0001-5030',
value=2.0,
summary_data={'foo': 5, 'bar': 'foobar'},
Expand All @@ -99,22 +98,22 @@ def test_report_usage(self):
)
events.append(reading)
reading = ArchFXDataPoint(
timestamp=dateutil.parser.parse('2021-01-20T00:00:00.200000+00:00'),
timestamp=datetime(2021, 1, 20, 0, 0, 0, 200000, timezone.utc),
stream=0x15030,
value=3.0,
summary_data={'foo': 6, 'bar': 'foobar'},
reading_id=1001
)
events.append(reading)
reading = ArchFXDataPoint(
timestamp=dateutil.parser.parse('2021-01-20T00:00:00.200000+00:00'),
timestamp=datetime(2021, 1, 20, 0, 0, 0, 200000, timezone.utc),
stream='5051',
value=1.0,
reading_id=1002
)
events.append(reading)

sent_time = dateutil.parser.parse('2021-01-20T00:00:00.300000Z')
sent_time = datetime(2021, 1, 20, 0, 0, 0, 300000, timezone.utc)
report = ArchFXFlexibleDictionaryReport.FromReadings(
device='d--1234',
data=events,
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.12.0'
version = '0.13.0'

0 comments on commit 0630f8d

Please sign in to comment.