If your favourite editor is not listed here, we would love to receive a PR with how to include it.
Unless otherwise specified, all instructions assume you have snakefmt
installed
already.
- Locate the path to your
snakefmt
executable.
# linux and macOS
$ which snakefmt
/usr/local/bin/snakefmt # just an example
# windows
$ where snakefmt
%LocalAppData%\Programs\Python\Python36-32\Scripts\snakefmt.exe # just an example
- Open External tools in PyCharm/IntelliJ IDEA
-
On macOS:
PyCharm -> Preferences -> Tools -> External Tools
-
On Windows / Linux / BSD:
File -> Settings -> Tools -> External Tools
-
Click the
+
icon to add a new external tool with the following values:- Name: Snakefmt
- Description: The uncompromising Snakemake code formatter
- Program: result of
which/where snakefmt
from step 1 - Arguments:
"$FilePath$"
-
Format the currently opened file by selecting
Tools -> External Tools -> Snakefmt
.- Alternatively, you can set a keyboard shortcut by navigating to
Preferences/Settings -> Keymap -> External Tools -> External Tools - Snakefmt
. We use Alt+s
- Alternatively, you can set a keyboard shortcut by navigating to
-
Optionally, run
snakefmt
on every file save:- Make sure you have the File Watchers plugin installed.
- Go to
Preferences or Settings -> Tools -> File Watchers
and click+
to add a new watcher:- Name: Snakefmt
- File type: Python
- Scope: Project Files
- Program: result of
which/where snakefmt
from step 1 - Arguments:
$FilePath$
- Output paths to refresh:
$FilePath$
- Working directory:
$ProjectFileDir$
- Uncheck "Auto-save edited files to trigger the watcher" in Advanced Options
-
Install the extension within Visual Studio (VS) Code by visiting the Snakefmt extension page and following the instructions at the top of the page.
-
Follow the directions under the extension's Details page. Pay attention in particular to the Requirements section to provide a path to your
snakefmt
executable (if it isn't already in yourPATH
environment variable). -
See VS Code's documentation on Formatting for more instructions on how to apply formatting within the IDE.
Credit: plugin inspired by black
-
Install the plugin.
Recommended way is via a plugin manager, eg vim-plug:
Plug 'snakemake/snakefmt'
or Vundle:
Plugin 'snakemake/snakefmt'
-
That's it! Run
:Snakefmt
to format a buffer, and:SnakefmtVersion
for version info.If you do not run Vim 7.0+ built with Python3.6+ support, or you have not installed
snakefmt
, those commands will complain. -
If you want to format your file automatically when saving it, write this in your vimrc:
au BufNewFile,BufRead Snakefile,*.smk set filetype=snakemake au FileType snakemake autocmd BufWritePre <buffer> execute ':Snakefmt'
-
If you additionally want syntax highlighting on your snakemake files, install snakemake's syntax highlighter!
Under certain circumstances, import errors can occur when using a virtual environment due to Black dependency imports. See the Black Vim integration docs for more details and a potential solution.