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

Remove dependency on pytz #363

Merged
merged 1 commit into from
Dec 19, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This project should more or less adhere to [Semantic Versioning](https://semver.
## [x.x.x] - unreleased

* Initial work at integrating typing information. Details in https://github.com/python-caldav/caldav/pull/358
* Remove dependency on pytz. Details in https://github.com/python-caldav/caldav/issues/231

## [1.3.9] - 2023-12-12

Expand Down
17 changes: 4 additions & 13 deletions caldav/elements/cdav.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,17 @@
# -*- encoding: utf-8 -*-
import logging
from datetime import datetime
from datetime import timezone
from typing import ClassVar
from typing import Optional

from caldav.lib.namespace import ns

from .base import BaseElement
from .base import NamedBaseElement
from .base import ValuedBaseElement

try:
from datetime import timezone

utc_tz = timezone.utc
except:
## pytz is deprecated - but as of 2021-11, the icalendar library is only
## compatible with pytz (see https://github.com/collective/icalendar/issues/333 https://github.com/collective/icalendar/issues/335 https://github.com/collective/icalendar/issues/336)
import pytz

utc_tz = pytz.utc

from caldav.lib.namespace import ns
from .base import BaseElement, NamedBaseElement, ValuedBaseElement
utc_tz = timezone.utc


def _to_utc_date_string(ts):
Expand Down
7 changes: 4 additions & 3 deletions examples/scheduling_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import uuid
from datetime import datetime
from datetime import timedelta
from datetime import timezone

import pytz
from caldav import DAVClient
from caldav import error
from icalendar import Calendar
from icalendar import Event


###############
### SETUP START
### rfc6638_users should be a list with three dicts containing credential details.
Expand Down Expand Up @@ -218,8 +219,8 @@ def cleanup(self, calendar_name):

pdb.set_trace()
some_data_returned = organizer.principal.freebusy_request(
dtstart=datetime.now().astimezone(pytz.utc) + timedelta(days=399),
dtend=datetime.now().astimezone(pytz.utc) + timedelta(days=399, hours=1),
dtstart=datetime.now().astimezone(timezone.utc) + timedelta(days=399),
dtend=datetime.now().astimezone(timezone.utc) + timedelta(days=399, hours=1),
attendees=[attendee1.principal, attendee2.principal],
)

Expand Down
32 changes: 6 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,20 @@
)

if __name__ == "__main__":
## For python 2.7 and 3.5 we depend on pytz and tzlocal. For 3.6 and up, batteries are included. Same with mock. (But unfortunately the icalendar library only support pytz timezones, so we'll keep pytz around for a bit longer).
try:
import datetime
from datetime import timezone

datetime.datetime.now().astimezone(timezone.utc)
extra_packages = []
## line below can be removed when https://github.com/collective/icalendar/issues/333 is fixed
extra_packages = ["pytz", "tzlocal"]
except:
extra_packages = ["pytz", "tzlocal"]
try:
from unittest.mock import MagicMock

extra_test_packages = []
except:
extra_test_packages = ["mock"]

## TODO: consider if automated testing with radicale in addition to
## xandikos would yield any benefits.
test_packages = [
"pytest",
"pytest-coverage",
"coverage",
"sphinx",
"backports.zoneinfo;python_version<'3.9'",
"tzlocal",
"xandikos==0.2.8;python_version<'3.9'",
"dulwich==0.20.50;python_version<'3.9'",
"xandikos;python_version>='3.9'",
]

if sys.version_info.major == 3 and sys.version_info.minor < 9:
test_packages.append("xandikos==0.2.8")
test_packages.append("dulwich==0.20.50")
else:
test_packages.append("xandikos")

setup(
name="caldav",
version=version,
Expand Down Expand Up @@ -90,8 +71,7 @@
"icalendar",
"recurring-ical-events>=2.0.0",
"typing_extensions",
]
+ extra_packages,
],
extras_require={
"test": test_packages,
},
Expand Down
14 changes: 9 additions & 5 deletions tests/test_cdav.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import datetime

import pytz
import tzlocal
from caldav.elements.cdav import _to_utc_date_string
from caldav.elements.cdav import CalendarQuery

SOMEWHERE_REMOTE = pytz.timezone("Brazil/DeNoronha") # UTC-2 and no DST
try:
import zoneinfo
except ImportError:
from backports import zoneinfo

SOMEWHERE_REMOTE = zoneinfo.ZoneInfo("Brazil/DeNoronha") # UTC-2 and no DST


def test_element():
Expand All @@ -32,9 +36,9 @@ def test_to_utc_date_string_utc():
assert res == "20190514T211023Z"


def test_to_utc_date_string_dt_with_pytz_tzinfo():
input = datetime.datetime(2019, 5, 14, 21, 10, 23, 23)
res = _to_utc_date_string(SOMEWHERE_REMOTE.localize(input))
def test_to_utc_date_string_dt_with_zoneinfo_tzinfo():
input = datetime.datetime(2019, 5, 14, 21, 10, 23, 23, tzinfo=SOMEWHERE_REMOTE)
res = _to_utc_date_string(input)
assert res == "20190514T231023Z"


Expand Down
6 changes: 2 additions & 4 deletions tests/test_vcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
import uuid
from datetime import datetime
from datetime import timedelta
from datetime import timezone
from unittest import TestCase

import icalendar
import pytest
import pytz
import vobject
from caldav.lib import vcal
from caldav.lib.python_utilities import to_normal_str
from caldav.lib.python_utilities import to_wire
from caldav.lib.vcal import create_ical
from caldav.lib.vcal import fix

# from datetime import timezone
# utc = timezone.utc
utc = pytz.utc
utc = timezone.utc

# example from http://www.rfc-editor.org/rfc/rfc5545.txt
ev = """BEGIN:VCALENDAR
Expand Down
Loading