diff --git a/.github/workflows/build-n-test.yml b/.github/workflows/build-n-test.yml index 46300ed..5132da5 100644 --- a/.github/workflows/build-n-test.yml +++ b/.github/workflows/build-n-test.yml @@ -3,40 +3,41 @@ name: Build 🛠️ and test 🧪 eventkit on: [push, workflow_dispatch] jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["pypy3.10", "pypy3.11", "3.10", "3.11", "3.12", "3.13"] + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: + ["pypy3.10", "pypy3.11", "3.10", "3.11", "3.12", "3.13", "3.14"] - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - cache: pip - # Print the current Python version - - name: Display Python version - run: python -c "import sys; print(sys.version)" - - name: Install dependencies - run: | - python -m pip install -U pip poetry - poetry install --with dev + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: pip + # Print the current Python version + - name: Display Python version + run: python -c "import sys; print(sys.version)" + - name: Install dependencies + run: | + python -m pip install -U pip poetry + poetry install --with dev - - name: Ruff static code analysis - run: | - poetry run ruff check eventkit/ - poetry run ruff format eventkit/ + - name: Ruff static code analysis + run: | + poetry run ruff check eventkit/ + poetry run ruff format eventkit/ - - name: MyPy static code analysis - run: | - poetry run mypy . + - name: MyPy static code analysis + run: | + poetry run mypy . - - name: Test with pytest - run: | - poetry run pytest -vs + - name: Test with pytest + run: | + poetry run pytest -vs - - name: Build a binary wheel and a source tarball - run: | - poetry build -n + - name: Build a binary wheel and a source tarball + run: | + poetry build -n diff --git a/eventkit/util.py b/eventkit/util.py index da34ab9..c704a28 100644 --- a/eventkit/util.py +++ b/eventkit/util.py @@ -1,3 +1,5 @@ +"""Eventkit utilities.""" + import asyncio import datetime as dt from typing import AsyncIterator, Final @@ -18,8 +20,15 @@ def __repr__(self): def get_event_loop(): """Get asyncio event loop or create one if it doesn't exist.""" - loop = asyncio.get_event_loop_policy().get_event_loop() - return loop + try: + return asyncio.get_running_loop() + except RuntimeError: + try: + return asyncio.get_event_loop() + except RuntimeError: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + return loop async def timerange(start=0, end=None, step: float = 1) -> AsyncIterator[dt.datetime]: