diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 12962111..bd294b03 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.10" # 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 59678338..4f6fad50 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/.gitignore b/.gitignore index 450d7b0c..350ddfb2 100644 --- a/.gitignore +++ b/.gitignore @@ -146,6 +146,9 @@ venv.bak/ # mkdocs documentation /site +# ruff +.ruff_cache/ + # mypy .mypy_cache/ .dmypy.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4e5ddd14..f943f89f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -48,7 +48,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/CHANGELOG.md b/CHANGELOG.md index 4b2a2899..3a884496 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed -- +- Drop Python 3.7 support by [@XuehaiPan](https://github.com/XuehaiPan) in [#136](https://github.com/metaopt/torchopt/pull/136). ------ diff --git a/Makefile b/Makefile index 750b9d9f..bd839812 100644 --- a/Makefile +++ b/Makefile @@ -68,11 +68,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) @@ -202,6 +198,7 @@ format: py-format-install ruff-install clang-format-install addlicense-install clean-py: find . -type f -name '*.py[co]' -delete find . -depth -type d -name "__pycache__" -exec rm -r "{}" + + find . -depth -type d -name ".ruff_cache" -exec rm -r "{}" + find . -depth -type d -name ".mypy_cache" -exec rm -r "{}" + find . -depth -type d -name ".pytest_cache" -exec rm -r "{}" + rm tests/.coverage diff --git a/README.md b/README.md index 8c8bd8f6..fe149970 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/github/metaopt/torchopt/main?logo=codecov) diff --git a/docs/source/developer/contributing.rst b/docs/source/developer/contributing.rst index ce11e20e..4e7dd355 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 eb3a19ae..a6a2ae77 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", @@ -79,7 +78,7 @@ lint = [ "flake8-pyi", "flake8-simplify", "ruff", - "doc8 < 1.0.0a0", # unpin this when we drop support for Python 3.7 + "doc8", "pydocstyle[toml]", "pyenchant", "cpplint", @@ -175,7 +174,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 @@ -189,7 +188,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 @@ -216,7 +215,7 @@ max-line-length = 500 [tool.ruff] # Sync with requires-python -target-version = "py37" +target-version = "py38" line-length = 100 show-source = true src = ["torchopt", "tests"] diff --git a/tests/requirements.txt b/tests/requirements.txt index 1d12cc79..87c994e1 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -21,8 +21,7 @@ flake8-docstrings flake8-pyi flake8-simplify ruff -# 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 dd0bd925..7678d543 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 2f677518..c6e5e92c 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 dd563bb6..6cd6cf67 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 6afe08e7..b56231c6 100644 --- a/torchopt/utils.py +++ b/torchopt/utils.py @@ -18,8 +18,7 @@ import copy import itertools -from typing import TYPE_CHECKING, Any, NamedTuple, Sequence, cast, overload -from typing_extensions import Literal # Python 3.8+ +from typing import TYPE_CHECKING, Any, Literal, NamedTuple, Sequence, cast, overload from typing_extensions import TypeAlias # Python 3.10+ import torch