From 53e301ecd0da4cf88616ddc8c40634f38b52af56 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Wed, 31 May 2023 20:33:38 +0200 Subject: [PATCH 01/10] Fixed Issue 518 (RRULE BYDAY=xMO with x>=10 raises ValueError with to_ical()): updated WEEKDAY_RULE regex to accept 2 digits. Added tests for to_ical() covering various BYDAY values. --- CHANGES.rst | 4 ++- docs/credits.rst | 1 + src/icalendar/prop.py | 2 +- src/icalendar/tests/test_recurrence.py | 38 ++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 457c9d8e..c3e315fc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,9 @@ Changelog 4.1.1 (unreleased) ------------------ -- Nothing changed yet. +Bug fixes: + +- to_ical() now accepts RRULE BYDAY values>=10 (Issue #518) 4.1.0 (2022-07-11) diff --git a/docs/credits.rst b/docs/credits.rst index 420af8d4..24772ed7 100644 --- a/docs/credits.rst +++ b/docs/credits.rst @@ -56,6 +56,7 @@ icalendar contributors - Clive Stevens - Dalton Durst - Kamil MaƄkowski +- Matt Lewis Find out who contributed:: diff --git a/src/icalendar/prop.py b/src/icalendar/prop.py index 48a346b1..60e9feb9 100644 --- a/src/icalendar/prop.py +++ b/src/icalendar/prop.py @@ -71,7 +71,7 @@ WEEKS_PART = r'(\d+)W' DURATION_REGEX = re.compile(r'([-+]?)P(?:%s|%s)$' % (WEEKS_PART, DATETIME_PART)) -WEEKDAY_RULE = re.compile(r'(?P[+-]?)(?P[\d]?)' +WEEKDAY_RULE = re.compile(r'(?P[+-]?)(?P[\d]{0,2})' r'(?P[\w]{2})$') diff --git a/src/icalendar/tests/test_recurrence.py b/src/icalendar/tests/test_recurrence.py index fc8b1be0..4e1aa46b 100644 --- a/src/icalendar/tests/test_recurrence.py +++ b/src/icalendar/tests/test_recurrence.py @@ -60,3 +60,41 @@ def test_recurrence_exdates_multiple_lines(self): self.assertEqual(exdate[0].to_ical(), b'20120529T100000') # TODO: test for embedded timezone information! + + def test_byday_to_ical(self): + 'Test the BYDAY rule is correctly processed by to_ical().' + TEST_CASES = ( + # Test some YEARLY BYDAY repeats + ('YEARLY', '1SU', datetime.date(2016,1,3), # 1st Sunday in year + b'BEGIN:VEVENT\r\nSUMMARY:Event YEARLY 1SU\r\nDTSTART;VALUE=DATE:20160103\r\nRRULE:FREQ=YEARLY;BYDAY=1SU\r\nEND:VEVENT\r\n'), + ('YEARLY', '53MO', datetime.date(1984,12,31), # 53rd Mon in (leap) year + b'BEGIN:VEVENT\r\nSUMMARY:Event YEARLY 53MO\r\nDTSTART;VALUE=DATE:19841231\r\nRRULE:FREQ=YEARLY;BYDAY=53MO\r\nEND:VEVENT\r\n'), + ('YEARLY', '-1TU', datetime.date(1999,12,28), # Last Tues in year + b'BEGIN:VEVENT\r\nSUMMARY:Event YEARLY -1TU\r\nDTSTART;VALUE=DATE:19991228\r\nRRULE:FREQ=YEARLY;BYDAY=-1TU\r\nEND:VEVENT\r\n'), + ('YEARLY', '-17WE', datetime.date(2000,9,6), # 17th-last Wed in year + b'BEGIN:VEVENT\r\nSUMMARY:Event YEARLY -17WE\r\nDTSTART;VALUE=DATE:20000906\r\nRRULE:FREQ=YEARLY;BYDAY=-17WE\r\nEND:VEVENT\r\n'), + # Test some MONTHLY BYDAY repeats + ('MONTHLY', '2TH', datetime.date(2003,4,10), # 2nd Thurs in month + b'BEGIN:VEVENT\r\nSUMMARY:Event MONTHLY 2TH\r\nDTSTART;VALUE=DATE:20030410\r\nRRULE:FREQ=MONTHLY;BYDAY=2TH\r\nEND:VEVENT\r\n'), + ('MONTHLY', '-3FR', datetime.date(2017,5,12), # 3rd-last Fri in month + b'BEGIN:VEVENT\r\nSUMMARY:Event MONTHLY -3FR\r\nDTSTART;VALUE=DATE:20170512\r\nRRULE:FREQ=MONTHLY;BYDAY=-3FR\r\nEND:VEVENT\r\n'), + ('MONTHLY', '-5SA', datetime.date(2053,11,1), # 5th-last Sat in month + b'BEGIN:VEVENT\r\nSUMMARY:Event MONTHLY -5SA\r\nDTSTART;VALUE=DATE:20531101\r\nRRULE:FREQ=MONTHLY;BYDAY=-5SA\r\nEND:VEVENT\r\n'), + # Specifically test examples from the report of Issue #518 + # https://github.com/collective/icalendar/issues/518 + ('YEARLY', '9MO', datetime.date(2023,2,27), # 9th Monday in year + b'BEGIN:VEVENT\r\nSUMMARY:Event YEARLY 9MO\r\nDTSTART;VALUE=DATE:20230227\r\nRRULE:FREQ=YEARLY;BYDAY=9MO\r\nEND:VEVENT\r\n'), + ('YEARLY', '10MO', datetime.date(2023,3,6), # 10th Monday in year + b'BEGIN:VEVENT\r\nSUMMARY:Event YEARLY 10MO\r\nDTSTART;VALUE=DATE:20230306\r\nRRULE:FREQ=YEARLY;BYDAY=10MO\r\nEND:VEVENT\r\n'), + ) + for c in TEST_CASES: + self._dotest_byday_to_ical(*c) + + def _dotest_byday_to_ical(self, freq, byday, dtstart, expected): + 'Called by test_byday_to_ical() with various parameters' + event = icalendar.Event() + event.add('SUMMARY', ' '.join(['Event', freq, byday])) + event.add('DTSTART', dtstart) + event.add('RRULE', {'FREQ':[freq], 'BYDAY':byday}) + ical = event.to_ical() + self.assertEqual(ical, expected) From b3ecc2cf6d4188a61259df31dccf0ce6d2668b51 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 30 Aug 2023 07:12:15 +0100 Subject: [PATCH 02/10] Fix python versions and OS versions see https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json --- .github/workflows/tests.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6bd86c24..f85cbb45 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,13 +16,13 @@ jobs: # [Python version, tox env, OS ] # see for version: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json # see for runners: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources - - ["2.7", "py27", "ubuntu-latest"] - - ["pypy-2.7", "pypy", "ubuntu-latest"] + - ["2.7", "py27", "ubuntu-22.04"] + - ["pypy-2.7", "pypy", "ubuntu-22.04"] - ["3.4.10", "py34", "ubuntu-18.04"] - - ["3.5.10", "py35", "ubuntu-latest"] - - ["3.6", "py36", "ubuntu-latest"] - - ["3.7", "py37", "ubuntu-latest"] - - ["3.8", "py38", "ubuntu-latest"] + - ["3.5.10", "py35", "ubuntu-20.04"] + - ["3.6.15", "py36", "ubuntu-20.04"] + - ["3.7.17", "py37", "ubuntu-22.04"] + - ["3.8.18", "py38", "ubuntu-latest"] - ["3.9", "py39", "ubuntu-latest"] - ["3.10", "py310", "ubuntu-latest"] - ["pypy3", "pypy3", "ubuntu-latest"] From db77958094b2eb50f7390afcc19573390961f4f6 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 30 Aug 2023 07:21:23 +0100 Subject: [PATCH 03/10] update CI task versions and remove Python versions --- .github/workflows/tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f85cbb45..1bf407d1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,8 +16,8 @@ jobs: # [Python version, tox env, OS ] # see for version: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json # see for runners: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources - - ["2.7", "py27", "ubuntu-22.04"] - - ["pypy-2.7", "pypy", "ubuntu-22.04"] +# - ["2.7", "py27", "ubuntu-22.04"] + - ["pypy2.7", "pypy", "ubuntu-22.04"] - ["3.4.10", "py34", "ubuntu-18.04"] - ["3.5.10", "py35", "ubuntu-20.04"] - ["3.6.15", "py36", "ubuntu-20.04"] @@ -25,14 +25,14 @@ jobs: - ["3.8.18", "py38", "ubuntu-latest"] - ["3.9", "py39", "ubuntu-latest"] - ["3.10", "py310", "ubuntu-latest"] - - ["pypy3", "pypy3", "ubuntu-latest"] + - ["pypy3.9", "pypy3", "ubuntu-latest"] runs-on: ${{ matrix.config[2] }} name: ${{ matrix.config[1] }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.config[0] }} - name: Pip cache From d70ed7f14e268121efdb2a239f90522f083f10ed Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 30 Aug 2023 07:24:58 +0100 Subject: [PATCH 04/10] Fix coverage --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1bf407d1..d667e1dc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,6 +16,7 @@ jobs: # [Python version, tox env, OS ] # see for version: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json # see for runners: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources + # If you change this, maybe you need to change the coverage version. # - ["2.7", "py27", "ubuntu-22.04"] - ["pypy2.7", "pypy", "ubuntu-22.04"] - ["3.4.10", "py34", "ubuntu-18.04"] @@ -50,7 +51,7 @@ jobs: - name: Test run: tox -e ${{ matrix.config[1] }} - name: Coverage - if: matrix.config[0] != '2.7' && matrix.config[0] != 'pypy-2.7' && matrix.config[0] != '3.4.10' + if: matrix.config[0] != '2.7' && matrix.config[0] != 'pypy2.7' && matrix.config[0] != '3.4.10' run: | pip install coveralls coverage-python-version coveralls --service=github From eac2ea37e0fe9f352445c86b08ade4e296850902 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 30 Aug 2023 07:28:27 +0100 Subject: [PATCH 05/10] Add Python2.7 as installed by default --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d667e1dc..04b86c4c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,7 +17,7 @@ jobs: # see for version: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json # see for runners: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources # If you change this, maybe you need to change the coverage version. -# - ["2.7", "py27", "ubuntu-22.04"] + - ["2.7", "py27", "ubuntu-22.04"] - ["pypy2.7", "pypy", "ubuntu-22.04"] - ["3.4.10", "py34", "ubuntu-18.04"] - ["3.5.10", "py35", "ubuntu-20.04"] @@ -33,6 +33,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python + if: matrix.config[0] != '2.7' uses: actions/setup-python@v4 with: python-version: ${{ matrix.config[0] }} From be406978a1d9aa9e1d15d5c61bea7965c502d029 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 30 Aug 2023 07:30:10 +0100 Subject: [PATCH 06/10] Revert "Add Python2.7 as installed by default" This reverts commit eac2ea37e0fe9f352445c86b08ade4e296850902. --- .github/workflows/tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 04b86c4c..d667e1dc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,7 +17,7 @@ jobs: # see for version: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json # see for runners: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources # If you change this, maybe you need to change the coverage version. - - ["2.7", "py27", "ubuntu-22.04"] +# - ["2.7", "py27", "ubuntu-22.04"] - ["pypy2.7", "pypy", "ubuntu-22.04"] - ["3.4.10", "py34", "ubuntu-18.04"] - ["3.5.10", "py35", "ubuntu-20.04"] @@ -33,7 +33,6 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python - if: matrix.config[0] != '2.7' uses: actions/setup-python@v4 with: python-version: ${{ matrix.config[0] }} From 2e1442bc38a8ef138ca16090c2728b71d9c073d2 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 30 Aug 2023 07:56:28 +0100 Subject: [PATCH 07/10] remove 18.04 runner (py3.4) --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d667e1dc..6e787ad7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,7 +19,7 @@ jobs: # If you change this, maybe you need to change the coverage version. # - ["2.7", "py27", "ubuntu-22.04"] - ["pypy2.7", "pypy", "ubuntu-22.04"] - - ["3.4.10", "py34", "ubuntu-18.04"] +# - ["3.4.10", "py34", "ubuntu-18.04"] # there seem to be no 18.04 runners any more - ["3.5.10", "py35", "ubuntu-20.04"] - ["3.6.15", "py36", "ubuntu-20.04"] - ["3.7.17", "py37", "ubuntu-22.04"] From 67f4199bcd1a5242dd250c158b42b68aae4b0dfc Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 30 Aug 2023 07:59:14 +0100 Subject: [PATCH 08/10] document version compatibility in README --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index c699a68d..3be0a844 100644 --- a/README.rst +++ b/README.rst @@ -11,7 +11,7 @@ files. :Code: https://github.com/collective/icalendar :Mailing list: https://github.com/collective/icalendar/issues :Dependencies: `python-dateutil`_ and `pytz`_. -:Compatible with: Python 2.7 and 3.4+ +:Compatible with: Python 2.7 & 3.4 untested; 3.5+, Pypy2 and Pypy3 tested :License: `BSD`_ ---- From 669baf02d304547d39bc8b74adb0322229a33302 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 30 Aug 2023 08:01:39 +0100 Subject: [PATCH 09/10] add pypi deployment from tags to 4.x branch --- .github/workflows/tests.yml | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6e787ad7..46650108 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -57,3 +57,61 @@ jobs: coveralls --service=github env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + deploy-tag-to-pypi: + # only deploy on tags, see https://stackoverflow.com/a/58478262/1320237 + if: startsWith(github.ref, 'refs/tags/v') + needs: + - run-tests + runs-on: ubuntu-latest + # This environment stores the TWINE_USERNAME and TWINE_PASSWORD + # see https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment + environment: + name: PyPI + url: https://pypi.org/project/icalendar/ + # after using the environment, we need to make the secrets available + # see https://docs.github.com/en/actions/security-guides/encrypted-secrets#example-using-bash + env: + TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} + TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.9" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install wheel twine + - name: Check the tag + run: | + PACKAGE_VERSION=`python setup.py --version` + TAG_NAME=v$PACKAGE_VERSION + echo "Package version $PACKAGE_VERSION with possible tag name $TAG_NAME on $GITHUB_REF_NAME" + # test that the tag represents the version + # see https://docs.github.com/en/actions/learn-github-actions/environment-variables + if [ "$TAG_NAME" != "$GITHUB_REF_NAME" ]; then + echo "ERROR: This tag is for the wrong version. Got \"$GITHUB_REF_NAME\" expected \"$TAG_NAME\"." + exit 1 + fi + - name: remove old files + run: rm -rf dist/* + - name: build distribution files + run: python setup.py bdist_wheel sdist + - name: deploy to pypi + run: | + # You will have to set the variables TWINE_USERNAME and TWINE_PASSWORD + # You can use a token specific to your project by setting the user name to + # __token__ and the password to the token given to you by the PyPI project. + # sources: + # - https://shambu2k.hashnode.dev/gitlab-to-pypi + # - http://blog.octomy.org/2020/11/deploying-python-pacakges-to-pypi-using.html?m=1 + if [ -z "$TWINE_USERNAME" ]; then + echo "WARNING: TWINE_USERNAME not set!" + fi + if [ -z "$TWINE_PASSWORD" ]; then + echo "WARNING: TWINE_PASSWORD not set!" + fi + twine check dist/* + twine upload dist/* From b736c87a896cd09f0955316f0d7e068ddff835a1 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 30 Aug 2023 08:07:16 +0100 Subject: [PATCH 10/10] Fix workflow reference --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 46650108..3a17682d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ on: workflow_dispatch: jobs: - build: + run-tests: strategy: matrix: config: