summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-04-17 11:26:01 +0000
committerGerrit Code Review <review@openstack.org>2023-04-17 11:26:01 +0000
commitadfd830d44419548a8fc79925cd24c8109549e54 (patch)
tree84a380b5e301ea53adb32aef1dc6a5f9c9bcabec
parent9ffd4e59d715d3577e221d093cdcf97a806c0182 (diff)
parenta326ec5eea86d7458953a229b4dbd887595f68f1 (diff)
downloadoslo-serialization-adfd830d44419548a8fc79925cd24c8109549e54.tar.gz
Merge "Implement zoneinfo support to drop dependency to pytz"
-rw-r--r--oslo_serialization/msgpackutils.py10
-rw-r--r--oslo_serialization/tests/test_msgpackutils.py16
-rw-r--r--releasenotes/notes/implement-zoneinfo-to-remove-pytz-c136b33bbfbfe59f.yaml6
-rw-r--r--requirements.txt2
4 files changed, 21 insertions, 13 deletions
diff --git a/oslo_serialization/msgpackutils.py b/oslo_serialization/msgpackutils.py
index ff7b267..01003bf 100644
--- a/oslo_serialization/msgpackutils.py
+++ b/oslo_serialization/msgpackutils.py
@@ -33,10 +33,10 @@ import functools
import itertools
import uuid
from xmlrpc import client as xmlrpclib
+import zoneinfo
import msgpack
from oslo_utils import importutils
-from pytz import timezone
netaddr = importutils.try_import("netaddr")
@@ -236,7 +236,7 @@ class DateTimeHandler(object):
'microsecond': dt.microsecond,
}
if dt.tzinfo:
- tz = dt.tzinfo.tzname(None)
+ tz = str(dt.tzinfo)
dct['tz'] = tz
return dumps(dct, registry=self._registry)
@@ -263,9 +263,9 @@ class DateTimeHandler(object):
minute=dct['minute'],
second=dct['second'],
microsecond=dct['microsecond'])
- if 'tz' in dct:
- tzinfo = timezone(dct['tz'])
- dt = tzinfo.localize(dt)
+ if 'tz' in dct and dct['tz']:
+ tzinfo = zoneinfo.ZoneInfo(dct['tz'])
+ dt = dt.replace(tzinfo=tzinfo)
return dt
diff --git a/oslo_serialization/tests/test_msgpackutils.py b/oslo_serialization/tests/test_msgpackutils.py
index a8a91e9..3acc70d 100644
--- a/oslo_serialization/tests/test_msgpackutils.py
+++ b/oslo_serialization/tests/test_msgpackutils.py
@@ -15,10 +15,10 @@
import datetime
import itertools
from xmlrpc import client as xmlrpclib
+import zoneinfo
import netaddr
from oslotest import base as test_base
-from pytz import timezone
from oslo_serialization import msgpackutils
from oslo_utils import uuidutils
@@ -145,20 +145,22 @@ class MsgPackUtilsTest(test_base.BaseTestCase):
self.assertEqual(today, _dumps_loads(today))
def test_datetime_tz_clone(self):
- eastern = timezone('US/Eastern')
+ eastern = zoneinfo.ZoneInfo('US/Eastern')
now = datetime.datetime.now()
- e_dt = eastern.localize(now)
+ e_dt = now.replace(tzinfo=eastern)
e_dt2 = _dumps_loads(e_dt)
self.assertEqual(e_dt, e_dt2)
self.assertEqual(e_dt.strftime(_TZ_FMT), e_dt2.strftime(_TZ_FMT))
def test_datetime_tz_different(self):
- eastern = timezone('US/Eastern')
- pacific = timezone('US/Pacific')
+ eastern = zoneinfo.ZoneInfo('US/Eastern')
+ pacific = zoneinfo.ZoneInfo('US/Pacific')
now = datetime.datetime.now()
- e_dt = eastern.localize(now)
- p_dt = pacific.localize(now)
+ now = now.replace(tzinfo=eastern)
+ e_dt = now
+ now = now.replace(tzinfo=pacific)
+ p_dt = now
self.assertNotEqual(e_dt, p_dt)
self.assertNotEqual(e_dt.strftime(_TZ_FMT), p_dt.strftime(_TZ_FMT))
diff --git a/releasenotes/notes/implement-zoneinfo-to-remove-pytz-c136b33bbfbfe59f.yaml b/releasenotes/notes/implement-zoneinfo-to-remove-pytz-c136b33bbfbfe59f.yaml
new file mode 100644
index 0000000..24c7d7f
--- /dev/null
+++ b/releasenotes/notes/implement-zoneinfo-to-remove-pytz-c136b33bbfbfe59f.yaml
@@ -0,0 +1,6 @@
+---
+other:
+ - |
+ Implement zoneinfo to allow us to remove pytz's dependency. zoneinfo
+ was introduced by python 3.9, and the series 2023.2 (bobcat) set py39
+ as the minimal supported runtime, so we are able to remove pytz.
diff --git a/requirements.txt b/requirements.txt
index d8c62c4..d31beef 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -10,4 +10,4 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0
msgpack>=0.5.2 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0
-pytz>=2013.6 # MIT
+tzdata>=2022.4 # MIT