From 35a786fb4686a84c1ea56ab3b9f9e9187a1ce81f Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Thu, 16 Feb 2023 05:03:50 +0000 Subject: [PATCH] deps(python): drop Python 3.7 support --- .github/workflows/build.yml | 18 +++++++++--------- .github/workflows/tests.yml | 8 ++++---- .pre-commit-config.yaml | 2 +- .pylintrc | 2 +- Makefile | 8 ++------ README.md | 2 +- conda-recipe.yaml | 2 +- docs/source/developer/contributing.rst | 4 ++-- pyproject.toml | 9 ++++----- tests/requirements.txt | 3 +-- torchopt/base.py | 3 +-- torchopt/diff/zero_order/decorator.py | 3 +-- torchopt/typing.py | 14 ++++++++++++-- torchopt/utils.py | 3 +-- 14 files changed, 41 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 12962111..98a0d620 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -56,7 +56,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.7 - 3.10" # sync with requires-python in pyproject.toml + python-version: "3.8 - 3.11" # sync with requires-python in pyproject.toml update-environment: true - name: Set __release__ @@ -96,14 +96,14 @@ jobs: run: | make pytest - build-wheels-py37: + build-wheels-py38: name: Build wheels for Python ${{ matrix.python-version }} on ubuntu-latest runs-on: ubuntu-latest needs: [build] if: github.repository == 'metaopt/torchopt' && (github.event_name != 'push' || startsWith(github.ref, 'refs/tags/')) strategy: matrix: - python-version: ["3.7"] # sync with requires-python in pyproject.toml + python-version: ["3.8"] # sync with requires-python in pyproject.toml fail-fast: false timeout-minutes: 60 steps: @@ -142,18 +142,18 @@ jobs: - uses: actions/upload-artifact@v3 with: - name: wheels-py37 + name: wheels-py38 path: wheelhouse/*.whl if-no-files-found: error build-wheels: name: Build wheels for Python ${{ matrix.python-version }} on ubuntu-latest runs-on: ubuntu-latest - needs: [build, build-wheels-py37] + needs: [build, build-wheels-py38] if: github.repository == 'metaopt/torchopt' && (github.event_name != 'push' || startsWith(github.ref, 'refs/tags/')) strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] # sync with requires-python in pyproject.toml + python-version: ["3.9", "3.10"] # sync with requires-python in pyproject.toml fail-fast: false timeout-minutes: 60 steps: @@ -198,7 +198,7 @@ jobs: publish: runs-on: ubuntu-latest - needs: [build, build-wheels-py37, build-wheels] + needs: [build, build-wheels-py38, build-wheels] if: | github.repository == 'metaopt/torchopt' && github.event_name != 'pull_request' && (github.event_name != 'workflow_dispatch' || github.event.inputs.task == 'build-and-publish') && @@ -215,7 +215,7 @@ jobs: uses: actions/setup-python@v4 if: startsWith(github.ref, 'refs/tags/') with: - python-version: "3.7 - 3.11" # sync with requires-python in pyproject.toml + python-version: "3.8 - 3.11" # sync with requires-python in pyproject.toml update-environment: true - name: Set __release__ @@ -249,7 +249,7 @@ jobs: with: # unpacks default artifact into dist/ # if `name: artifact` is omitted, the action will create extra parent dir - name: wheels-py37 + name: wheels-py38 path: dist - name: Download built wheels diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8bee5b9d..62bbc100 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,10 +41,10 @@ jobs: submodules: "recursive" fetch-depth: 1 - - name: Set up Python 3.7 + - name: Set up Python 3.8 uses: actions/setup-python@v4 with: - python-version: "3.7" # the lowest version we support (sync with requires-python in pyproject.toml) + python-version: "3.8" # the lowest version we support (sync with requires-python in pyproject.toml) update-environment: true - name: Setup CUDA Toolkit @@ -111,10 +111,10 @@ jobs: submodules: "recursive" fetch-depth: 1 - - name: Set up Python 3.7 + - name: Set up Python 3.8 uses: actions/setup-python@v4 with: - python-version: "3.7" # the lowest version we support (sync with requires-python in pyproject.toml) + python-version: "3.8" # the lowest version we support (sync with requires-python in pyproject.toml) update-environment: true - name: Upgrade pip diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 66f0bdf0..3b938719 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -42,7 +42,7 @@ repos: rev: v3.3.1 hooks: - id: pyupgrade - args: [--py37-plus] # sync with requires-python + args: [--py38-plus] # sync with requires-python stages: [commit, push, manual] exclude: | (?x)( diff --git a/.pylintrc b/.pylintrc index accc71d5..a21967ee 100644 --- a/.pylintrc +++ b/.pylintrc @@ -84,7 +84,7 @@ persistent=yes # Minimum Python version to use for version dependent checks. Will default to # the version used to run pylint. -py-version=3.7 # the lowest version we support (sync with requires-python in pyproject.toml) +py-version=3.8 # the lowest version we support (sync with requires-python in pyproject.toml) # Discover python modules and packages in the file system subtree. recursive=no diff --git a/Makefile b/Makefile index f856cb21..51fb431f 100644 --- a/Makefile +++ b/Makefile @@ -61,11 +61,7 @@ pre-commit-install: docs-install: $(call check_pip_install_extra,pydocstyle,pydocstyle[toml]) - $(call check_pip_install_extra,doc8,"doc8<1.0.0a0") - if ! $(PYTHON) -c "import sys; exit(sys.version_info < (3, 8))"; then \ - $(PYTHON) -m pip uninstall --yes importlib-metadata; \ - $(call check_pip_install_extra,importlib-metadata,"importlib-metadata<5.0.0a0"); \ - fi + $(call check_pip_install,doc8) $(call check_pip_install,sphinx) $(call check_pip_install,sphinx-rtd-theme) $(call check_pip_install,sphinx-autoapi) @@ -75,7 +71,7 @@ docs-install: $(call check_pip_install,sphinxcontrib-bibtex) $(call check_pip_install,sphinx-autodoc-typehints) $(call check_pip_install,myst-nb) - $(call check_pip_install_extra,sphinxcontrib.spelling,sphinxcontrib.spelling pyenchant) + $(call check_pip_install_extra,sphinxcontrib-spelling,sphinxcontrib-spelling pyenchant) pytest-install: $(call check_pip_install,pytest) diff --git a/README.md b/README.md index 321f39e3..bb1c4be5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@
- ![Python 3.7+](https://img.shields.io/badge/Python-3.7%2B-brightgreen.svg) + ![Python 3.8+](https://img.shields.io/badge/Python-3.8%2B-brightgreen.svg) ![PyPI](https://img.shields.io/pypi/v/torchopt?logo=pypi) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/metaopt/torchopt/tests.yml?label=tests&logo=github) ![CodeCov](https://img.shields.io/codecov/c/gh/metaopt/torchopt) diff --git a/conda-recipe.yaml b/conda-recipe.yaml index faee0a7c..808583b0 100644 --- a/conda-recipe.yaml +++ b/conda-recipe.yaml @@ -90,7 +90,7 @@ dependencies: - mypy >= 0.990 - flake8 - flake8-bugbear - - doc8 < 1.0.0a0 + - doc8 - pydocstyle - clang-format >= 14 - clang-tools >= 14 # clang-tidy diff --git a/docs/source/developer/contributing.rst b/docs/source/developer/contributing.rst index ee66f560..8cea9406 100644 --- a/docs/source/developer/contributing.rst +++ b/docs/source/developer/contributing.rst @@ -102,9 +102,9 @@ For example, the following command will build a wheel for Python 3.7: .. code-block:: bash - CIBW_BUILD="cp37*manylinux*" python3 -m cibuildwheel --platform=linux --output-dir=wheelhouse --config-file=pyproject.toml + CIBW_BUILD="cp38*manylinux*" python3 -m cibuildwheel --platform=linux --output-dir=wheelhouse --config-file=pyproject.toml -You can change ``cp37*`` to ``cp310*`` to build for Python 3.10. See https://cibuildwheel.readthedocs.io/en/stable/options for more options. +You can change ``cp38*`` to ``cp310*`` to build for Python 3.10. See https://cibuildwheel.readthedocs.io/en/stable/options for more options. .. |cibuildwheel| replace:: ``cibuildwheel`` .. _cibuildwheel: https://github.com/pypa/cibuildwheel diff --git a/pyproject.toml b/pyproject.toml index 12fd6fe3..e63890d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ description = "An efficient library for differentiable optimization for PyTorch. readme = "README.md" # Change this if wheels for `torch` is available # Search "requires-python" and update all corresponding items -requires-python = ">= 3.7" +requires-python = ">= 3.8" authors = [ { name = "TorchOpt Contributors" }, { name = "Jie Ren", email = "jieren9806@gmail.com" }, @@ -34,7 +34,6 @@ classifiers = [ "License :: OSI Approved :: Apache Software License", # Sync with requires-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", @@ -74,7 +73,7 @@ lint = [ "mypy >= 0.990", "flake8", "flake8-bugbear", - "doc8 < 1.0.0a0", # unpin this when we drop support for Python 3.7 + "doc8", "pydocstyle[toml]", "pyenchant", "cpplint", @@ -170,7 +169,7 @@ safe = true line-length = 100 skip-string-normalization = true # Sync with requires-python -target-version = ["py37", "py38", "py39", "py310", "py311"] +target-version = ["py38", "py39", "py310", "py311"] [tool.isort] atomic = true @@ -184,7 +183,7 @@ multi_line_output = 3 [tool.mypy] # Sync with requires-python -python_version = 3.7 +python_version = 3.8 pretty = true show_error_codes = true show_error_context = true diff --git a/tests/requirements.txt b/tests/requirements.txt index 6706dca5..e62c9ed5 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -16,8 +16,7 @@ pylint[spelling] >= 2.15.0 mypy >= 0.990 flake8 flake8-bugbear -# https://github.com/PyCQA/doc8/issues/112 -doc8 < 1.0.0a0 +doc8 pydocstyle[toml] pyenchant cpplint diff --git a/torchopt/base.py b/torchopt/base.py index b250c387..edd9ce24 100644 --- a/torchopt/base.py +++ b/torchopt/base.py @@ -35,8 +35,7 @@ import itertools from abc import abstractmethod -from typing import TYPE_CHECKING, Callable, NamedTuple -from typing_extensions import Protocol # Python 3.8+ +from typing import TYPE_CHECKING, Callable, NamedTuple, Protocol if TYPE_CHECKING: # pragma: no cover diff --git a/torchopt/diff/zero_order/decorator.py b/torchopt/diff/zero_order/decorator.py index 43522028..4726c83b 100644 --- a/torchopt/diff/zero_order/decorator.py +++ b/torchopt/diff/zero_order/decorator.py @@ -17,8 +17,7 @@ from __future__ import annotations import functools -from typing import Any, Callable, Sequence -from typing_extensions import Literal # Python 3.8+ +from typing import Any, Callable, Literal, Sequence from typing_extensions import TypeAlias # Python 3.10+ import torch diff --git a/torchopt/typing.py b/torchopt/typing.py index 2075dc62..8895c6a1 100644 --- a/torchopt/typing.py +++ b/torchopt/typing.py @@ -15,9 +15,19 @@ """Typing utilities.""" import abc -from typing import Callable, Dict, List, Optional, Sequence, Tuple, TypeVar, Union +from typing import ( + Callable, + Dict, + List, + Optional, + Protocol, + Sequence, + Tuple, + TypeVar, + Union, + runtime_checkable, +) from typing_extensions import TypeAlias # Python 3.10+ -from typing_extensions import Protocol, runtime_checkable # Python 3.8+ import torch import torch.distributed.rpc as rpc diff --git a/torchopt/utils.py b/torchopt/utils.py index 12adb214..a1885a7b 100644 --- a/torchopt/utils.py +++ b/torchopt/utils.py @@ -18,8 +18,7 @@ import copy import itertools -from typing import TYPE_CHECKING, NamedTuple, Sequence, cast, overload -from typing_extensions import Literal # Python 3.8+ +from typing import TYPE_CHECKING, Literal, NamedTuple, Sequence, cast, overload from typing_extensions import TypeAlias # Python 3.10+ import torch