diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b1e1e1e1..2f101744 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,10 +34,6 @@ repos: hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - - repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort - repo: https://github.com/psf/black rev: 24.10.0 hooks: diff --git a/Makefile b/Makefile index 054d1e8c..2bb23346 100644 --- a/Makefile +++ b/Makefile @@ -66,8 +66,8 @@ flake8-install: .PHONY: py-format-install py-format-install: - $(call check_pip_install,isort) $(call check_pip_install,black) + $(call check_pip_install,ruff) .PHONY: ruff-install ruff-install: @@ -156,10 +156,10 @@ flake8: flake8-install .PHONY: py-format py-format: py-format-install - $(PYTHON) -m isort --version $(PYTHON) -m black --version - $(PYTHON) -m isort --project $(PROJECT_PATH) --check $(PYTHON_FILES) && \ - $(PYTHON) -m black --check $(PYTHON_FILES) + $(PYTHON) -m ruff --version + $(PYTHON) -m black --check $(PYTHON_FILES) && \ + $(PYTHON) -m ruff check --select=I $(PYTHON_FILES) .PHONY: ruff ruff: ruff-install @@ -252,7 +252,6 @@ lint: ruff flake8 py-format mypy pylint doctest clang-format clang-tidy cpplint .PHONY: format format: py-format-install ruff-install clang-format-install addlicense-install - $(PYTHON) -m isort --project $(PROJECT_PATH) $(PYTHON_FILES) $(PYTHON) -m black $(PYTHON_FILES) $(PYTHON) -m ruff check --fix --exit-zero . $(CLANG_FORMAT) -style=file -i $(CXX_FILES) diff --git a/conda-recipe.yaml b/conda-recipe.yaml index f3d199dd..eca143aa 100644 --- a/conda-recipe.yaml +++ b/conda-recipe.yaml @@ -65,7 +65,6 @@ dependencies: - conda-forge::pytest - conda-forge::pytest-cov - conda-forge::pytest-xdist - - conda-forge::isort - conda-forge::black - conda-forge::pylint - conda-forge::mypy diff --git a/optree/functools.py b/optree/functools.py index e3351f4d..4a056685 100644 --- a/optree/functools.py +++ b/optree/functools.py @@ -18,8 +18,10 @@ import functools from typing import TYPE_CHECKING, Any, Callable, ClassVar -from typing_extensions import Self # Python 3.11+ -from typing_extensions import deprecated # Python 3.13+ +from typing_extensions import ( + Self, # Python 3.11+ + deprecated, # Python 3.13+ +) from optree import registry from optree.accessor import GetAttrEntry diff --git a/optree/registry.py b/optree/registry.py index e2a2978b..a445d48b 100644 --- a/optree/registry.py +++ b/optree/registry.py @@ -40,8 +40,10 @@ TypeVar, overload, ) -from typing_extensions import TypeAlias # Python 3.10+ -from typing_extensions import deprecated # Python 3.13+ +from typing_extensions import ( + TypeAlias, # Python 3.10+ + deprecated, # Python 3.13+ +) from optree import _C from optree.accessor import ( diff --git a/optree/typing.py b/optree/typing.py index 192052fb..939df3bc 100644 --- a/optree/typing.py +++ b/optree/typing.py @@ -47,10 +47,12 @@ ValuesView, runtime_checkable, ) -from typing_extensions import NamedTuple # Generic NamedTuple: Python 3.11+ -from typing_extensions import ParamSpec # Python 3.10+ -from typing_extensions import Self # Python 3.11+ -from typing_extensions import TypeAlias # Python 3.10+ +from typing_extensions import ( + NamedTuple, # Generic NamedTuple: Python 3.11+ + ParamSpec, # Python 3.10+ + Self, # Python 3.11+ + TypeAlias, # Python 3.10+ +) from optree import _C from optree._C import PyTreeKind, PyTreeSpec diff --git a/pyproject.toml b/pyproject.toml index 5cd86cca..8075bac7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,6 @@ jax = ["jax"] numpy = ["numpy"] torch = ["torch"] lint = [ - "isort", "black", "pylint[spelling]", "mypy", @@ -124,16 +123,6 @@ line-length = 100 skip-string-normalization = true target-version = ["py38"] -[tool.isort] -atomic = true -profile = "black" -src_paths = ["optree", "tests"] -extra_standard_library = ["typing_extensions"] -indent = 4 -line_length = 100 -lines_after_imports = 2 -multi_line_output = 3 - [tool.mypy] python_version = "3.8" exclude = ["^setup\\.py$", "^tests/.*\\.py$"] @@ -186,6 +175,7 @@ src = ["optree", "tests"] select = [ "E", "W", # pycodestyle "F", # pyflakes + "I", # isort "C90", # mccabe "N", # pep8-naming "UP", # pyupgrade @@ -272,6 +262,12 @@ typing-modules = ["optree.typing"] "ANN", # flake8-annotations ] +[tool.ruff.lint.isort] +known-first-party = ["optree"] +known-local-folder = ["optree", "tests"] +extra-standard-library = ["typing_extensions"] +lines-after-imports = 2 + [tool.ruff.lint.pydocstyle] convention = "google" diff --git a/tests/requirements.txt b/tests/requirements.txt index 8d8def5d..857e6777 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -3,7 +3,6 @@ pytest pytest-cov pytest-xdist -isort black pylint[spelling] mypy