Remove pytz dependency in favor of dateutil.tz

This commit is contained in:
s3lph 2019-11-18 21:46:41 +01:00
parent afd4710c44
commit e29ef0ff2c
4 changed files with 17 additions and 14 deletions

View file

@ -57,7 +57,7 @@ build_debian:
Section: web
Priority: optional
Architecture: all
Depends: python3 (>= 3.7), python3-jinja2, python3-bottle, python3-dateutil, python3-icalendar, python3-isodate, python3-tz
Depends: python3 (>= 3.7), python3-jinja2, python3-bottle, python3-dateutil, python3-icalendar, python3-isodate
Description: Scrape iCalendar endpoints and present their data in a
timeseries format. A small service that scrapes iCalendar files
served over HTTP, parses their contents and returns a timeseries

View file

@ -8,9 +8,10 @@ import urllib.request
import sys
import logging
import pytz
import jinja2
from isodate import Duration, parse_duration
from dateutil import tz
from datetime import tzinfo
from icalendar_timeseries_server import __version__
@ -93,7 +94,7 @@ class Config:
config = dict()
self._addr: str = _keycheck('addr', config, str, '', default_value='127.0.0.1')
self._port: int = _keycheck('port', config, int, '', default_value=8090)
self._tz: pytz.tzinfo = _parse_timezone('tz', config, '', default_value='UTC')
self._tz: tzinfo = _parse_timezone('tz', config, '', default_value='UTC')
self._start_delta: Duration = _parse_timedelta('start_delta', config, '', default_value='PT')
self._end_delta: Duration = _parse_timedelta('end_delta', config, '', default_value='P30D')
self._calendars: Dict[str, CalendarConfig] = self._parse_calendars_config('calendars', config, '')
@ -120,7 +121,7 @@ class Config:
return self._port
@property
def tz(self) -> pytz.tzinfo:
def tz(self) -> tzinfo:
return self._tz
@property
@ -185,7 +186,10 @@ def _parse_timezone(key: str,
path: str,
default_value: Any = None) -> Any:
zonename: str = _keycheck(key, config, str, path, default_value=default_value)
return pytz.timezone(zonename)
zone: zoneinfo = tz.gettz(zonename)
if zone is None:
raise ValueError(f'Unknown timezone: {zonename}')
return zone
def _parse_key_replace(key: str,

View file

@ -2,9 +2,9 @@
import unittest
import json
import pytz
from datetime import timedelta
from datetime import timedelta, tzinfo
from dateutil import tz
from isodate.duration import Duration
from icalendar_timeseries_server.config import _keycheck, _parse_timedelta, _parse_timezone, Config
@ -113,10 +113,10 @@ class ConfigTest(unittest.TestCase):
'tz': 'Europe/Zurich',
'notz': 'North/Winterfell'
}
self.assertEqual(_parse_timezone('tz', config, ''), pytz.timezone('Europe/Zurich'))
self.assertEqual(_parse_timezone('tz', config, ''), tz.gettz('Europe/Zurich'))
self.assertEqual(_parse_timezone('def', config, '', default_value='Europe/Berlin'),
pytz.timezone('Europe/Berlin'))
with self.assertRaises(pytz.exceptions.UnknownTimeZoneError):
tz.gettz('Europe/Berlin'))
with self.assertRaises(ValueError):
_parse_timezone('notz', config, '')
def test_parse_full_config_valid(self):
@ -125,7 +125,7 @@ class ConfigTest(unittest.TestCase):
self.assertEqual(config.port, 8090)
self.assertEqual(config.start_delta, Duration(hours=-3))
self.assertEqual(config.end_delta, Duration(days=30))
self.assertEqual(config.tz, pytz.timezone('Europe/Zurich'))
self.assertEqual(config.tz, tz.gettz('Europe/Zurich'))
def test_parse_calendars(self):
config = Config(json.loads(_CONFIG_VALID))

View file

@ -18,11 +18,10 @@ setup(
python_requires='>=3.6',
install_requires=[
'bottle',
'python-dateutil',
'python-dateutil>=2.8',
'icalendar',
'isodate',
'jinja2',
'pytz'
'jinja2'
],
entry_points={
'console_scripts': [