Skip to content

Commit dde12b8

Browse files
authored
Prefer Ruff over isort for more efficient and complete import sorting and grouping (#2220)
1 parent 2b3b1a0 commit dde12b8

6 files changed

Lines changed: 35 additions & 21 deletions

File tree

.github/workflows/main.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ jobs:
104104
with:
105105
# This job only needs to target the oldest supported version (black@stable supports Python >=3.8)
106106
python-version: '3.8'
107-
- run: pip install isort pycln
107+
- run: pip install pycln
108108
- run: pycln . --config=pycln.toml --check
109-
- run: isort . --diff --check-only
109+
- uses: chartboost/ruff-action@v1
110+
with:
111+
version: '0.3.4'
110112
- uses: psf/black@stable
111113
with:
112114
options: "--fast --check --diff --verbose"

.isort.cfg

Lines changed: 0 additions & 7 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ repos:
2727
- id: pycln
2828
args: [--config=pycln.toml]
2929
verbose: true
30-
- repo: https://github.com/pycqa/isort
31-
rev: 5.13.2
30+
- repo: https://github.com/astral-sh/ruff-pre-commit
31+
rev: v0.3.4
3232
hooks:
33-
- id: isort
34-
name: isort (python)
35-
verbose: true
33+
- id: ruff # Run the linter.
34+
args: [--fix]
3635
- repo: https://github.com/psf/black-pre-commit-mirror
3736
rev: 24.2.0
3837
hooks:

Pythonwin/pywin/scintilla/view.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
import win32ui
1212
from pywin.mfc import afxres, docview
1313

14-
from . import IDLEenvironment # IDLE emulation.
15-
from . import bindings, control, scintillacon
14+
from . import (
15+
IDLEenvironment, # IDLE emulation.
16+
bindings,
17+
control,
18+
scintillacon,
19+
)
1620

1721
PRINTDLGORD = 1538
1822
IDC_PRINT_MAG_EDIT = 1010

ruff.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
target-version = "py37"
2+
3+
[lint]
4+
select = ["I"]
5+
6+
[lint.isort]
7+
combine-as-imports = true
8+
# Because pywin32 has a mix of relative and absolute imports, with undetectable first-party c-extensions
9+
# This makes import grouping more consistent
10+
detect-same-package = false
11+
known-third-party = [
12+
"__main__",
13+
# This forces distutils imports to always be after setuptools
14+
# setuptools must be imported before distutils because it monkey-patches it.
15+
# distutils is also removed in Python 3.12 and deprecated with setuptools
16+
"distutils",
17+
]
18+
extra-standard-library = ["setuptools"]

setup.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@
3535
import sys
3636
import winreg
3737
from pathlib import Path
38-
from tempfile import gettempdir
39-
from typing import Iterable, List, Tuple, Union
40-
41-
# setuptools must be imported before distutils because it monkey-patches it.
42-
# distutils is also removed in Python 3.12 and deprecated with setuptools
4338
from setuptools import Extension, setup
4439
from setuptools.command.build import build
4540
from setuptools.command.build_ext import build_ext
4641
from setuptools.command.install import install
4742
from setuptools.command.install_lib import install_lib
43+
from tempfile import gettempdir
44+
from typing import Iterable, List, Tuple, Union
4845

4946
from distutils import ccompiler
5047
from distutils._msvccompiler import MSVCCompiler
@@ -2214,6 +2211,7 @@ def convert_optional_data_files(files):
22142211
# fixup https://github.com/pypa/setuptools/issues/3284
22152212
def maybe_fixup_exes():
22162213
import site
2214+
22172215
from distutils.command import bdist_wininst
22182216

22192217
# setuptools can't find .exe stubs in `site-packages/setuptools/_distutils`

0 commit comments

Comments
 (0)