Skip to content

Commit

Permalink
Drop python 3.8 support and update CI (#5)
Browse files Browse the repository at this point in the history
- Drop python3.8 support
- Add additional pre-commit checks
- Enable python 3.13 in CI
- Enable windows and mac os versions in CI
- Enable CI caching
  • Loading branch information
sdb9696 authored Aug 29, 2024
1 parent d78eef6 commit b637f5b
Show file tree
Hide file tree
Showing 39 changed files with 1,670 additions and 896 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ max-line-length = 88
extend-ignore = E203
per-file-ignores =
# imported but unused & redefinition of unused
tests/*: F811, F401
tests/*: F811, F401
84 changes: 84 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
name: Setup Environment
description: Install requested pipx dependencies, configure the system python, and install poetry and the package dependencies

inputs:
poetry-install-options:
default: ""
poetry-version:
default: 1.8.2
python-version:
required: true
cache-pre-commit:
default: false

runs:
using: composite
steps:
- uses: "actions/setup-python@v5"
id: setup-python
with:
python-version: "${{ inputs.python-version }}"
allow-prereleases: true

- name: Setup pipx environment Variables
id: pipx-env-setup
# pipx default home and bin dir are not writable by the cache action
# so override them here and add the bin dir to PATH for later steps.
# This also ensures the pipx cache only contains poetry
run: |
SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}"
PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache"
echo "pipx-cache-path=${PIPX_CACHE}" >> $GITHUB_OUTPUT
echo "pipx-version=$(pipx --version)" >> $GITHUB_OUTPUT
echo "PIPX_HOME=${PIPX_CACHE}${SEP}home" >> $GITHUB_ENV
echo "PIPX_BIN_DIR=${PIPX_CACHE}${SEP}bin" >> $GITHUB_ENV
echo "PIPX_MAN_DIR=${PIPX_CACHE}${SEP}man" >> $GITHUB_ENV
echo "${PIPX_CACHE}${SEP}bin" >> $GITHUB_PATH
shell: bash

- name: Pipx cache
id: pipx-cache
uses: actions/cache@v4
with:
path: ${{ steps.pipx-env-setup.outputs.pipx-cache-path }}
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-poetry-${{ inputs.poetry-version }}

- name: Install poetry
if: steps.pipx-cache.outputs.cache-hit != 'true'
id: install-poetry
shell: bash
run: |-
pipx install poetry==${{ inputs.poetry-version }} --python "${{ steps.setup-python.outputs.python-path }}"
- name: Read poetry cache location
id: poetry-cache-location
shell: bash
run: |-
echo "poetry-venv-location=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Poetry cache
with:
path: |
${{ steps.poetry-cache-location.outputs.poetry-venv-location }}
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-options-${{ inputs.poetry-install-options }}

- name: "Poetry install"
shell: bash
run: |
poetry install ${{ inputs.poetry-install-options }}
- name: Read pre-commit version
if: inputs.cache-pre-commit == 'true'
id: pre-commit-version
shell: bash
run: >-
echo "pre-commit-version=$(poetry run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
if: inputs.cache-pre-commit == 'true'
name: Pre-commit cache
with:
path: ~/.cache/pre-commit/
key: ${{ runner.os }}-pre-commit-${{ steps.pre-commit-version.outputs.pre-commit-version }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
110 changes: 36 additions & 74 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ on:
branches: ["main"]

env:
POETRY_VERSION: 1.6.1
TOX_VERSION: 4.11.3
COVERALLS_VERSION: 3.3.1
POETRY_VERSION: 1.8.3

jobs:
linting:
Expand All @@ -19,22 +17,17 @@ jobs:
matrix:
python-version: ["3.12"]
steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
- uses: "actions/checkout@v4"
- name: Setup environment
uses: ./.github/actions/setup
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
run: |
python3 -m pip install --upgrade pip
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install poetry==$POETRY_VERSION
pipx install tox==$TOX_VERSION
- name: Lint with tox
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
poetry-install-options: ""
cache-pre-commit: true
- name: "Run pre-commit checks"
run: |
tox
env:
TOXENV: lint
poetry run pre-commit run --all-files
docs:
name: "Build docs"
Expand All @@ -44,73 +37,42 @@ jobs:
matrix:
python-version: ["3.12"]
steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
- uses: "actions/checkout@v4"
- name: Setup environment
uses: ./.github/actions/setup
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
run: |
python3 -m pip install --upgrade pip
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install poetry==$POETRY_VERSION
pipx install tox==$TOX_VERSION
- name: Make docs with tox
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
poetry-install-options: "--extras docs --without dev"
- name: Make docs poetry
run: |
tox
env:
TOXENV: docs
poetry run make -C docs html
tests:
name: tests
name: Tests - Python ${{ matrix.python-version}} on ${{ matrix.os }}
needs: linting
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.9", "pypy-3.10"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: "actions/checkout@v4"
- name: Setup environment
uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install poetry==$POETRY_VERSION
pipx install tox==$TOX_VERSION
pipx install coveralls==$COVERALLS_VERSION
- name: Prepare toxenv
id: toxenv
run: |
if [[ '${{ matrix.python-version }}' == '3.8' ]]; then
echo "::set-output name=toxenv::py38"
elif [[ '${{ matrix.python-version }}' == '3.9' ]]; then
echo "::set-output name=toxenv::py39"
elif [[ '${{ matrix.python-version }}' == '3.10' ]]; then
echo "::set-output name=toxenv::py310"
elif [[ '${{ matrix.python-version }}' == '3.11' ]]; then
echo "::set-output name=toxenv::py311"
else
echo "::set-output name=toxenv::py312"
fi
- name: Test with tox
run: |
tox
env:
TOXENV: ${{ steps.toxenv.outputs.toxenv }}
- name: Report to Coveralls
run: |
coveralls --service=github
# Only report coverage on latest Python version and skip on prior failures
poetry-version: ${{ env.POETRY_VERSION }}
- name: Run tests
run: >
poetry run pytest tests/
--cov=firebase_messaging --cov-report=xml
--cov-report=term-missing --import-mode importlib
- name: Coveralls GitHub Action
uses: coverallsapp/[email protected]
with:
file: coverage.xml
debug: true
if: ${{ success() && matrix.python-version == '3.12' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
python -m pip install --upgrade pip
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install poetry==1.6.1
pipx install poetry==1.8.3
- name: Build
run: |
poetry build
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ __pycache__/
.tox
htmlcov/
docs/build
dist
dist
59 changes: 37 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
repos:
- repo: https://github.com/python-poetry/poetry
rev: 1.6.0

- repo: https://github.com/python-poetry/poetry
rev: "1.8"
hooks:
- id: poetry-check

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: poetry-check
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: check-ast

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
rev: v0.6.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
args: ["--install-types", "--non-interactive", "--ignore-missing-imports"]
additional_dependencies: [types-protobuf]
# Exclude the proto/*.py so when files are passed as parameters
# they do not cause duplicate module errors
exclude: |
(?x)^(
tests/.*|
docs/.*|
firebase_messaging/proto/.*py$
)$
- id: ruff-format

- repo: https://github.com/PyCQA/doc8
rev: 'v1.1.1'
hooks:
- id: doc8
additional_dependencies: [tomli]

- repo: local
hooks:
# Run mypy in the virtual environment so it uses the installed dependencies
# for more accurate checking than using the pre-commit mypy mirror
- id: mypy
name: mypy
entry: ./run-in-env.sh mypy
language: system
types_or: [python, pyi]
require_serial: true
exclude: | # exclude required because --all-files passes py and pyi
(?x)^(
docs/.*|
tests/.*|
firebase_messaging/proto/.*py$
)$
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ python:
- method: pip
path: .
extra_requirements:
- docs
- docs
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Code originally based on typescript/node implementation by
`Matthieu Lemoine <https://github.com/MatthieuLemoine/push-receiver>`_.
See `this blog post <https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0>`_ for more details.

Converted to python by
Converted to python by
`lolisamurai <https://github.com/Francesco149/push_receiver>`_

http decryption logic in decrypt.py by
http decryption logic in decrypt.py by
`Martin Thomson <https://github.com/web-push-libs/encrypted-content-encoding>`_
2 changes: 1 addition & 1 deletion docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ API Documentation

.. autoclass:: FcmPushClient
:members:
:undoc-members:
:undoc-members:
2 changes: 1 addition & 1 deletion docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.. include:: ../../CHANGELOG.rst
.. include:: ../../CHANGELOG.rst
3 changes: 1 addition & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ Welcome to python-ring-doorbell's documentation!
:hidden:
:titlesonly:
:maxdepth: 0

Home <self>
api
changelog

6 changes: 3 additions & 3 deletions firebase_messaging/fcmpushclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from contextlib import suppress as contextlib_suppress
from dataclasses import dataclass
from enum import Enum
from typing import TYPE_CHECKING, Any, Callable, Dict
from typing import TYPE_CHECKING, Any, Callable

from aiohttp import ClientSession
from cryptography.hazmat.backends import default_backend
Expand Down Expand Up @@ -42,8 +42,8 @@

_logger = logging.getLogger(__name__)

OnNotificationCallable = Callable[[Dict[str, Any], str, Any], None]
CredentialsUpdatedCallable = Callable[[Dict[str, Any]], None]
OnNotificationCallable = Callable[[dict[str, Any], str, Any], None]
CredentialsUpdatedCallable = Callable[[dict[str, Any]], None]


class ErrorType(Enum):
Expand Down
Loading

0 comments on commit b637f5b

Please sign in to comment.