Skip to content

Commit 49ba409

Browse files
authored
Replace isort with Ruff (#10912)
1 parent 77bccbe commit 49ba409

12 files changed

+29
-50
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ repos:
1414
hooks:
1515
- id: black
1616
language_version: python3.10
17-
- repo: https://github.com/pycqa/isort
18-
rev: 5.12.0 # must match requirements-tests.txt
19-
hooks:
20-
- id: isort
21-
name: isort (python)
2217
- repo: https://github.com/astral-sh/ruff-pre-commit
2318
rev: v0.1.0 # must match requirements-tests.txt and tests.yml
2419
hooks:

.vscode/extensions.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"editorconfig.editorconfig",
88
"ms-python.black-formatter",
99
"ms-python.flake8",
10-
"ms-python.isort",
1110
"ms-python.mypy-type-checker",
1211
"ms-python.python",
1312
"ms-python.vscode-pylance",
@@ -16,17 +15,19 @@
1615
],
1716
"unwantedRecommendations": [
1817
/*
19-
* Don't recommend by default for this workspace
18+
* Don't recommend by default for this workspace
2019
*/
2120
"christian-kohler.npm-intellisense",
2221
/*
23-
* Must disable in this workspace
24-
* https://github.com/microsoft/vscode/issues/40239
22+
* Must disable in this workspace
23+
* https://github.com/microsoft/vscode/issues/40239
2524
*/
2625
// even-better-toml has format on save
2726
"bungcip.better-toml",
2827
// Don't use two mypy extensions simultaneously
2928
"matangover.mypy",
29+
// Use Ruff instead
30+
"ms-python.isort",
3031
// We use Black
3132
"ms-python.autopep8",
3233
// Not using pylint

.vscode/settings.default.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
"python.linting.prospectorEnabled": false,
8181
"python.linting.pylamaEnabled": false,
8282
"python.linting.pylintEnabled": false,
83-
// Not using bandit
8483
"python.linting.banditEnabled": false,
8584
// python.analysis is Pylance (pyright) configurations
8685
"python.analysis.fixAll": [
@@ -109,13 +108,12 @@
109108
"--config=.flake8"
110109
],
111110
"flake8.importStrategy": "fromEnvironment",
112-
"isort.check": true,
113-
"isort.importStrategy": "fromEnvironment",
114111
"black-formatter.importStrategy": "fromEnvironment",
112+
// Using Ruff instead of isort
113+
"isort.check": false,
115114
"ruff.importStrategy": "fromEnvironment",
116115
"ruff.fixAll": true,
117-
// Conflict between Ruff and isort
118-
"ruff.organizeImports": false,
116+
"ruff.organizeImports": true,
119117
"evenBetterToml.formatter.alignComments": false,
120118
"evenBetterToml.formatter.alignEntries": false,
121119
"evenBetterToml.formatter.allowedBlankLines": 1,

CONTRIBUTING.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ Typeshed runs continuous integration (CI) on all pull requests. This means that
3030
if you file a pull request (PR), our full test suite
3131
-- including our linter, [Flake8](https://github.com/PyCQA/flake8) --
3232
is run on your PR. It also means that bots will automatically apply
33-
changes to your PR (using [Black](https://github.com/psf/black),
34-
[isort](https://github.com/PyCQA/isort) and
33+
changes to your PR (using [Black](https://github.com/psf/black) and
3534
[Ruff](https://github.com/astral-sh/ruff)) to fix any formatting issues.
3635
This frees you up to ignore all local setup on your side, focus on the
3736
code and rely on the CI to fix everything, or point you to the places that
@@ -87,8 +86,7 @@ terminal to install all non-pytype requirements:
8786

8887
## Code formatting
8988

90-
The code is formatted using [`Black`](https://github.com/psf/black)
91-
and [`isort`](https://github.com/PyCQA/isort).
89+
The code is formatted using [`Black`](https://github.com/psf/black).
9290
Various other autofixes are
9391
also performed by [`Ruff`](https://github.com/astral-sh/ruff).
9492

@@ -101,8 +99,7 @@ That being said, if you *want* to run the checks locally when you commit,
10199
you're free to do so. Either run the following manually...
102100

103101
```bash
104-
(.venv)$ isort .
105-
(.venv)$ ruff .
102+
(.venv)$ ruff check .
106103
(.venv)$ black .
107104
```
108105

pyproject.toml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ skip_magic_trailing_comma = true
77
# for just these files, but doesn't seem possible yet.
88
force-exclude = ".*_pb2.pyi"
99

10-
[tool.isort]
11-
profile = "black"
12-
combine_as_imports = true
13-
line_length = 130
14-
skip = [".git", ".github", ".venv"]
15-
extra_standard_library = [
10+
[tool.ruff.isort]
11+
split-on-trailing-comma = false
12+
combine-as-imports = true
13+
extra-standard-library = [
1614
"_typeshed",
1715
"typing_extensions",
18-
# Extra modules not recognized by isort
16+
# Extra modules not recognized by Ruff/isort
1917
"_ast",
2018
"_bisect",
2119
"_bootlocale",
@@ -56,7 +54,7 @@ extra_standard_library = [
5654
"opcode",
5755
"pyexpat",
5856
]
59-
known_first_party = ["parse_metadata", "utils"]
57+
known-first-party = ["parse_metadata", "utils"]
6058

6159
[tool.ruff]
6260
line-length = 130
@@ -75,12 +73,11 @@ exclude = [
7573
".venv",
7674
"env",
7775
]
78-
79-
# Only enable rules that have safe autofixes;
80-
# only enable rules that are relevant to stubs
8176
select = [
82-
"F401", # Remove unused imports
8377
"FA", # flake8-future-annotations
78+
"I", # isort
79+
# Only enable rules that have safe autofixes:
80+
"F401", # Remove unused imports
8481
"PYI009", # use `...`, not `pass`, in empty class bodies
8582
"PYI010", # function bodies must be empty
8683
"PYI012", # class bodies must not contain `pass`

requirements-tests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ flake8==6.1.0 # must match .pre-commit-config.yaml
66
flake8-bugbear==23.9.16 # must match .pre-commit-config.yaml
77
flake8-noqa==1.3.2 # must match .pre-commit-config.yaml
88
flake8-pyi==23.10.0 # must match .pre-commit-config.yaml
9-
isort==5.12.0 # must match .pre-commit-config.yaml
109
mypy==1.6.1
1110
pre-commit-hooks==4.5.0 # must match .pre-commit-config.yaml
1211
pytype==2023.10.17; platform_system != "Windows" and python_version < "3.12"

scripts/create_baseline_stubs.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,9 @@ def run_black(stub_dir: str) -> None:
6565
subprocess.run(["black", stub_dir])
6666

6767

68-
def run_isort(stub_dir: str) -> None:
69-
print(f"Running isort: isort {stub_dir}")
70-
subprocess.run([sys.executable, "-m", "isort", stub_dir])
71-
72-
7368
def run_ruff(stub_dir: str) -> None:
74-
print(f"Running Ruff: ruff {stub_dir}")
75-
subprocess.run([sys.executable, "-m", "ruff", stub_dir])
69+
print(f"Running Ruff: ruff check {stub_dir} --fix-only")
70+
subprocess.run([sys.executable, "-m", "ruff", "check", stub_dir, "--fix-only"])
7671

7772

7873
async def get_project_urls_from_pypi(project: str, session: aiohttp.ClientSession) -> dict[str, str]:
@@ -189,7 +184,7 @@ def add_pyright_exclusion(stub_dir: str) -> None:
189184
def main() -> None:
190185
parser = argparse.ArgumentParser(
191186
description="""Generate baseline stubs automatically for an installed pip package
192-
using stubgen. Also run Black, isort and Ruff. If the name of
187+
using stubgen. Also run Black and Ruff. If the name of
193188
the project is different from the runtime Python package name, you may
194189
need to use --package (example: --package yaml PyYAML)."""
195190
)
@@ -239,7 +234,6 @@ def main() -> None:
239234
run_stubdefaulter(stub_dir)
240235

241236
run_ruff(stub_dir)
242-
run_isort(stub_dir)
243237
run_black(stub_dir)
244238

245239
create_metadata(project, stub_dir, version)

scripts/generate_proto_stubs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ PYTHON_PROTOBUF_DIR="protobuf-$PYTHON_PROTOBUF_VERSION"
4545
VENV=venv
4646
python3 -m venv "$VENV"
4747
source "$VENV/bin/activate"
48-
pip install -r "$REPO_ROOT/requirements-tests.txt" # for Black and isort
48+
pip install -r "$REPO_ROOT/requirements-tests.txt" # for Black and Ruff
4949

5050
# Install mypy-protobuf
5151
pip install mypy-protobuf=="$MYPY_PROTOBUF_VERSION"
@@ -73,7 +73,7 @@ PROTO_FILES=$(grep "GenProto.*google" $PYTHON_PROTOBUF_DIR/python/setup.py | \
7373
# shellcheck disable=SC2086
7474
protoc_install/bin/protoc --proto_path="$PYTHON_PROTOBUF_DIR/src" --mypy_out="relax_strict_optional_primitives:$REPO_ROOT/stubs/protobuf" $PROTO_FILES
7575

76-
isort "$REPO_ROOT/stubs/protobuf"
76+
ruff check "$REPO_ROOT/stubs/protobuf" --fix-only
7777
black "$REPO_ROOT/stubs/protobuf"
7878

7979
sed --in-place="" \

scripts/runtests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ def main() -> None:
8383

8484
# Run formatters first. Order matters.
8585
print("\nRunning Ruff...")
86-
subprocess.run([sys.executable, "-m", "ruff", path])
87-
print("\nRunning isort...")
88-
subprocess.run([sys.executable, "-m", "isort", path])
86+
subprocess.run([sys.executable, "-m", "ruff", "check", path])
8987
print("\nRunning Black...")
9088
black_result = subprocess.run([sys.executable, "-m", "black", path])
9189
if black_result.returncode == 123:

scripts/sync_tensorflow_protobuf_stubs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ rm tensorflow/compiler/xla/service/hlo_execution_profile_data_pb2.pyi \
6161
tensorflow/core/protobuf/worker_service_pb2.pyi \
6262
tensorflow/core/util/example_proto_fast_parsing_test_pb2.pyi
6363

64-
isort "$REPO_ROOT/stubs/tensorflow/tensorflow"
64+
ruff check "$REPO_ROOT/stubs/tensorflow/tensorflow" --fix-only
6565
black "$REPO_ROOT/stubs/tensorflow/tensorflow"
6666

6767
sed --in-place="" \

stdlib/csv.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ from _csv import (
2323
)
2424

2525
if sys.version_info >= (3, 12):
26-
from _csv import QUOTE_STRINGS as QUOTE_STRINGS, QUOTE_NOTNULL as QUOTE_NOTNULL
26+
from _csv import QUOTE_NOTNULL as QUOTE_NOTNULL, QUOTE_STRINGS as QUOTE_STRINGS
2727
from _typeshed import SupportsWrite
2828
from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence
2929
from typing import Any, Generic, TypeVar, overload

tests/check_consistent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# These type checkers and linters must have exact versions in the requirements file to ensure
2525
# consistent CI runs.
26-
linters = {"black", "flake8", "flake8-bugbear", "flake8-noqa", "flake8-pyi", "isort", "ruff", "mypy", "pytype"}
26+
linters = {"black", "flake8", "flake8-bugbear", "flake8-noqa", "flake8-pyi", "ruff", "mypy", "pytype"}
2727

2828

2929
def assert_consistent_filetypes(

0 commit comments

Comments
 (0)