Skip to content

replace isort with ruff #1459

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

Merged
merged 2 commits into from
Aug 15, 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
5 changes: 3 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
python-version: "3.10"
- name: Install Ruff
run: |
python -m pip install ruff>=0.5
- name: Format check (Ruff)
python -m pip install ruff>=0.6
- name: Lint using Ruff
run: |
ruff format --check
ruff check
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
rev: v0.6.0
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand All @@ -14,11 +16,6 @@ repos:
- id: check-yaml
- id: mixed-line-ending
args: ['--fix=lf']
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
exclude: ^(oauth2_provider/migrations/|tests/migrations/)
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
Expand Down
11 changes: 5 additions & 6 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,27 @@ Code Style
==========

The project uses `flake8 <https://flake8.pycqa.org/en/latest/>`_ for linting,
`black <https://black.readthedocs.io/en/stable/>`_ for formatting the code,
`isort <https://pycqa.github.io/isort/>`_ for formatting and sorting imports,
`ruff <https://docs.astral.sh/ruff/>`_ for formatting the code and sorting imports,
and `pre-commit <https://pre-commit.com/>`_ for checking/fixing commits for
correctness before they are made.

You will need to install ``pre-commit`` yourself, and then ``pre-commit`` will
take care of installing ``flake8``, ``black`` and ``isort``.
take care of installing ``flake8`` and ``ruff``.

After cloning your repository, go into it and run::

pre-commit install

to install the hooks. On the next commit that you make, ``pre-commit`` will
download and install the necessary hooks (a one off task). If anything in the
commit would fail the hooks, the commit will be abandoned. For ``black`` and
``isort``, any necessary changes will be made automatically, but not staged.
commit would fail the hooks, the commit will be abandoned. For ``ruff``, any
necessary changes will be made automatically, but not staged.
Review the changes, and then re-stage and commit again.

Using ``pre-commit`` ensures that code that would fail in QA does not make it
into a commit in the first place, and will save you time in the long run. You
can also (largely) stop worrying about code style, although you should always
check how the code looks after ``black`` has formatted it, and think if there
check how the code looks after ``ruff`` has formatted it, and think if there
is a better way to structure the code so that it is more readable.

Documentation
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ ignore-words-list = 'assertIn'
[tool.ruff]
line-length = 110
exclude = [".tox", "oauth2_provider/migrations/", "tests/migrations/", "manage.py"]

[tool.ruff.lint]
select = ["I", "Q"]

[tool.ruff.lint.isort]
lines-after-imports = 2
known-first-party = ["oauth2_provider"]
14 changes: 0 additions & 14 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ skip_install = True
commands = flake8 {toxinidir}
deps =
flake8
flake8-isort
flake8-quotes

[testenv:migrations]
setenv =
Expand Down Expand Up @@ -138,15 +136,3 @@ exclude = docs/, oauth2_provider/migrations/, tests/migrations/, .tox/, build/,
application-import-names = oauth2_provider
inline-quotes = double
extend-ignore = E203, W503

[isort]
default_section = THIRDPARTY
known_first_party = oauth2_provider
line_length = 110
lines_after_imports = 2
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
use_parentheses = True
ensure_newline_before_comments = True
skip = oauth2_provider/migrations/, .tox/, tests/migrations/
Loading