From 0ff6e8c4c4595ab7a5ef45d2355d7fd390d06dbe Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen Date: Mon, 11 Dec 2023 14:00:09 +0100 Subject: [PATCH 1/2] Use Python 3.11 throughout In the: - CI/CD - Dockerfile - Python package metadata Add pyupgrade pre-commit hook, setting it to run with arg `--py311-plus`. --- .github/workflows/cd_release.yml | 4 ++-- .github/workflows/ci_dependabot.yml | 4 ++-- .github/workflows/ci_tests.yml | 12 ++++++------ .pre-commit-config.yaml | 20 +++++++++++++------- Dockerfile | 2 +- pyproject.toml | 2 +- setup.py | 6 ++---- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/.github/workflows/cd_release.yml b/.github/workflows/cd_release.yml index 4a9c126..666d36f 100644 --- a/.github/workflows/cd_release.yml +++ b/.github/workflows/cd_release.yml @@ -22,10 +22,10 @@ jobs: with: fetch-depth: 0 - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: '3.11' - name: Install Python dependencies run: | diff --git a/.github/workflows/ci_dependabot.yml b/.github/workflows/ci_dependabot.yml index 9e8f547..9a1208a 100644 --- a/.github/workflows/ci_dependabot.yml +++ b/.github/workflows/ci_dependabot.yml @@ -23,10 +23,10 @@ jobs: with: ref: main - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: '3.11' - name: Install `pre-commit` run: | diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index e264638..ae51df1 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -17,10 +17,10 @@ jobs: token: ${{ secrets.CI_RESET_TEST_BRANCHES }} fetch-depth: 0 - - name: Set up Python 3.9 + - name: Set up Python 3.11 uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: '3.11' - name: Reset branches run: | @@ -289,10 +289,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: '3.11' - name: Install dependencies run: | @@ -319,10 +319,10 @@ jobs: with: fetch-depth: 2 - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: '3.11' - name: Install dependencies run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b6a646..ffcddb3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,7 @@ default_language_version: - python: python3.8 + python: python3.11 repos: - - repo: https://github.com/ambv/black - rev: 23.11.0 - hooks: - - id: black - name: Blacken - - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: @@ -22,6 +16,18 @@ repos: name: Fix requirements*.txt files: ^requirements.*\.txt$ + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: [--py311-plus] + + - repo: https://github.com/ambv/black + rev: 23.11.0 + hooks: + - id: black + name: Blacken + - repo: https://github.com/PyCQA/bandit rev: '1.7.5' hooks: diff --git a/Dockerfile b/Dockerfile index d5bb765..cd2e1a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:alpine +FROM python:3.11-alpine COPY README.md setup.py requirements*.txt ./ COPY push_action ./push_action diff --git a/pyproject.toml b/pyproject.toml index b07265f..493d83e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.mypy] -python_version = "3.8" +python_version = "3.11" ignore_missing_imports = true scripts_are_modules = true warn_unused_configs = true diff --git a/setup.py b/setup.py index 92e7941..b5fe942 100644 --- a/setup.py +++ b/setup.py @@ -39,12 +39,10 @@ packages=find_packages(), classifiers=[ "Development Status :: 5 - Production/Stable", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.11", "Intended Audience :: Developers", ], - python_requires=">=3.8", + python_requires=">=3.11,<3.12", install_requires=(TOP_DIR / "requirements.txt").read_text(), extras_require={"dev": (TOP_DIR / "requirements_dev.txt").read_text()}, entry_points={"console_scripts": ["push-action=push_action.run:main"]}, From d60e99f74b01bbc6abb7f54387673f968733dbeb Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen Date: Mon, 11 Dec 2023 14:06:24 +0100 Subject: [PATCH 2/2] Updates to codebase from pyupgrade run --- push_action/cache.py | 3 ++- push_action/run.py | 2 +- push_action/utils.py | 3 ++- push_action/validate.py | 2 +- setup.py | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/push_action/cache.py b/push_action/cache.py index b769c39..a7e4e80 100644 --- a/push_action/cache.py +++ b/push_action/cache.py @@ -7,7 +7,8 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: # pragma: no cover - from typing import Any, Iterator + from typing import Any + from collections.abc import Iterator class InMemoryCache: diff --git a/push_action/run.py b/push_action/run.py index d4c52b4..594862d 100644 --- a/push_action/run.py +++ b/push_action/run.py @@ -186,7 +186,7 @@ def unprotect_reviews() -> None: def protect_reviews() -> None: """Re-add pull request review protection for target branch""" # Retrieve data - with open("tmp_protection_rules.json", "r", encoding="utf8") as handle: + with open("tmp_protection_rules.json", encoding="utf8") as handle: data = json.load(handle) # Add protection diff --git a/push_action/utils.py b/push_action/utils.py index bc4e1e7..49e3427 100644 --- a/push_action/utils.py +++ b/push_action/utils.py @@ -21,7 +21,8 @@ from push_action.validate import validate_rest_api_base_url if TYPE_CHECKING: # pragma: no cover - from typing import Callable, List, Union + from typing import List, Union + from collections.abc import Callable LOGGER = logging.getLogger("push_action.utils") diff --git a/push_action/validate.py b/push_action/validate.py index 00acbc9..a2be3fc 100644 --- a/push_action/validate.py +++ b/push_action/validate.py @@ -40,7 +40,7 @@ def validate_conclusions(conclusions: list[str]) -> list[str]: ) # Remove redundant entries and conform to lowercase - conclusions = list(set(conclusion.lower() for conclusion in conclusions)) + conclusions = list({conclusion.lower() for conclusion in conclusions}) for conclusion in conclusions: invalid_conclusions: list[str] = [] diff --git a/setup.py b/setup.py index b5fe942..747404d 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ TOP_DIR = Path(__file__).parent.resolve() -with open(TOP_DIR / "push_action" / "__init__.py", "r", encoding="utf8") as handle: +with open(TOP_DIR / "push_action" / "__init__.py", encoding="utf8") as handle: for line in handle.readlines(): version = re.findall(r'__version__ = "(.*)"', line) if version: