Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Use ruff as a linter as a replacement for flake8/isort
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Willemsen committed Sep 12, 2023
1 parent 5536081 commit 33b144b
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ venv*

# further build artifacts
lockfiles/

# ruff cache
.ruff_cache/
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ repos:
entry: black --check --diff
types: [python]

- id: flake8
name: Run flake8
- id: ruff
name: Run ruff
stages: [commit]
language: system
entry: flake8
entry: ruff
types: [python]
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"ms-python.python",
"tamasfe.even-better-toml",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters"
"ryanluker.vscode-coverage-gutters",
"charliermarsh.Ruff"
]
}
15 changes: 11 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.flake8Enabled": false,
"python.linting.mypyEnabled": true,
"python.linting.enabled": true,
"python.testing.pytestArgs": ["--cov=python3_pip_skeleton", "--cov-report", "xml:cov.xml"],
"python.testing.pytestArgs": [
"--cov=python3_pip_skeleton",
"--cov-report",
"xml:cov.xml"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.formatting.provider": "black",
"python.languageServer": "Pylance",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll.ruff": false,
"source.organizeImports.ruff": true
}
}
}
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@
rst_epilog = """
.. _Diamond Light Source: http://www.diamond.ac.uk
.. _black: https://github.com/psf/black
.. _flake8: https://flake8.pycqa.org/en/latest/
.. _isort: https://github.com/PyCQA/isort
.. _ruff: https://beta.ruff.rs/docs/
.. _mypy: http://mypy-lang.org/
.. _pre-commit: https://pre-commit.com/
"""
Expand Down
12 changes: 6 additions & 6 deletions docs/developer/how-to/lint.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Run linting using pre-commit
============================

Code linting is handled by black_, flake8_ and isort_ run under pre-commit_.
Code linting is handled by black_ and ruff_ run under pre-commit_.

Running pre-commit
------------------
Expand All @@ -26,14 +26,14 @@ repository::

$ black .

Likewise with isort::
Likewise with ruff::

$ isort .
$ ruff --fix .

If you get any flake8 issues you will have to fix those manually.
Ruff may not be able to automatically fix all issues; in this case, you will have to fix those manually.

VSCode support
--------------

The ``.vscode/settings.json`` will run black and isort formatters as well as
flake8 checking on save. Issues will be highlighted in the editor window.
The ``.vscode/settings.json`` will run black formatting as well as
ruff checking on save. Issues will be highlighted in the editor window.
3 changes: 1 addition & 2 deletions docs/developer/reference/standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Code Standards
The code in this repository conforms to standards set by the following tools:

- black_ for code formatting
- flake8_ for style checks
- isort_ for import ordering
- ruff_ for style checks
- mypy_ for static type checking

.. seealso::
Expand Down
35 changes: 19 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ requires-python = ">=3.7"
dev = [
"black",
"mypy",
"flake8-isort",
"Flake8-pyproject",
"pipdeptree",
"pre-commit",
"pydata-sphinx-theme>=0.12",
"pytest",
"pytest-cov",
"ruff",
"sphinx-autobuild",
"sphinx-copybutton",
"sphinx-design",
Expand All @@ -57,20 +56,6 @@ write_to = "src/python3_pip_skeleton/_version.py"
[tool.mypy]
ignore_missing_imports = true # Ignore missing stubs in imported modules

[tool.isort]
float_to_top = true
profile = "black"

[tool.flake8]
extend-ignore = [
"E203", # See https://github.com/PyCQA/pycodestyle/issues/373
"F811", # support typing.overload decorator
"F722", # allow Annotated[typ, some_func("some string")]
]
max-line-length = 88 # Respect black's line length (default 88),
exclude = [".tox", "venv"]


[tool.pytest.ini_options]
# Run pytest with all our checkers, and don't spam us with massive tracebacks on error
addopts = """
Expand Down Expand Up @@ -111,3 +96,21 @@ commands =
pre-commit: pre-commit run --all-files {posargs}
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
"""


[tool.ruff]
src = ["src", "tests"]
ignore = [
"C408",
"E501",
"F811", # support typing.overload decorator
"F722", # allow Annotated[typ, some_func("some string")]
]
line-length = 88
select = [
"C4",
"E",
"F",
"W",
"I001", # isort
]

0 comments on commit 33b144b

Please sign in to comment.