snakefmt
snakefmt documentation
- Version in Mega-Linter: 0.4.4
- Visit Official Web Site
- See How to configure snakefmt rules
- If custom
.snakefmt.toml
config file is not found, .snakefmt.toml will be used
- If custom
Configuration in Mega-Linter
- Enable snakefmt by adding
SNAKEMAKE_SNAKEFMT
in ENABLE_LINTERS variable - Disable snakefmt by adding
SNAKEMAKE_SNAKEFMT
in DISABLE_LINTERS variable
- Enable auto-fixes by adding
SNAKEMAKE_SNAKEFMT
in APPLY_FIXES variable
Variable | Description | Default value |
---|---|---|
SNAKEMAKE_SNAKEFMT_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" |
|
SNAKEMAKE_SNAKEFMT_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib) |
Include every file |
SNAKEMAKE_SNAKEFMT_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples) |
Exclude no file |
SNAKEMAKE_SNAKEFMT_CLI_LINT_MODE | Override default CLI lint mode - file : Calls the linter for each file- list_of_files : Call the linter with the list of files as argument- project : Call the linter from the root of the project |
{linter.cli_lint_mode} |
SNAKEMAKE_SNAKEFMT_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".py", ""] |
[".smk"] |
SNAKEMAKE_SNAKEFMT_FILE_NAMES_REGEX | File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files Ex: ["Dockerfile(-.+)?", "Jenkinsfile"] |
["Snakefile"] |
SNAKEMAKE_SNAKEFMT_PRE_COMMANDS | List of bash commands to run before the linter | None |
SNAKEMAKE_SNAKEFMT_POST_COMMANDS | List of bash commands to run after the linter | None |
SNAKEMAKE_SNAKEFMT_CONFIG_FILE | snakefmt configuration file nameUse LINTER_DEFAULT to let the linter find it |
.snakefmt.toml |
SNAKEMAKE_SNAKEFMT_RULES_PATH | Path where to find linter configuration file | Workspace folder, then Mega-Linter default rules |
SNAKEMAKE_SNAKEFMT_DISABLE_ERRORS | Run linter but consider errors as warnings | true |
SNAKEMAKE_SNAKEFMT_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 |
Mega-Linter Flavours
This linter is available in the following flavours
Flavor | Description | Embedded linters | Info | |
---|---|---|---|---|
all | Default Mega-Linter Flavor | 94 | ||
dart | Optimized for DART based projects | 41 | ||
documentation | Mega-Linter for documentation projects | 40 | ||
dotnet | Optimized for C, C++, C# or VB based projects | 47 | ||
go | Optimized for GO based projects | 42 | ||
java | Optimized for JAVA based projects | 42 | ||
javascript | Optimized for JAVASCRIPT or TYPESCRIPT based projects | 49 | ||
php | Optimized for PHP based projects | 44 | ||
python | Optimized for PYTHON based projects | 49 | ||
ruby | Optimized for RUBY based projects | 41 | ||
rust | Optimized for RUST based projects | 41 | ||
salesforce | Optimized for Salesforce based projects | 43 | ||
scala | Optimized for SCALA based projects | 41 | ||
swift | Optimized for SWIFT based projects | 41 | ||
terraform | Optimized for TERRAFORM based projects | 45 |
Behind the scenes
How are identified applicable files
- File extensions:
.smk
- File names (regex):
Snakefile
How the linting is performed
- snakefmt is called one time by identified file
Example calls
snakefmt --check --compact-diff Snakefile
snakefmt --check --compact-diff --config .snakefmt.toml Snakefile
snakefmt --config .snakefmt.toml Snakefile
Help content
Usage: snakefmt [OPTIONS] [SRC]...
The uncompromising Snakemake code formatter.
SRC specifies directories and files to format. Directories will be
searched for file names that conform to the include/exclude patterns
provided.
Files are modified in-place by default; use diff, check, or `snakefmt - <
Snakefile` to avoid this.
Options:
-l, --line-length INT Lines longer than INT will be wrapped. [default: 88]
--check Don't write the files back, just return the status.
Return code 0 means nothing would change. Return code
1 means some files would be reformatted. Return code
123 means there was an error.
-d, --diff Don't write the files back, just output a diff for
each file to stdout.
--compact-diff Same as --diff but only shows lines that would change
plus a few lines of context.
--include PATTERN A regular expression that matches files and
directories that should be included on recursive
searches. An empty value means all files are
included regardless of the name. Use forward slashes
for directories on all platforms (Windows, too).
Exclusions are calculated first, inclusions later.
[default: (\.smk$|^Snakefile)]
--exclude PATTERN A regular expression that matches files and
directories that should be excluded on recursive
searches. An empty value means no paths are
excluded. Use forward slashes for directories on all
platforms (Windows, too). Exclusions are calculated
first, inclusions later. [default: (\.snakemake|\.eg
gs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|\.svn|_
build|buck-out|build|dist)]
-c, --config PATH Read configuration from PATH. By default, will try to
read from `./pyproject.toml`
-h, --help Show this message and exit.
-V, --version Show the version and exit.
-v, --verbose Turns on debug-level logger.
Installation on mega-linter Docker image
- PIP packages (Python):
Example success log
Results of snakefmt linter (version 0.2.4)
See documentation on https://megalinter.github.io/descriptors/snakemake_snakefmt/
-----------------------------------------------
[SUCCESS] .automation/test/snakemake/snakemake_good_1.smk
=====> Diff for .automation/test/snakemake/snakemake_good_1.smk <=====
[INFO] All 1 file(s) would be left unchanged 🎉
Example error log
Results of snakefmt linter (version 0.2.4)
See documentation on https://megalinter.github.io/descriptors/snakemake_snakefmt/
-----------------------------------------------
[ERROR] .automation/test/snakemake/snakemake_bad_1.smk
=====> Diff for .automation/test/snakemake/snakemake_bad_1.smk <=====
--- original
+++ new
@@ -1,10 +1,11 @@
rule all:
input:
- file1='result.txt',
+ file1="result.txt",
+
rule simulation:
output:
- file1="result.txt"
+ file1="result.txt",
shell:
"""
touch {output}
[INFO] 1 file(s) would be changed 😬