Skip to content

Commit ecd681a

Browse files
authored
chore: Replace pylint, black and isort with ruff (#323)
1 parent 47db54d commit ecd681a

19 files changed

+275
-383
lines changed

.github/README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,23 @@ The generated HTML will appear in the `docs/_build/html` directory.
103103

104104
Code is formatted, linted and checked using the following tools:
105105

106-
- [Black](https://github.com/psf/black)
107-
- [Pylint](https://pypi.org/project/pylint/)
108-
- [isort](https://github.com/timothycrosley/isort)
106+
- [Ruff](https://github.com/astral-sh/ruff) - A fast Python linter and formatter (replaces Black, isort, and Pylint)
109107
- [mypy](http://mypy-lang.org/)
110108

111109
These checks are run on all code merged to master, and may also be run locally from the open-controls directory:
112110

113111
```shell
114-
pip install black isort mypy pylint
112+
pip install ruff mypy
115113
mypy
116-
isort --check .
117-
black --check .
118-
pylint .
114+
ruff check .
115+
ruff format --check .
119116
```
120117

121-
Note that you can speed up the execution of Pylint by running it in the parallel mode with the `-j` option: `pylint -j 0 .`. See the [official documentation](https://pylint.readthedocs.io/en/latest/user_guide/usage/run.html#parallel-execution) for details.
122-
123-
Black and isort, in addition to checking code, can also automatically apply fixes. To fix all code in the open-controls tree, run:
118+
Ruff, in addition to checking code, can also automatically apply fixes. To fix all code in the open-controls tree, run:
124119

125120
```shell
126-
isort
127-
black .
121+
ruff check --fix .
122+
ruff format .
128123
```
129124

130125
You can also run these checks only in the files that you changed by using the `pre-commit` tool. To use it, run:

.pre-commit-config.yaml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,26 @@ repos:
1111
- id: check-toml
1212
- repo: local
1313
hooks:
14-
- id: black
15-
name: black
16-
entry: poetry run black
14+
- id: ruff-check
15+
name: ruff-check
16+
entry: poetry run ruff check
1717
language: system
1818
require_serial: true
1919
types: [python]
20-
- id: isort
21-
name: isort
22-
entry: poetry run isort
23-
require_serial: true
20+
args: [--fix]
21+
- id: ruff-format
22+
name: ruff-format
23+
entry: poetry run ruff format
2424
language: system
25+
require_serial: true
2526
types: [python]
26-
args: ['--filter-files']
2727
- id: mypy
2828
name: mypy
2929
entry: poetry run mypy
3030
require_serial: true
3131
language: system
3232
types: [python]
3333
exclude: docs/conf.py
34-
- id: pylint
35-
entry: poetry run pylint --rcfile=.pylintrc
36-
name: pylint
37-
language: system
38-
types: [file, python]
39-
# when passing in a single file as argument the ignore entry in the .pylintrc does
40-
# not seem to be considered.
41-
exclude: .*(venv|\.conf\.py)
4234
- repo: https://github.com/pre-commit/mirrors-prettier
4335
rev: v3.0.0
4436
hooks:

.pylintrc

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

docs/conf.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""
16-
Configuration file for the Sphinx documentation builder.
17-
"""
15+
"""Configuration file for the Sphinx documentation builder."""
1816

1917
# This file only contains a selection of the most common options. For a full
2018
# list see the documentation:
@@ -28,25 +26,24 @@
2826

2927
import datetime
3028
import inspect
31-
import os
3229
import sys
30+
from pathlib import Path
3331
from typing import List
3432

3533
import tomli
3634

3735
import qctrlopencontrols
3836

39-
# pylint:disable=invalid-name
40-
sys.path.insert(0, os.path.abspath(".."))
37+
sys.path.insert(0, str(Path("..").resolve()))
4138

4239
# -- Project information -----------------------------------------------------
43-
with open("../pyproject.toml", "rb") as f:
40+
with Path("../pyproject.toml").open("rb") as f:
4441
parsed = tomli.load(f)
4542
package_info = parsed["tool"]["poetry"]
4643
project = package_info["description"]
4744
author = ", ".join(package_info["authors"])
4845
release = package_info["version"]
49-
copyright = f"{datetime.datetime.now().year} Q-CTRL. All rights reserved." # pylint: disable=redefined-builtin
46+
copyright = f"{datetime.datetime.now().year} Q-CTRL. All rights reserved." # noqa: A001
5047

5148
# -- General configuration ---------------------------------------------------
5249

@@ -111,9 +108,7 @@
111108
+ "."
112109
+ _class.__name__
113110
+ "."
114-
+ attribute: _class.__name__
115-
+ "."
116-
+ attribute
111+
+ attribute: _class.__name__ + "." + attribute
117112
for attribute in dir(_class)
118113
if not attribute.startswith("_")
119114
}

examples/creating-a-driven-control.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
"outputs": [],
3030
"source": [
3131
"import numpy as np\n",
32-
"import matplotlib.pyplot as plt\n",
32+
"from qctrlvisualizer import plot_controls\n",
33+
"\n",
3334
"from qctrlopencontrols import (\n",
3435
" DrivenControl,\n",
3536
" new_bb1_control,\n",
37+
" new_corpse_control,\n",
3638
" new_primitive_control,\n",
3739
" new_sk1_control,\n",
38-
" new_corpse_control,\n",
39-
")\n",
40-
"from qctrlvisualizer import plot_controls"
40+
")"
4141
]
4242
},
4343
{
@@ -290,7 +290,7 @@
290290
],
291291
"source": [
292292
"## Reload the file and check its content to better understand the format\n",
293-
"with open(filename, \"rt\") as handle:\n",
293+
"with open(filename) as handle:\n",
294294
" file_content = handle.read()\n",
295295
"print(file_content)"
296296
]

examples/creating-a-dynamical-decoupling-sequence.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
"outputs": [],
3030
"source": [
3131
"import numpy as np\n",
32-
"import matplotlib.pyplot as plt\n",
32+
"from qctrlvisualizer import plot_sequences\n",
33+
"\n",
3334
"from qctrlopencontrols import (\n",
34-
" new_spin_echo_sequence,\n",
35+
" DynamicDecouplingSequence,\n",
3536
" new_carr_purcell_sequence,\n",
36-
" new_walsh_sequence,\n",
37+
" new_quadratic_sequence,\n",
3738
" new_ramsey_sequence,\n",
39+
" new_spin_echo_sequence,\n",
40+
" new_walsh_sequence,\n",
3841
" new_x_concatenated_sequence,\n",
39-
" new_quadratic_sequence,\n",
40-
" DynamicDecouplingSequence,\n",
41-
")\n",
42-
"from qctrlvisualizer import plot_sequences"
42+
")"
4343
]
4444
},
4545
{
@@ -320,7 +320,7 @@
320320
],
321321
"source": [
322322
"## Reload the file and check its content to better understand the format\n",
323-
"with open(filename, \"rt\") as handle:\n",
323+
"with open(filename) as handle:\n",
324324
" file_content = handle.read()\n",
325325
"print(file_content)"
326326
]

0 commit comments

Comments
 (0)