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
snakefmtexecutable.
# 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 snakefmtfrom 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
snakefmton every file save:- Make sure you have the File Watchers plugin installed.
- Go to
Preferences or Settings -> Tools -> File Watchersand click+to add a new watcher:- Name: Snakefmt
- File type: Python
- Scope: Project Files
- Program: result of
which/where snakefmtfrom 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
snakefmtexecutable (if it isn't already in yourPATHenvironment 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
:Snakefmtto format a buffer, and:SnakefmtVersionfor 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.
The format-all package supports use of snakefmt out of the box provided snakefmt is available on the exec-path; it should suffice to have snakefmt available on your PATH.
snakefmt can be invoked in a buffer using format-all in the usual way with format-all-buffer, and also by adding a hook to your dotfile to enable the format-all-mode minor mode. If you are using snakemake-mode already, you can do this with:
(add-hook `snakemake-mode-hook #`format-all-mode)See the format-all repo for more documentation.