|
31 | 31 |
|
32 | 32 | import nox |
33 | 33 |
|
| 34 | +RUFF_VERSION = "ruff==0.14.14" |
34 | 35 | FLAKE8_VERSION = "flake8==6.1.0" |
35 | 36 | PYTYPE_VERSION = "pytype==2020.7.24" |
36 | 37 | BLACK_VERSION = "black[jupyter]==23.7.0" |
37 | 38 | ISORT_VERSION = "isort==5.11.0" |
38 | 39 | LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] |
39 | 40 |
|
| 41 | +# Add samples to the list of directories to format if the directory exists. |
| 42 | +if os.path.isdir("samples"): |
| 43 | + LINT_PATHS.append("samples") |
| 44 | + |
40 | 45 | ALL_PYTHON = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] |
41 | 46 | DEFAULT_PYTHON_VERSION = "3.14" |
42 | 47 |
|
@@ -136,19 +141,31 @@ def blacken(session): |
136 | 141 | @nox.session(python=DEFAULT_PYTHON_VERSION) |
137 | 142 | def format(session): |
138 | 143 | """ |
139 | | - Run isort to sort imports. Then run black |
140 | | - to format code to uniform standard. |
| 144 | + Run ruff to sort imports and format code. |
141 | 145 | """ |
142 | | - session.install(BLACK_VERSION, ISORT_VERSION) |
143 | | - # Use the --fss option to sort imports using strict alphabetical order. |
144 | | - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections |
| 146 | + # 1. Install ruff (skipped automatically if you run with --no-venv) |
| 147 | + session.install(RUFF_VERSION) |
| 148 | + |
| 149 | + # 2. Run Ruff to fix imports |
| 150 | + # check --select I: Enables strict import sorting |
| 151 | + # --fix: Applies the changes automatically |
145 | 152 | session.run( |
146 | | - "isort", |
147 | | - "--fss", |
| 153 | + "ruff", |
| 154 | + "check", |
| 155 | + "--select", |
| 156 | + "I", |
| 157 | + "--fix", |
| 158 | + f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", |
| 159 | + "--line-length=88", # Standard Black line length |
148 | 160 | *LINT_PATHS, |
149 | 161 | ) |
| 162 | + |
| 163 | + # 3. Run Ruff to format code |
150 | 164 | session.run( |
151 | | - "black", |
| 165 | + "ruff", |
| 166 | + "format", |
| 167 | + f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", |
| 168 | + "--line-length=88", # Standard Black line length |
152 | 169 | *LINT_PATHS, |
153 | 170 | ) |
154 | 171 |
|
|
0 commit comments