Skip to content

Commit

Permalink
deps(python): drop Python 3.7 support (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan authored Feb 20, 2023
1 parent 14962cf commit 3aa3fba
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 40 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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') &&
Expand All @@ -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__
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ venv.bak/
# mkdocs documentation
/site

# ruff
.ruff_cache/

# mypy
.mypy_cache/
.dmypy.json
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)(
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

------

Expand Down
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<div align="center">

<a>![Python 3.7+](https://img.shields.io/badge/Python-3.7%2B-brightgreen.svg)</a>
<a>![Python 3.8+](https://img.shields.io/badge/Python-3.8%2B-brightgreen.svg)</a>
<a href="https://pypi.org/project/torchopt">![PyPI](https://img.shields.io/pypi/v/torchopt?logo=pypi)</a>
<a href="https://github.com/metaopt/torchopt/tree/HEAD/tests">![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/metaopt/torchopt/tests.yml?label=tests&logo=github)</a>
<a href="https://codecov.io/gh/metaopt/torchopt">![CodeCov](https://img.shields.io/codecov/c/github/metaopt/torchopt/main?logo=codecov)</a>
Expand Down
4 changes: 2 additions & 2 deletions docs/source/developer/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"]
Expand Down
3 changes: 1 addition & 2 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions torchopt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions torchopt/diff/zero_order/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions torchopt/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions torchopt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3aa3fba

Please # to comment.