|
22 | 22 |
|
23 | 23 | import nox
|
24 | 24 |
|
25 |
| - |
26 | 25 | # WARNING - WARNING - WARNING - WARNING - WARNING
|
27 | 26 | # WARNING - WARNING - WARNING - WARNING - WARNING
|
28 | 27 | # DO NOT EDIT THIS FILE EVER!
|
29 | 28 | # WARNING - WARNING - WARNING - WARNING - WARNING
|
30 | 29 | # WARNING - WARNING - WARNING - WARNING - WARNING
|
31 | 30 |
|
32 | 31 | BLACK_VERSION = "black==22.3.0"
|
| 32 | +ISORT_VERSION = "isort==5.10.1" |
33 | 33 |
|
34 | 34 | # Copy `noxfile_config.py` to your directory and modify it instead.
|
35 | 35 |
|
@@ -168,12 +168,33 @@ def lint(session: nox.sessions.Session) -> None:
|
168 | 168 |
|
169 | 169 | @nox.session
|
170 | 170 | def blacken(session: nox.sessions.Session) -> None:
|
| 171 | + """Run black. Format code to uniform standard.""" |
171 | 172 | session.install(BLACK_VERSION)
|
172 | 173 | python_files = [path for path in os.listdir(".") if path.endswith(".py")]
|
173 | 174 |
|
174 | 175 | session.run("black", *python_files)
|
175 | 176 |
|
176 | 177 |
|
| 178 | +# |
| 179 | +# format = isort + black |
| 180 | +# |
| 181 | + |
| 182 | + |
| 183 | +@nox.session |
| 184 | +def format(session: nox.sessions.Session) -> None: |
| 185 | + """ |
| 186 | + Run isort to sort imports. Then run black |
| 187 | + to format code to uniform standard. |
| 188 | + """ |
| 189 | + session.install(BLACK_VERSION, ISORT_VERSION) |
| 190 | + python_files = [path for path in os.listdir(".") if path.endswith(".py")] |
| 191 | + |
| 192 | + # Use the --fss option to sort imports using strict alphabetical order. |
| 193 | + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections |
| 194 | + session.run("isort", "--fss", *python_files) |
| 195 | + session.run("black", *python_files) |
| 196 | + |
| 197 | + |
177 | 198 | #
|
178 | 199 | # Sample Tests
|
179 | 200 | #
|
|
0 commit comments