From 784a2f22d18829f5053b8bcddcaa46687e638d2c Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Tue, 5 Nov 2024 22:41:55 +0100 Subject: [PATCH] allow strings instead of sequences as input for sort_keys in search. Updates https://github.com/python-caldav/caldav/issues/448 --- CHANGELOG.md | 9 ++++----- RELEASE-HOWTO.md | 3 ++- caldav/objects.py | 3 +++ tests/test_caldav.py | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c81ae341..96adc502 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,8 @@ This project should more or less adhere to [Semantic Versioning](https://semver. ## [1.4.0] - 2024-11-05 -* Georges Toth (github @sim0nx) did a lot of efforts lifting up the project to more modern standards, @smurfix and ArtemIsmagilov has also done quite some efforts cleaning up old code -* A hook for collecting debug information has been in the pull request queue for ages. I've decided to include it in 1.4.0. -* Many other fixes, improvements and some few changes, see below. +* Lots of work lifting the project up to more modern standards and improving code, thanks to Georges Toth (github @sim0nx), Matthias Urlichs (github @smurfix) and @ArtemIsmagilov. While this shouldn't matter for existing users, it will make the library more future-proof. +* Quite long lists of fixes, improvements and some few changes, nothing big, main focus is on ensuring compatibility with as many server implementations as possible. See below. ### Fixed @@ -30,7 +29,7 @@ This project should more or less adhere to [Semantic Versioning](https://semver. * There were some compatibility-logic loading objects if the server does not deliver icalendar data (as it's suppsoed to do according to the RFC), but only if passing the `expand`-flag to the `search`-method. Fixed that it loads regardless of weather `expand` is set or not. Also in https://github.com/python-caldav/caldav/pull/366 * Tests - lots of work getting as much test code as possible to pass on different servers, and now testing also for Python 3.12 - ref https://github.com/python-caldav/caldav/pull/368 https://github.com/python-caldav/caldav/issues/360 https://github.com/python-caldav/caldav/pull/447 https://github.com/python-caldav/caldav/pull/369 https://github.com/python-caldav/caldav/pull/370 https://github.com/python-caldav/caldav/pull/441 https://github.com/python-caldav/caldav/pull/443a * The vcal fixup method was converting implicit dates into timestamps in the COMPLETED property, as it should be a timestamp according to the RFC - however, the regexp failed on explicit dates. Now it will take explicit dates too. https://github.com/python-caldav/caldav/pull/387 -* Code cleanups and modernizing the code - https://github.com/python-caldav/caldav/pull/404 https://github.com/python-caldav/caldav/pull/405 https://github.com/python-caldav/caldav/pull/406 https://github.com/python-caldav/caldav/pull/407 https://github.com/python-caldav/caldav/pull/408 https://github.com/python-caldav/caldav/pull/409 https://github.com/python-caldav/caldav/pull/412 https://github.com/python-caldav/caldav/pull/414 https://github.com/python-caldav/caldav/pull/415 https://github.com/python-caldav/caldav/pull/418 https://github.com/python-caldav/caldav/pull/419 https://github.com/python-caldav/caldav/pull/417 https://github.com/python-caldav/caldav/pull/421 https://github.com/python-caldav/caldav/pull/423 https://github.com/python-caldav/caldav/pull/430 https://github.com/python-caldav/caldav/pull/431 https://github.com/python-caldav/caldav/pull/440 +* Code cleanups and modernizing the code - https://github.com/python-caldav/caldav/pull/404 https://github.com/python-caldav/caldav/pull/405 https://github.com/python-caldav/caldav/pull/406 https://github.com/python-caldav/caldav/pull/407 https://github.com/python-caldav/caldav/pull/408 https://github.com/python-caldav/caldav/pull/409 https://github.com/python-caldav/caldav/pull/412 https://github.com/python-caldav/caldav/pull/414 https://github.com/python-caldav/caldav/pull/415 https://github.com/python-caldav/caldav/pull/418 https://github.com/python-caldav/caldav/pull/419 https://github.com/python-caldav/caldav/pull/417 https://github.com/python-caldav/caldav/pull/421 https://github.com/python-caldav/caldav/pull/423 https://github.com/python-caldav/caldav/pull/430 https://github.com/python-caldav/caldav/pull/431 https://github.com/python-caldav/caldav/pull/440 https://github.com/python-caldav/caldav/pull/365 * Doc - improved examples, https://github.com/python-caldav/caldav/pull/427 * Purelymail sends absolute URLs, which is allowed by the RFC but was not supported by the library. Fixed in https://github.com/python-caldav/caldav/pull/442 @@ -44,7 +43,7 @@ This project should more or less adhere to [Semantic Versioning](https://semver. ### Added * Allow to reverse the sorting order on search function by @twissell- in https://github.com/python-caldav/caldav/pull/433 -* Work on integrating typing information. Details in https://github.com/python-caldav/caldav/pull/358 +* Work on integrating typing information. Details in https://github.com/python-caldav/caldav/pull/358ppp * Remove dependency on pytz. Details in https://github.com/python-caldav/caldav/issues/231 and https://github.com/python-caldav/caldav/pull/363 * Use setuptools-scm / pyproject.toml (modern packaging). Details in https://github.com/python-caldav/caldav/pull/364 and https://github.com/python-caldav/caldav/pull/367 * Debugging tool - an environment variable can be set, causing the library to spew out server communications into files under /tmp. Details in https://github.com/python-caldav/caldav/pull/249 and https://github.com/python-caldav/caldav/issues/248 diff --git a/RELEASE-HOWTO.md b/RELEASE-HOWTO.md index 05482bb0..79d59841 100644 --- a/RELEASE-HOWTO.md +++ b/RELEASE-HOWTO.md @@ -15,7 +15,8 @@ I have no clue on the proper procedures for doing releases, and I keep on doing * For minor and major releases, look through the github issues, anything urgent there that should be fixed prior to doing a new release? * Write up some release notes. (I typically keep a short summary of the changes in the CHANGELOG, and use that as the release notes). * Verify that we're on the right branch - `git checkout master`. (`master` may not always be right - sometimes we may want to use a dedicated branch connected to the release-series, i.e. `v1.3`) -* Commit the changes (typically `CHANGELOG.md`, `__init__.py`, documentation): `git commit -am "preparing for releasing v${VERSION}` +* Set the variable `VERSION=1.4.0` +* Commit the changes (typically `CHANGELOG.md`, perhaps documentation): `git commit -am "preparing for releasing v${VERSION}"` * Create a tag: `git tag -as v${VERSION}` - use the release notes in the tag message. * Make a clone: `git clone caldav/ caldav-release ; cd caldav-release ; git checkout v${VERSION}` * Run tests (particularly the style check): `pytest` and `tox -e style`. diff --git a/caldav/objects.py b/caldav/objects.py index ce8b67fd..13cc7408 100644 --- a/caldav/objects.py +++ b/caldav/objects.py @@ -1311,6 +1311,7 @@ def sort_key_func(x): > datetime.now().strftime("%F%H%M%S") ), } + ## ref https://github.com/python-caldav/caldav/issues/448 - allow strings instead of a sequence here for sort_key in sort_keys: val = comp.get(sort_key, None) if val is None: @@ -1327,6 +1328,8 @@ def sort_key_func(x): return ret if sort_keys: + if isinstance(sort_keys, str): + sort_keys = (sort_keys,) objects.sort(key=sort_key_func, reverse=sort_reverse) ## partial workaround for https://github.com/python-caldav/caldav/issues/201 diff --git a/tests/test_caldav.py b/tests/test_caldav.py index 4f3b00ae..b3c6254b 100644 --- a/tests/test_caldav.py +++ b/tests/test_caldav.py @@ -1500,6 +1500,40 @@ def testSearchEvent(self): assert len(all_events) == 3 assert all_events[0].instance.vevent.summary.value == "Our Blissful Anniversary" + ## A more robust check for the sort key + all_events = c.search(sort_keys=("DTSTART",)) + assert len(all_events) == 3 + assert str(all_events[0].icalendar_component["DTSTART"].dt) < str( + all_events[1].icalendar_component["DTSTART"].dt + ) + assert str(all_events[1].icalendar_component["DTSTART"].dt) < str( + all_events[2].icalendar_component["DTSTART"].dt + ) + all_events = c.search(sort_keys=("DTSTART",), sort_reverse=True) + assert str(all_events[0].icalendar_component["DTSTART"].dt) > str( + all_events[1].icalendar_component["DTSTART"].dt + ) + assert str(all_events[1].icalendar_component["DTSTART"].dt) > str( + all_events[2].icalendar_component["DTSTART"].dt + ) + + ## Ref https://github.com/python-caldav/caldav/issues/448 + all_events = c.search(sort_keys=("DTSTART")) + assert len(all_events) == 3 + assert str(all_events[0].icalendar_component["DTSTART"].dt) < str( + all_events[1].icalendar_component["DTSTART"].dt + ) + assert str(all_events[1].icalendar_component["DTSTART"].dt) < str( + all_events[2].icalendar_component["DTSTART"].dt + ) + all_events = c.search(sort_keys=("DTSTART"), sort_reverse=True) + assert str(all_events[0].icalendar_component["DTSTART"].dt) > str( + all_events[1].icalendar_component["DTSTART"].dt + ) + assert str(all_events[1].icalendar_component["DTSTART"].dt) > str( + all_events[2].icalendar_component["DTSTART"].dt + ) + def testSearchSortTodo(self): self.skip_on_compatibility_flag("read_only") self.skip_on_compatibility_flag("no_todo")