From 48e5a0ea2ecd032f60338e2b0567ce48c642607c Mon Sep 17 00:00:00 2001 From: David Salvisberg Date: Wed, 21 Aug 2024 11:13:09 +0200 Subject: [PATCH] Adds support for Python 3.11+. Drops Python 3.7 support. Uses trusted publishers for PyPI workflow. --- .github/workflows/python-pr.yaml | 6 +++--- .github/workflows/python-publish.yaml | 30 +++++++++++++++++---------- .github/workflows/python-tox.yaml | 7 ++++--- .pre-commit-config.yaml | 8 +++---- AIS/pdf.py | 13 ++++++------ HISTORY.rst | 3 +++ pyproject.toml | 20 ++++++++++-------- setup.cfg | 6 ++++-- 8 files changed, 55 insertions(+), 38 deletions(-) diff --git a/.github/workflows/python-pr.yaml b/.github/workflows/python-pr.yaml index ba6d107..35b7060 100644 --- a/.github/workflows/python-pr.yaml +++ b/.github/workflows/python-pr.yaml @@ -8,13 +8,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, '3.10'] + python-version: [3.8, 3.9, '3.10', '3.11', '3.12', '3.13'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} diff --git a/.github/workflows/python-publish.yaml b/.github/workflows/python-publish.yaml index 6757d86..4aa5a58 100644 --- a/.github/workflows/python-publish.yaml +++ b/.github/workflows/python-publish.yaml @@ -9,20 +9,28 @@ jobs: runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/project/ais2-py + + permissions: + id-token: write + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: '3.x' + python-version: "3.x" + - name: Install dependencies run: | python -m pip install --upgrade pip - pip install build twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python -m build -s -w - twine upload dist/* + pip install build + + - name: Build package distributions + run: python -m build -s -w + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/python-tox.yaml b/.github/workflows/python-tox.yaml index f5effef..1d3d11f 100644 --- a/.github/workflows/python-tox.yaml +++ b/.github/workflows/python-tox.yaml @@ -8,10 +8,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, '3.10'] + python-version: [3.8, 3.9, '3.10', '3.11', '3.12', '3.13'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Get branch name (merge) if: github.event_name != 'pull_request' @@ -28,9 +28,10 @@ jobs: >> $GITHUB_ENV - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + allow-prereleases: true - name: Install dependencies run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 10674f0..6781894 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: mixed-line-ending @@ -15,17 +15,17 @@ repos: additional_dependencies: - types_requests - repo: https://github.com/seantis/pre-commit-hooks - rev: v1.0.1 + rev: v1.1.0 hooks: - id: nocheckin exclude: .pre-commit-config.yaml - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + rev: 7.1.1 hooks: - id: flake8 files: '^(AIS/.*|tests/.*|setup)\.py$' - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.942 + rev: v1.11.1 hooks: - id: mypy files: '^AIS/.*\.py$' diff --git a/AIS/pdf.py b/AIS/pdf.py index 16a54dd..9841564 100644 --- a/AIS/pdf.py +++ b/AIS/pdf.py @@ -20,7 +20,7 @@ from typing import overload -from typing import BinaryIO +from typing import IO from typing import Optional from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -40,7 +40,7 @@ def __init__( self, input_file: 'FileLike', *, - out_stream: Optional[BinaryIO] = ..., + out_stream: Optional[IO[bytes]] = ..., sig_name: str = ..., sig_size: int = ... ): ... @@ -49,7 +49,7 @@ def __init__( def __init__( self, *, - inout_stream: BinaryIO, + inout_stream: IO[bytes], sig_name: str = ..., sig_size: int = ... ): ... @@ -58,8 +58,8 @@ def __init__( self, input_file: Optional['FileLike'] = None, *, - inout_stream: Optional[BinaryIO] = None, - out_stream: Optional[BinaryIO] = None, + inout_stream: Optional[IO[bytes]] = None, + out_stream: Optional[IO[bytes]] = None, sig_name: str = 'Signature', sig_size: int = 64*1024, # 64 KiB ): @@ -149,8 +149,9 @@ def __init__( """Signing I/O setup to be passed to pyHanko""" @property - def out_stream(self) -> BinaryIO: + def out_stream(self) -> IO[bytes]: """Output stream for the signed PDF.""" + assert self.sig_io_setup.output is not None return self.sig_io_setup.output def digest(self) -> str: diff --git a/HISTORY.rst b/HISTORY.rst index 206033c..00c16c5 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,9 @@ Release History --------------- +- Add Python 3.11, 3.12, 3.13 support +- Remove Python 3.7 support + 2.2.1 (2022-09-02) ++++++++++++++++++ diff --git a/pyproject.toml b/pyproject.toml index 7f810d6..76ce4e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ exclude_lines = [ ] [tool.mypy] -python_version = "3.10" +python_version = "3.8" follow_imports = "silent" warn_redundant_casts = true warn_unreachable = true @@ -46,19 +46,21 @@ ignore_missing_imports = true legacy_tox_ini = """ [tox] isolated_build = True -envlist = py37,py38,py39,py310,pypy,lint,bandit,mypy +envlist = py38,py39,py310,py311,py312,py313,pypy,lint,bandit,mypy [gh-actions] python = - 3.7: py37 3.8: py38 3.9: py39 - 3.10: py310,lint,bandit,mypy + 3.10: py310 + 3.11: py311,lint,bandit,mypy + 3.12: py312 + 3.13: py313 [testenv] setenv = - py{37,38,39,310}: COVERAGE_FILE = .coverage.{envname} -passenv = AIS_CUSTOMER AIS_KEY_STATIC AIS_CERT_FILE AIS_CERT_KEY AIS_SSL_CA + py{38,39,310,311,312,313}: COVERAGE_FILE = .coverage.{envname} +passenv = AIS_CUSTOMER,AIS_KEY_STATIC,AIS_CERT_FILE,AIS_CERT_KEY,AIS_SSL_CA deps = pytest>=2.8.0 vcrpy>=1.7.0 @@ -67,20 +69,20 @@ deps = commands = py.test --cov={envsitepackagesdir}/AIS --cov-report= {posargs} [testenv:lint] -basepython = python3.10 +basepython = python3.11 deps = flake8 commands = flake8 AIS/ tests/ [testenv:mypy] -basepython = python3.10 +basepython = python3.11 deps = mypy types-requests commands = mypy -p AIS [testenv:bandit] -basepython = python3.10 +basepython = python3.11 deps = bandit[toml] commands = bandit -c pyproject.toml -r AIS/ diff --git a/setup.cfg b/setup.cfg index 27dfa22..aa4cbbe 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,10 +17,12 @@ classifiers = License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+) Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 + Programming Language :: Python :: 3.13 Programming Language :: Python :: Implementation :: CPython Programming Language :: Python :: Implementation :: PyPy @@ -28,7 +30,7 @@ classifiers = include_package_data = True packages = AIS -python_requires = >=3.7 +python_requires = >=3.8 install_requires = requests >=2.0 pyHanko >=0.9.0