From d50317c700cd2d14ea7d2fe8d71f194f10cb2616 Mon Sep 17 00:00:00 2001 From: Jeremy Maitin-Shepard Date: Wed, 10 Jul 2024 14:48:30 -0700 Subject: [PATCH] Drop Python 3.8 support --- .github/workflows/build.yml | 70 +++++++++---------- docs/test_py_module/test.py | 11 ++- noxfile.py | 2 +- setup.py | 2 +- .../python/type_annotation_transforms.py | 42 +---------- 5 files changed, 40 insertions(+), 87 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e6beaf540..19c9b2219 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ on: - main workflow_dispatch: schedule: - - cron: '0 0 1,16 * *' + - cron: "0 0 1,16 * *" jobs: check_conventions: @@ -20,19 +20,17 @@ jobs: fail-fast: false matrix: include: - - nox-sessions: 'black check_yaml check_json check_toml check_eof check_trailing_space check_lf' - python-version: '3.x' - node-version: '16.x' - - nox-sessions: 'mypy pylint' - python-version: '3.8' - - nox-sessions: 'mypy pylint' - python-version: '3.9' - - nox-sessions: 'mypy pylint' - python-version: '3.10' - - nox-sessions: 'mypy pylint' - python-version: '3.11' - - nox-sessions: 'mypy pylint' - python-version: '3.12' + - nox-sessions: "black check_yaml check_json check_toml check_eof check_trailing_space check_lf" + python-version: "3.x" + node-version: "16.x" + - nox-sessions: "mypy pylint" + python-version: "3.9" + - nox-sessions: "mypy pylint" + python-version: "3.10" + - nox-sessions: "mypy pylint" + python-version: "3.11" + - nox-sessions: "mypy pylint" + python-version: "3.12" steps: - uses: actions/checkout@v4 - name: Setup Node.js @@ -71,13 +69,13 @@ jobs: fail-fast: false matrix: os: - - 'ubuntu-latest' - - 'windows-latest' - - 'macos-latest' + - "ubuntu-latest" + - "windows-latest" + - "macos-latest" python-version: - - '3.x' + - "3.x" node-version: - - '16.x' + - "16.x" runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -116,7 +114,7 @@ jobs: - name: Setup Graphviz uses: ts-graphviz/setup-graphviz@b1de5da23ed0a6d14e0aeee8ed52fdd87af2363c # v2.0.2 with: - macos-skip-brew-update: 'true' + macos-skip-brew-update: "true" - uses: actions/cache@v4 with: path: ${{ github.workspace }}/theme_build_cache @@ -143,25 +141,21 @@ jobs: fail-fast: false matrix: os: - - 'ubuntu-latest' - - 'windows-latest' - - 'macos-latest' + - "ubuntu-latest" + - "windows-latest" + - "macos-latest" python-version: - - '3.8' - - '3.9' - - '3.10' - - '3.11' - - '3.12' + - "3.9" + - "3.10" + - "3.11" + - "3.12" sphinx-version: - - 'sphinx4' - - 'sphinx5' - - 'sphinx6' - - 'sphinx7' + - "sphinx4" + - "sphinx5" + - "sphinx6" + - "sphinx7" node-version: - - '16.x' - exclude: - - python-version: '3.8' - sphinx-version: 'sphinx7' + - "16.x" runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -183,7 +177,7 @@ jobs: - name: Setup Graphviz uses: ts-graphviz/setup-graphviz@b1de5da23ed0a6d14e0aeee8ed52fdd87af2363c # v2.0.2 with: - macos-skip-brew-update: 'true' + macos-skip-brew-update: "true" - uses: actions/cache/restore@v4 with: path: ${{ github.workspace }}/theme_build_cache @@ -214,7 +208,7 @@ jobs: - name: Setup python uses: actions/setup-python@v5 with: - python-version: '3.x' + python-version: "3.x" - name: Create coverage report run: pipx run nox -s coverage - name: Upload comprehensive coverage HTML report diff --git a/docs/test_py_module/test.py b/docs/test_py_module/test.py index c288ce2d1..1782eef09 100644 --- a/docs/test_py_module/test.py +++ b/docs/test_py_module/test.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- """Test Module for sphinx_rtd_theme.""" import functools -import sys from typing import Union @@ -120,12 +119,10 @@ def qux_caps(self) -> str: """Return the instance qux as uppercase.""" return self.capitalize(self.qux) - if sys.version_info >= (3, 8): - - @functools.cached_property - def qux_caps_cached(self) -> str: - """Return the cached value of instance qux as uppercase.""" - return self.qux_caps + @functools.cached_property + def qux_caps_cached(self) -> str: + """Return the cached value of instance qux as uppercase.""" + return self.qux_caps def func(long: int, param: str, args: None, flags: bool, lists: Union[list, tuple]): diff --git a/noxfile.py b/noxfile.py index b874de5e4..29695549b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -17,7 +17,7 @@ "check_lf", ] -SUPPORTED_PY_VER = list(f"3.{x}" for x in range(8, 13)) +SUPPORTED_PY_VER = list(f"3.{x}" for x in range(9, 13)) @nox.session diff --git a/setup.py b/setup.py index bc7e38c81..6eecd502c 100644 --- a/setup.py +++ b/setup.py @@ -198,7 +198,7 @@ def run(self): ], "sphinx_immaterial.apidoc.cpp.cppreference_data": ["*.xml"], }, - python_requires=">=3.8", + python_requires=">=3.9", install_requires=REQUIREMENTS, use_scm_version={ # It would be nice to include the commit hash in the version, but that diff --git a/sphinx_immaterial/apidoc/python/type_annotation_transforms.py b/sphinx_immaterial/apidoc/python/type_annotation_transforms.py index 5d2b6e229..a9db75c87 100644 --- a/sphinx_immaterial/apidoc/python/type_annotation_transforms.py +++ b/sphinx_immaterial/apidoc/python/type_annotation_transforms.py @@ -3,7 +3,6 @@ import ast import functools import re -import sys from typing import ( cast, Dict, @@ -23,30 +22,6 @@ import sphinx.environment import sphinx.util.logging -# `ast.unparse` added in Python 3.9 -if sys.version_info >= (3, 9): - from ast import unparse as ast_unparse -else: - from sphinx.pycode.ast import unparse as ast_unparse - from sphinx.pycode.ast import _UnparseVisitor - - def _monkey_patch_sphinx_ast_unparse(): - """Monkey patch Sphinx's `ast_unparse`. - - This adds support for some additional ast nodes that we require. - """ - - def visit_Module(self: _UnparseVisitor, node: ast.Module) -> str: - return "\n".join(self.visit(el) for el in node.body) - - def visit_Expr(self: _UnparseVisitor, node: ast.Expr) -> str: - return self.visit(node.value) - - _UnparseVisitor.visit_Module = visit_Module # type: ignore[assignment] - _UnparseVisitor.visit_Expr = visit_Expr # type: ignore[assignment] - - _monkey_patch_sphinx_ast_unparse() - logger = sphinx.util.logging.getLogger(__name__) PEP585_ALIASES = { @@ -128,19 +103,6 @@ def _dotted_name_to_ast( return tree -if sys.version_info < (3, 8): - _CONSTANT_AST_NODE_TYPES = ( - ast.Constant, - ast.Num, - ast.Str, - ast.Bytes, - ast.Ellipsis, - ast.NameConstant, - ) -else: - _CONSTANT_AST_NODE_TYPES = (ast.Constant,) - - _CONFIG_ATTR = "_sphinx_immaterial_python_type_transform_config" @@ -173,7 +135,7 @@ def _retain_explicit_literal(node: ast.AST) -> bool: Since constants cannot be types, there is no ambiguity. """ - return not isinstance(node, _CONSTANT_AST_NODE_TYPES) + return not isinstance(node, ast.Constant) class TypeAnnotationTransformer(ast.NodeTransformer): @@ -266,7 +228,7 @@ def _parse_annotation(annotation: str, env: sphinx.environment.BuildEnvironment) transformer = TypeAnnotationTransformer() transformer.config = cast(TypeTransformConfig, transformer_config) tree = ast.fix_missing_locations(transformer.visit(tree)) - annotation = ast_unparse(tree) + annotation = ast.unparse(tree) return orig_parse_annotation(annotation, env) if sphinx.version_info >= (7, 3):