Skip to content

Commit

Permalink
Prefer Ruff over isort for more efficient and complete import sorting…
Browse files Browse the repository at this point in the history
… and grouping (#2220)
  • Loading branch information
Avasam authored Apr 12, 2024
1 parent 2b3b1a0 commit dde12b8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ jobs:
with:
# This job only needs to target the oldest supported version (black@stable supports Python >=3.8)
python-version: '3.8'
- run: pip install isort pycln
- run: pip install pycln
- run: pycln . --config=pycln.toml --check
- run: isort . --diff --check-only
- uses: chartboost/ruff-action@v1
with:
version: '0.3.4'
- uses: psf/black@stable
with:
options: "--fast --check --diff --verbose"
Expand Down
7 changes: 0 additions & 7 deletions .isort.cfg

This file was deleted.

9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ repos:
- id: pycln
args: [--config=pycln.toml]
verbose: true
- repo: https://github.com/pycqa/isort
rev: 5.13.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: isort
name: isort (python)
verbose: true
- id: ruff # Run the linter.
args: [--fix]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
hooks:
Expand Down
8 changes: 6 additions & 2 deletions Pythonwin/pywin/scintilla/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import win32ui
from pywin.mfc import afxres, docview

from . import IDLEenvironment # IDLE emulation.
from . import bindings, control, scintillacon
from . import (
IDLEenvironment, # IDLE emulation.
bindings,
control,
scintillacon,
)

PRINTDLGORD = 1538
IDC_PRINT_MAG_EDIT = 1010
Expand Down
18 changes: 18 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
target-version = "py37"

[lint]
select = ["I"]

[lint.isort]
combine-as-imports = true
# Because pywin32 has a mix of relative and absolute imports, with undetectable first-party c-extensions
# This makes import grouping more consistent
detect-same-package = false
known-third-party = [
"__main__",
# This forces distutils imports to always be after setuptools
# setuptools must be imported before distutils because it monkey-patches it.
# distutils is also removed in Python 3.12 and deprecated with setuptools
"distutils",
]
extra-standard-library = ["setuptools"]
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@
import sys
import winreg
from pathlib import Path
from tempfile import gettempdir
from typing import Iterable, List, Tuple, Union

# setuptools must be imported before distutils because it monkey-patches it.
# distutils is also removed in Python 3.12 and deprecated with setuptools
from setuptools import Extension, setup
from setuptools.command.build import build
from setuptools.command.build_ext import build_ext
from setuptools.command.install import install
from setuptools.command.install_lib import install_lib
from tempfile import gettempdir
from typing import Iterable, List, Tuple, Union

from distutils import ccompiler
from distutils._msvccompiler import MSVCCompiler
Expand Down Expand Up @@ -2214,6 +2211,7 @@ def convert_optional_data_files(files):
# fixup https://github.com/pypa/setuptools/issues/3284
def maybe_fixup_exes():
import site

from distutils.command import bdist_wininst

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

0 comments on commit dde12b8

Please sign in to comment.