Skip to content

Commit

Permalink
allow strings instead of sequences as input for sort_keys in search. …
Browse files Browse the repository at this point in the history
…Updates #448
  • Loading branch information
tobixen committed Nov 5, 2024
1 parent 5be5d35 commit 784a2f2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
9 changes: 4 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion RELEASE-HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
3 changes: 3 additions & 0 deletions caldav/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/test_caldav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 784a2f2

Please sign in to comment.