Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer Ruff over isort for more efficient and complete import sorting and grouping #2220

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -33,16 +33,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.command.install_data import install_data

Expand Down Expand Up @@ -2263,6 +2260,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
Loading