Skip to content

Commit

Permalink
MAINT: drop Python 3.7 & 3.8 support due to EOL (#418)
Browse files Browse the repository at this point in the history
* DX: run label sync on Python 3.12
* MAINT: modernize Python syntax to Python 3.9
* MAINT: switch to single quotation marks for sorting
  • Loading branch information
redeboer authored Oct 11, 2024
1 parent a4b371c commit 9d7f6f1
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sync-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.7"
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python",
"Typing :: Typed",
Expand All @@ -30,17 +28,17 @@ dependencies = [
"nbformat",
"pathspec",
"pip-tools",
"rtoml", # fast, read-only parsing
"ruamel.yaml", # better YAML dumping
"tomlkit", # preserve original TOML formatting
'rtoml', # fast, read-only parsing
'typing-extensions; python_version <"3.12.0"', # override
]
description = "Pre-commit hooks that ensure that ComPWA repositories have a similar developer set-up"
dynamic = ["version"]
license = {text = "BSD 3-Clause License"}
maintainers = [{email = "compwa-admin@ep1.rub.de"}]
name = "compwa-policy"
requires-python = ">=3.7"
requires-python = ">=3.9"

[project.optional-dependencies]
dev = [
Expand All @@ -50,7 +48,6 @@ dev = [
"labels",
"sphinx-autobuild",
"tox >=1.9", # for skip_install, use_develop
'sphinx-autobuild!=2024.4.*; python_version <"3.10.0"',
]
doc = [
"Sphinx",
Expand Down
11 changes: 7 additions & 4 deletions src/compwa_policy/check_dev_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
from argparse import ArgumentParser
from textwrap import dedent
from typing import TYPE_CHECKING, Any, Sequence
from typing import TYPE_CHECKING, Any

from compwa_policy.check_dev_files import (
black,
Expand Down Expand Up @@ -42,6 +42,8 @@
from compwa_policy.utilities.precommit import ModifiablePrecommit

if TYPE_CHECKING:
from collections.abc import Sequence

from compwa_policy.utilities.pyproject import PythonVersion


Expand All @@ -57,9 +59,10 @@ def main(argv: Sequence[str] | None = None) -> int:
package_managers: set[conda.PackageManagerChoice] = set(
_to_list(args.package_managers) # type: ignore[arg-type]
)
with Executor(
raise_exception=False
) as do, ModifiablePrecommit.load() as precommit_config:
with (
Executor(raise_exception=False) as do,
ModifiablePrecommit.load() as precommit_config,
):
do(citation.main, precommit_config)
do(commitlint.main)
do(conda.main, dev_python_version, package_managers)
Expand Down
8 changes: 1 addition & 7 deletions src/compwa_policy/check_dev_files/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from __future__ import annotations

import sys
from typing import NoReturn
from typing import Literal, NoReturn

from ruamel.yaml.comments import CommentedMap, CommentedSeq
from ruamel.yaml.scalarstring import PlainScalarString
Expand All @@ -18,11 +17,6 @@
)
from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal

PackageManagerChoice = Literal["conda", "pixi", "uv", "venv"]
"""Package managers you want to develop the project with."""

Expand Down
3 changes: 2 additions & 1 deletion src/compwa_policy/check_dev_files/cspell.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import json
import os
from typing import TYPE_CHECKING, Any, Iterable, Sequence
from typing import TYPE_CHECKING, Any

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import COMPWA_POLICY_DIR, CONFIG_PATH, rename_file, vscode
Expand All @@ -18,6 +18,7 @@
from compwa_policy.utilities.readme import add_badge, remove_badge

if TYPE_CHECKING:
from collections.abc import Iterable, Sequence
from pathlib import Path

from compwa_policy.utilities.precommit import ModifiablePrecommit
Expand Down
7 changes: 1 addition & 6 deletions src/compwa_policy/check_dev_files/dependabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

from __future__ import annotations

import sys
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Literal

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import COMPWA_POLICY_DIR, CONFIG_PATH

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
if TYPE_CHECKING:
from pathlib import Path

Expand Down
4 changes: 3 additions & 1 deletion src/compwa_policy/check_dev_files/precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import re
from pathlib import Path
from typing import TYPE_CHECKING, Any, MutableMapping, cast
from typing import TYPE_CHECKING, Any, cast

from ruamel.yaml.comments import CommentedMap, CommentedSeq

Expand All @@ -21,6 +21,8 @@
from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml

if TYPE_CHECKING:
from collections.abc import MutableMapping

from compwa_policy.utilities.precommit import (
ModifiablePrecommit,
Precommit,
Expand Down
4 changes: 3 additions & 1 deletion src/compwa_policy/check_dev_files/prettier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
from __future__ import annotations

import os
from typing import TYPE_CHECKING, Iterable
from typing import TYPE_CHECKING

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import COMPWA_POLICY_DIR, CONFIG_PATH, vscode
from compwa_policy.utilities.executor import Executor
from compwa_policy.utilities.readme import add_badge, remove_badge

if TYPE_CHECKING:
from collections.abc import Iterable

from compwa_policy.utilities.precommit import ModifiablePrecommit

# cspell:ignore esbenp rettier
Expand Down
4 changes: 3 additions & 1 deletion src/compwa_policy/check_dev_files/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Iterable
from typing import TYPE_CHECKING

import rtoml
from ini2toml.api import Translator
Expand All @@ -14,6 +14,8 @@
from compwa_policy.utilities.toml import to_toml_array

if TYPE_CHECKING:
from collections.abc import Iterable

from tomlkit.items import Array


Expand Down
2 changes: 1 addition & 1 deletion src/compwa_policy/check_dev_files/pyupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __get_pyupgrade_version_argument() -> CommentedSeq:
"""Get the --py3x-plus argument for pyupgrade.
>>> __get_pyupgrade_version_argument()
['--py37-plus']
['--py39-plus']
"""
supported_python_versions = Pyproject.load().get_supported_python_versions()
lowest_version = supported_python_versions[0]
Expand Down
6 changes: 4 additions & 2 deletions src/compwa_policy/check_dev_files/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
from collections import abc
from typing import TYPE_CHECKING, Any, Iterable, Mapping
from typing import TYPE_CHECKING, Any

from ruamel.yaml import YAML

Expand All @@ -22,6 +22,8 @@
from compwa_policy.utilities.toml import to_toml_array

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping

from tomlkit.items import Array

from compwa_policy.utilities.precommit import ModifiablePrecommit
Expand Down Expand Up @@ -254,7 +256,7 @@ def ___get_target_version(pyproject: Pyproject) -> str:
>>> pyproject = Pyproject.load()
>>> ___get_target_version(pyproject)
'py37'
'py39'
"""
supported_python_versions = pyproject.get_supported_python_versions()
versions = {f'py{v.replace(".", "")}' for v in supported_python_versions}
Expand Down
8 changes: 1 addition & 7 deletions src/compwa_policy/check_dev_files/update_pip_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from __future__ import annotations

import sys
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Literal

from compwa_policy.check_dev_files.github_workflows import (
remove_workflow,
Expand All @@ -23,11 +22,6 @@
if TYPE_CHECKING:
from compwa_policy.utilities.precommit import Precommit

if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal


Frequency = Literal[
"no",
Expand Down
5 changes: 4 additions & 1 deletion src/compwa_policy/colab_toc_visible.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

import argparse
import sys
from typing import Sequence
from typing import TYPE_CHECKING

import nbformat

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities.executor import Executor
from compwa_policy.utilities.notebook import load_notebook

if TYPE_CHECKING:
from collections.abc import Sequence


def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(__doc__)
Expand Down
5 changes: 4 additions & 1 deletion src/compwa_policy/fix_nbformat_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import argparse
import sys
from textwrap import dedent
from typing import Sequence
from typing import TYPE_CHECKING

import nbformat

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities.executor import Executor
from compwa_policy.utilities.notebook import load_notebook

if TYPE_CHECKING:
from collections.abc import Sequence

BINARY_CELL_OUTPUT = [
"image/jpeg",
"image/png",
Expand Down
5 changes: 4 additions & 1 deletion src/compwa_policy/remove_empty_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

import argparse
import sys
from typing import Sequence
from typing import TYPE_CHECKING

import nbformat

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities.executor import Executor
from compwa_policy.utilities.notebook import load_notebook

if TYPE_CHECKING:
from collections.abc import Sequence


def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(__doc__)
Expand Down
5 changes: 4 additions & 1 deletion src/compwa_policy/set_nb_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import sys
from functools import lru_cache
from textwrap import dedent
from typing import Sequence
from typing import TYPE_CHECKING

import nbformat

from compwa_policy.utilities.notebook import load_notebook
from compwa_policy.utilities.pyproject import Pyproject

if TYPE_CHECKING:
from collections.abc import Sequence

__CONFIG_CELL_CONTENT = """
import os
Expand Down
5 changes: 4 additions & 1 deletion src/compwa_policy/utilities/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import re
from configparser import ConfigParser
from pathlib import Path
from typing import Callable, Iterable
from typing import TYPE_CHECKING, Callable

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import read, write

if TYPE_CHECKING:
from collections.abc import Iterable


def format_config(
input: Path | io.TextIOBase | str, # noqa: A002
Expand Down
10 changes: 3 additions & 7 deletions src/compwa_policy/utilities/precommit/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
from __future__ import annotations

import sys
from functools import lru_cache
from typing import ForwardRef
from functools import cache
from typing import ForwardRef, Literal, TypedDict

if sys.version_info < (3, 8):
from typing_extensions import Literal, TypedDict
else:
from typing import Literal, TypedDict
if sys.version_info < (3, 11):
from typing_extensions import NotRequired
else:
Expand Down Expand Up @@ -76,7 +72,7 @@ def validate(config: PrecommitConfig) -> None:
raise ValueError(msg)


@lru_cache(maxsize=None)
@cache
def _get_required_keys(struct: type) -> set[str]:
annotations: dict[str, ForwardRef] = struct.__annotations__
return {
Expand Down
Loading

0 comments on commit 9d7f6f1

Please sign in to comment.