diff options
| author | Edmund Miller <20095261+edmundmiller@users.noreply.github.com> | 2024-10-05 20:42:22 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-05 18:42:22 -0700 |
| commit | d6f520752a77923a420f2ef894a6f2d26d29d7d0 (patch) | |
| tree | 0c03f67f9937c2d793afb7a902cee659bbec7b5b | |
| parent | adeaaf714f0efcca335b7afe10c6bee5a0242dfa (diff) | |
Add snakefmt (#307)
https://github.com/snakemake/snakefmt
---------
Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | apheleia-formatters.el | 4 | ||||
| -rw-r--r-- | test/formatters/installers/snakefmt.bash | 2 | ||||
| -rw-r--r-- | test/formatters/samplecode/snakefmt/in.smk | 21 | ||||
| -rw-r--r-- | test/formatters/samplecode/snakefmt/out.smk | 44 |
5 files changed, 74 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7709f62..9d0d67b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog]. [typst](https://typst.app/) ([#313]). * [`rubocop`](https://github.com/rubocop/rubocop) changed to use `-a` instead of deprecated `--auto-correct` ([#316]). +* `snakefmt` official formatter for + [Snakemake](https://snakemake.readthedocs.io) ([#307]). ### Bugs fixed * `apheleia-npx` would use an incorrect path for the Yarn PnP ESM @@ -38,6 +40,7 @@ The format is based on [Keep a Changelog]. [#301]: https://github.com/radian-software/apheleia/pull/301 [#306]: https://github.com/radian-software/apheleia/pull/306 +[#307]: https://github.com/radian-software/apheleia/pull/307 [#309]: https://github.com/radian-software/apheleia/issues/309 [#312]: https://github.com/radian-software/apheleia/issues/312 [#313]: https://github.com/radian-software/apheleia/pull/313 diff --git a/apheleia-formatters.el b/apheleia-formatters.el index 77e07ef..d1f3750 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -176,6 +176,9 @@ "--fix" "--fix-only" "--stdin-filename" filepath "-")) + (snakefmt . ("snakefmt" + (apheleia-formatters-fill-column "--line-length") + "-")) (shfmt . ("shfmt" "-filename" filepath "-ln" (cl-case (bound-and-true-p sh-shell) @@ -356,6 +359,7 @@ rather than using this system." (rustic-mode . rustfmt) (rust-mode . rustfmt) (rust-ts-mode . rustfmt) + (snakemake-mode . snakefmt) (scss-mode . prettier-scss) (sql-mode . pgformatter) (svelte-mode . prettier-svelte) diff --git a/test/formatters/installers/snakefmt.bash b/test/formatters/installers/snakefmt.bash new file mode 100644 index 0000000..003234d --- /dev/null +++ b/test/formatters/installers/snakefmt.bash @@ -0,0 +1,2 @@ +apt-get install -y python3-pip +pip install snakefmt diff --git a/test/formatters/samplecode/snakefmt/in.smk b/test/formatters/samplecode/snakefmt/in.smk new file mode 100644 index 0000000..10adc3c --- /dev/null +++ b/test/formatters/samplecode/snakefmt/in.smk @@ -0,0 +1,21 @@ +from snakemake.utils import min_version +min_version("5.14.0") +configfile: "config.yaml" # snakemake keywords are treated like classes i.e. 2 newlines +SAMPLES = ['s1', 's2'] # strings are normalised +CONDITIONS = ["a", "b", "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"] # long lines are wrapped +include: "rules/foo.smk" # 2 newlines + +rule all: + input: "data/results.txt" # newlines after keywords enforced and trailing comma + +rule gets_separated_by_two_newlines: + input: + files = expand("long/string/to/data/files/gets_broken_by_black/{sample}.{condition}",sample=SAMPLES, condition=CONDITIONS) +if True: + rule can_be_inside_python_code: + input: "parameters", "get_indented" + threads: 4 # Numeric params stay unindented + params: key_val = "PEP8_formatted" + run: + + print("weirdly_spaced_string_gets_respaced") diff --git a/test/formatters/samplecode/snakefmt/out.smk b/test/formatters/samplecode/snakefmt/out.smk new file mode 100644 index 0000000..049f04c --- /dev/null +++ b/test/formatters/samplecode/snakefmt/out.smk @@ -0,0 +1,44 @@ +from snakemake.utils import min_version + +min_version("5.14.0") + + +configfile: "config.yaml" # snakemake keywords are treated like classes i.e. 2 newlines + + +SAMPLES = ["s1", "s2"] # strings are normalised +CONDITIONS = [ + "a", + "b", + "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglong", +] # long lines are wrapped + + +include: "rules/foo.smk" # 2 newlines + + +rule all: + input: + "data/results.txt", # newlines after keywords enforced and trailing comma + + +rule gets_separated_by_two_newlines: + input: + files=expand( + "long/string/to/data/files/gets_broken_by_black/{sample}.{condition}", + sample=SAMPLES, + condition=CONDITIONS, + ), + + +if True: + + rule can_be_inside_python_code: + input: + "parameters", + "get_indented", + threads: 4 # Numeric params stay unindented + params: + key_val="PEP8_formatted", + run: + print("weirdly_spaced_string_gets_respaced") |
