You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -17,10 +17,10 @@ design and specifications of [Black][black].
17
17
> `--diff` or `--check` options. See [Usage](#usage) for more details.
18
18
19
19
> [!IMPORTANT]
20
-
> **Recent Changes:**
20
+
> **Recent Changes:**
21
21
> 1.**Rule and module directives are now sorted by default:**`snakefmt` will automatically sort the order of directives inside rules (e.g. `input`, `output`, `shell`) and modules into a consistent order. You can opt out of this by using the `--no-sort` CLI flag.
22
22
> 2.**Black upgraded to v26:** The underlying `black` formatter has been upgraded to v26. You will see changes in how implicitly concatenated strings are wrapped (they are now collapsed onto a single line if they fit within the line limit) and other minor adjustments compared to previous versions.
23
-
>
23
+
>
24
24
> **Example of expected differences:**
25
25
> ```python
26
26
># Before (Snakefmt older versions)
@@ -33,7 +33,7 @@ design and specifications of [Black][black].
33
33
>"b.txt",
34
34
>input:
35
35
>"a.txt",
36
-
>
36
+
>
37
37
># After (Directives sorted, strings collapsed by Black 26)
38
38
> rule example:
39
39
>input:
@@ -56,13 +56,16 @@ design and specifications of [Black][black].
56
56
- [Usage](#usage)
57
57
- [Basic Usage](#basic-usage)
58
58
- [Full Usage](#full-usage)
59
-
- [Configuration](#configuration)
60
59
- [Directive Sorting](#directive-sorting)
60
+
- [Format Directives](#format-directives)
61
+
- [Configuration](#configuration)
61
62
- [Integration](#integration)
62
-
- [Editor Integration](#editor-integration)
63
-
- [Version Control Integration](#version-control-integration)
64
-
- [Github Actions](#github-actions)
63
+
- [Editor Integration](#editor-integration)
64
+
- [Version Control Integration](#version-control-integration)
65
+
- [GitHub Actions](#github-actions)
65
66
- [Plug Us](#plug-us)
67
+
- [Markdown](#markdown)
68
+
- [ReStructuredText](#restructuredtext)
66
69
- [Changes](#changes)
67
70
- [Contributing](#contributing)
68
71
- [Cite](#cite)
@@ -280,20 +283,6 @@ Options:
280
283
-v, --verbose Turns on debug-level logger.
281
284
```
282
285
283
-
## Configuration
284
-
285
-
`snakefmt`is able to read project-specific default values for its command line options
286
-
from a `pyproject.toml`file. In addition, it will also load any [`black`
287
-
configurations][black-config] you have in the same file.
288
-
289
-
By default, `snakefmt` will search in the parent directories of the formatted file(s)
290
-
for a file called `pyproject.toml`and use any configuration there.
291
-
If your configuration fileis located somewhere elseor called something different,
292
-
specify it using `--config`.
293
-
294
-
Any options you pass on the command line will take precedence over default values in the
295
-
configuration file.
296
-
297
286
### Directive Sorting
298
287
299
288
By default, `snakefmt` sorts rule and module directives (like `input`, `output`, `shell`, etc.) into a consistent order. This makes rules easier to read and allows for quicker cross-referencing between inputs, outputs, and the resources used by the execution command.
@@ -313,9 +302,104 @@ This ordering ensures that the directives most frequently used in execution bloc
313
302
314
303
You can disable this feature using the `--no-sort` flag.
315
304
305
+
### Format Directives
306
+
307
+
`snakefmt` supports comment directives to control formatting behaviour for specific regions of code.
308
+
Directives should appear as standalone comment lines, an inline occurrence (e.g. `input: # fmt: off`) is treated as a plain comment and has no effect.
309
+
All directives are scope-local: only the region they select is affected, while code before and after follows normal `snakefmt` formatting and spacing rules (equivalent to replacing the directive with a plain comment line).
310
+
311
+
#### `# fmt: off` / `# fmt: on`
312
+
313
+
Disables all formatting for the region between the two directives.
314
+
Both directives *must* appear at the same indentation level; a `# fmt: on` at a deeper indent than the matching `# fmt: off` has no effect.
315
+
316
+
```python
317
+
rule a:
318
+
input:
319
+
"a.txt",
320
+
321
+
322
+
# fmt: off
323
+
rule b:
324
+
input: "b.txt"
325
+
output:
326
+
"c.txt"
327
+
# fmt: on
328
+
329
+
330
+
rule c:
331
+
input:
332
+
"d.txt",
333
+
```
334
+
335
+
>**Note:** inside `run:` blocks and other Python contexts, `# fmt: off` / `# fmt: on` is passed through to [Black][black], which handles it natively.
336
+
337
+
#### `# fmt: off[sort]`
338
+
339
+
Disables directive sorting for the enclosed region while still applying all other formatting.
340
+
Directives between `# fmt: off[sort]` and `# fmt: on[sort]` are kept in their original order.
341
+
A plain `# fmt: on` also closes a `# fmt: off[sort]` region.
342
+
343
+
```python
344
+
# fmt: off[sort]
345
+
rule keep_my_order:
346
+
output:
347
+
"result.txt",
348
+
input:
349
+
"source.txt",
350
+
shell:
351
+
"cp {input}{output}"
352
+
# fmt: on[sort]
353
+
```
354
+
355
+
#### `# fmt: off[next]`
356
+
357
+
Disables formatting for the single next Snakemake keyword block (e.g. `rule`, `checkpoint`, `use rule`).
358
+
Only that block is left unformatted; all subsequent blocks are formatted normally.
359
+
360
+
```python
361
+
rule formatted:
362
+
input:
363
+
"a.txt",
364
+
output:
365
+
"b.txt",
366
+
367
+
368
+
# fmt: off[next]
369
+
rule unformatted:
370
+
input: "a.txt"
371
+
output: "b.txt"
372
+
373
+
374
+
rule also_formatted:
375
+
input:
376
+
"a.txt",
377
+
```
378
+
379
+
#### `# fmt: skip`
380
+
381
+
`# fmt: skip` preserves a single line exactly as written, without any formatting (see [Black's documentation][black-skip] for details).
382
+
383
+
>**Note:**`# fmt: skip` is not yet supported within Snakemake rule blocks.
384
+
> It currently applies only to plain Python lines outside of rules, checkpoints, and similar Snakemake constructs.
385
+
386
+
### Configuration
387
+
388
+
`snakefmt`is able to read project-specific default values for its command line options
389
+
from a `pyproject.toml`file. In addition, it will also load any [`black`
390
+
configurations][black-config] you have in the same file.
391
+
392
+
By default, `snakefmt` will search in the parent directories of the formatted file(s)
393
+
for a file called `pyproject.toml`and use any configuration there.
394
+
If your configuration fileis located somewhere elseor called something different,
395
+
specify it using `--config`.
396
+
397
+
Any options you pass on the command line will take precedence over default values in the
0 commit comments