snakefmt

The uncompromising Snakemake code formatter

https://github.com/snakemake/snakefmt

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 5 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    3 of 18 committers (16.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.9%) to scientific vocabulary

Keywords

bioinformatics black code codeformatter fmt formatter python snakemake

Keywords from Contributors

hack standardization interpretability meshing argument-parser pipeline-testing datacleaner data-profilers sequences robust
Last synced: 4 months ago · JSON representation ·

Repository

The uncompromising Snakemake code formatter

Basic Info
  • Host: GitHub
  • Owner: snakemake
  • License: mit
  • Language: Python
  • Default Branch: master
  • Size: 894 KB
Statistics
  • Stars: 176
  • Watchers: 5
  • Forks: 33
  • Open Issues: 14
  • Releases: 37
Topics
bioinformatics black code codeformatter fmt formatter python snakemake
Created almost 6 years ago · Last pushed 4 months ago
Metadata Files
Readme Changelog Contributing License Citation Codeowners

README.md

Snakefmt

GitHub Workflow Status codecov PyPI PyPI - Python Version License: MIT Code style: black

This repository provides formatting for Snakemake files. It follows the design and specifications of Black.

⚠️WARNING⚠️: snakefmt modifies files in-place by default, thus we strongly recommend ensuring your files are under version control before doing any formatting. You can also pipe the file in from stdin, which will print it to the screen, or use the --diff or --check options. See Usage for more details.

Table of Contents

Install

PyPi

PyPI - Python Version PyPI - Version PyPI - Downloads

sh pip install snakefmt

Conda

Conda (channel only) bioconda version Conda Downloads

sh conda install -c bioconda snakefmt

Containers

As snakefmt has a Conda recipe, there is a matching image built for each version by Biocontainers.

In the following examples, all tags (<tag>) can be found here.

Docker

shell $ docker run -it "quay.io/biocontainers/snakefmt:<tag>" snakefmt --help

Singularity

shell $ singularity exec "docker://quay.io/biocontainers/snakefmt:<tag>" snakefmt --help

Local

These instructions include installing uv. ```sh

install uv

curl -LsSf https://astral.sh/uv/install.sh | sh

git clone https://github.com/snakemake/snakefmt && cd snakefmt

install snakefmt in a new environment

make install

you can now run snakefmt with

uv run snakefmt --help ```

Example File

Input

```python from snakemake.utils import minversion minversion("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 getsseparatedbytwonewlines: input: files = expand("long/string/to/data/files/getsbrokenbyblack/{sample}.{condition}",sample=SAMPLES, condition=CONDITIONS) if True: rule canbeinsidepythoncode: input: "parameters", "getindented" threads: 4 # Numeric params stay unindented params: keyval = "PEP8formatted" run:

            print("weirdly_spaced_string_gets_respaced")

```

Output

```python 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 getsseparatedbytwonewlines: input: files=expand( "long/string/to/data/files/getsbrokenby_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")

```

Usage

Basic Usage

Format a single Snakefile.

shell snakefmt Snakefile

Format all Snakefiles within a directory.

shell snakefmt workflows/

Format a file but write the output to stdout.

shell snakefmt - < Snakefile

Full Usage

``` $ snakefmt --help 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|.mypycache|.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 logging.

```

Configuration

snakefmt is able to read project-specific default values for its command line options from a pyproject.toml file. In addition, it will also load any black configurations you have in the same file.

By default, snakefmt will search in the parent directories of the formatted file(s) for a file called pyproject.toml and use any configuration there. If your configuration file is located somewhere else or called something different, specify it using --config.

Any options you pass on the command line will take precedence over default values in the configuration file.

Example

pyproject.toml

```toml [tool.snakefmt] line_length = 90 include = '.smk$|^Snakefile|.py$'

snakefmt passes these options on to black

[tool.black] skipstringnormalization = true ```

In this example we increase the --line-length value and also include python (*.py) files for formatting - this effectively runs black on them. snakefmt will also pass on the [tool.black] settings, internally, to black.

Integration

Editor Integration

For instructions on how to integrate snakefmt into your editor of choice, refer to docs/editor_integration.md

Version Control Integration

snakefmt supports pre-commit, a framework for managing git pre-commit hooks. Using this framework you can run snakefmt whenever you commit a Snakefile or *.smk file. Pre-commit automatically creates an isolated virtual environment with snakefmt and will stop the commit if snakefmt would modify the file. You then review, stage, and re-commit these changes. Pre-commit is especially useful if you don't have access to a CI/CD system like GitHub actions.

To do so, create the file .pre-commit-config.yaml in the root of your project directory with the following:

yaml repos: - repo: https://github.com/snakemake/snakefmt rev: v0.10.2 # Replace by any tag/version ≥v0.6.0 : https://github.com/snakemake/snakefmt/releases hooks: - id: snakefmt

Then install pre-commit and initialize the pre-commit hooks by running pre-commit install (Note you need to run this step once per clone of your repository). Additional pre-commit hooks can be found here.

GitHub Actions

GitHub Actions in combination with super-linter allows you to automatically run snakefmt on all Snakefiles in your repository e.g. whenever you push a new commit.

To do so, create the file .github/workflows/linter.yml in your repository:

```yaml

name: Lint Code Base

on: push: pull_request: branches: [master]

jobs: build: name: Lint Code Base runs-on: ubuntu-latest

steps:
  - name: Checkout Code
    uses: actions/checkout@v2

  - name: Lint Code Base
    uses: github/super-linter@v3
    env:
      VALIDATE_ALL_CODEBASE: false
      DEFAULT_BRANCH: master
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      VALIDATE_SNAKEMAKE_SNAKEFMT: true

```

Additional configuration parameters can be specified by creating .github/linters/.snakefmt.toml: toml [tool.black] skip_string_normalization = true

For more information check the super-linter readme.

Plug Us

If you can't get enough of badges, then feel free to show others you're using snakefmt in your project.

Code style: snakefmt

Markdown

md [![Code style: snakefmt](https://img.shields.io/badge/code%20style-snakefmt-000000.svg)](https://github.com/snakemake/snakefmt)

ReStructuredText

rst .. image:: https://img.shields.io/badge/code%20style-snakefmt-000000.svg :target: https://github.com/snakemake/snakefmt

Changes

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

Cite

DOI

Bibtex @article{snakemake2021, doi = {10.12688/f1000research.29032.2}, url = {https://doi.org/10.12688/f1000research.29032.2}, year = {2021}, month = apr, publisher = {F1000 Research Ltd}, volume = {10}, pages = {33}, author = {Felix M\"{o}lder and Kim Philipp Jablonski and Brice Letcher and Michael B. Hall and Christopher H. Tomkins-Tinch and Vanessa Sochat and Jan Forster and Soohyun Lee and Sven O. Twardziok and Alexander Kanitz and Andreas Wilm and Manuel Holtgrewe and Sven Rahmann and Sven Nahnsen and Johannes K\"{o}ster}, title = {Sustainable data analysis with Snakemake}, journal = {F1000Research} }

Owner

  • Name: Snakemake
  • Login: snakemake
  • Kind: organization

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: 'Snakefmt: the uncompromising Snakemake code formatter '
message: >-
  If you use this software, please cite both the article
  from preferred-citation and the software itself.
type: software
authors:
  - given-names: Michael
    name-particle: B
    family-names: Hall
    email: michael@mbh.sh
    affiliation: >-
      European Molecular Biology Laboratory, European
      Bioinformatics Institute, Wellcome Genome Campus,
      Hinxton, UK
    orcid: 'https://orcid.org/0000-0003-3683-6208'
  - given-names: Brice
    family-names: Letcher
    affiliation: >-
      European Molecular Biology Laboratory, European
      Bioinformatics Institute, Wellcome Genome Campus,
      Hinxton, UK
    orcid: 'https://orcid.org/0000-0002-8921-6005'
identifiers:
  - type: doi
    value: 10.12688/f1000research.29032.2
    description: >-
      The snakemake paper, which should also be cited if
      using snakefmt
repository-code: 'https://github.com/snakemake/snakefmt'
url: 'https://github.com/snakemake/snakefmt'
abstract: >-
  Snakefmt formats Snakemake workflow files using the same
  style as Black (https://github.com/psf/black).
keywords:
  - format
  - snakemake
  - code
license: MIT
commit: 05ae61d90ecf38f8d075eab10795bfa47bd41e04
version: 0.8.4
date-released: '2023-04-05'
preferred-citation:
    authors:
        - family-names: Mölder
          given-names: Felix
        - family-names: Jablonski
          given-names: Kim Philipp
        - family-names: Letcher
          given-names: Brice
        - family-names: Hall
          given-names: Michael
          name-particle: B
        - family-names: Tomkins-Tinch
          given-names: Christopher
          name-particle: H
        - family-names: Sochat
          given-names: Vanessa
        - family-names: Forster
          given-names: Jan
        - family-names: Lee
          given-names: Soohyun
        - family-names: Twardziok
          given-names: Sven
          name-particle: O
        - family-names: Kanitz
          given-names: Alexander
        - family-names: Wilm
          given-names: Andreas
        - family-names: Holtgrewe
          given-names: Manuel
        - family-names: Köster
          given-names: Johannes
    title: 'Sustainable data analysis with Snakemake'
    type: article
    year: 2021
    identifiers:
      - type: doi
        value: 10.12688/f1000research.29032.2
        

GitHub Events

Total
  • Issues event: 13
  • Watch event: 21
  • Delete event: 9
  • Issue comment event: 37
  • Push event: 38
  • Pull request review event: 21
  • Pull request review comment event: 12
  • Pull request event: 17
  • Fork event: 4
  • Create event: 5
Last Year
  • Issues event: 13
  • Watch event: 21
  • Delete event: 9
  • Issue comment event: 37
  • Push event: 38
  • Pull request review event: 21
  • Pull request review comment event: 12
  • Pull request event: 17
  • Fork event: 4
  • Create event: 5

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 426
  • Total Committers: 18
  • Avg Commits per committer: 23.667
  • Development Distribution Score (DDS): 0.596
Past Year
  • Commits: 26
  • Committers: 4
  • Avg Commits per committer: 6.5
  • Development Distribution Score (DDS): 0.538
Top Committers
Name Email Commits
Brice Letcher b****r@e****k 172
Michael Hall m****l@m****h 170
Johannes Koester j****r@u****e 20
Michael Hall m****8@g****m 16
github-actions[bot] 4****] 14
David Laehnemann d****n@h****e 9
dependabot[bot] 4****] 7
Jeremiah Lewis 4****1 5
Koen van Greevenbroek k****k@u****o 3
snakemake-bot s****n@g****m 2
Austin Keller a****r@s****m 1
Branch Vincent b****t@g****m 1
C. Titus Brown t****s@i****g 1
Derek Croote d****e 1
Jameel Al-Aziz 2****z 1
Justin Fear j****r@g****m 1
Jan Wagner j****f@t****e 1
Kim k****i@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 85
  • Total pull requests: 120
  • Average time to close issues: 4 months
  • Average time to close pull requests: 22 days
  • Total issue authors: 47
  • Total pull request authors: 19
  • Average comments per issue: 3.51
  • Average comments per pull request: 1.95
  • Merged pull requests: 83
  • Bot issues: 0
  • Bot pull requests: 51
Past Year
  • Issues: 7
  • Pull requests: 20
  • Average time to close issues: 19 days
  • Average time to close pull requests: 9 days
  • Issue authors: 6
  • Pull request authors: 9
  • Average comments per issue: 1.86
  • Average comments per pull request: 2.1
  • Merged pull requests: 11
  • Bot issues: 0
  • Bot pull requests: 4
Top Authors
Issue Authors
  • corneliusroemer (15)
  • johanneskoester (5)
  • siebrenf (4)
  • mbhall88 (3)
  • hermidalc (3)
  • jbloom (3)
  • lczech (3)
  • y9c (3)
  • Hugovdberg (2)
  • chillenzer (2)
  • GianlucaFicarelli (2)
  • gordonkoehn (2)
  • fgypas (2)
  • Hocnonsense (2)
  • hepcat72 (2)
Pull Request Authors
  • dependabot[bot] (29)
  • mbhall88 (28)
  • github-actions[bot] (22)
  • bricoletc (13)
  • johanneskoester (7)
  • snakemake-bot (5)
  • jakevc (2)
  • dlaehnemann (2)
  • fischuu (2)
  • jeremiahpslewis (1)
  • je3we3 (1)
  • Hocnonsense (1)
  • koen-vg (1)
  • twillis209 (1)
  • GiulioCentorame (1)
Top Labels
Issue Labels
bug (32) enhancement (4) question (3) wontfix (3) help wanted (3) good first issue (1)
Pull Request Labels
dependencies (29) autorelease: tagged (16) autorelease: pending (11) python (2)

Packages

  • Total packages: 3
  • Total downloads:
    • pypi 11,524 last-month
    • homebrew 134 last-month
  • Total docker downloads: 1,727,969
  • Total dependent packages: 1
    (may contain duplicates)
  • Total dependent repositories: 70
    (may contain duplicates)
  • Total versions: 68
  • Total maintainers: 1
pypi.org: snakefmt

The uncompromising Snakemake code formatter

  • Versions: 38
  • Dependent Packages: 1
  • Dependent Repositories: 70
  • Downloads: 11,524 Last month
  • Docker Downloads: 1,727,969
Rankings
Docker downloads count: 0.8%
Dependent repos count: 1.8%
Downloads: 3.4%
Average: 4.1%
Dependent packages count: 4.8%
Stargazers count: 6.2%
Forks count: 7.8%
Maintainers (1)
Last synced: 4 months ago
proxy.golang.org: github.com/snakemake/snakefmt
  • Versions: 17
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.3%
Average: 5.5%
Dependent repos count: 5.7%
Last synced: 4 months ago
formulae.brew.sh: snakefmt

Snakemake code formatter

  • Versions: 13
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 134 Last month
Rankings
Dependent packages count: 19.0%
Forks count: 31.0%
Stargazers count: 32.5%
Average: 45.1%
Dependent repos count: 50.7%
Downloads: 92.0%
Last synced: 4 months ago

Dependencies

poetry.lock pypi
  • appdirs 1.4.4 develop
  • atomicwrites 1.4.0 develop
  • attrs 21.4.0 develop
  • certifi 2022.5.18.1 develop
  • charset-normalizer 2.0.12 develop
  • configargparse 1.5.3 develop
  • connection-pool 0.0.3 develop
  • coverage 6.3.3 develop
  • datrie 0.8.2 develop
  • decorator 5.1.1 develop
  • docutils 0.18.1 develop
  • dpath 2.0.6 develop
  • fastjsonschema 2.15.3 develop
  • flake8 3.9.2 develop
  • gitdb 4.0.9 develop
  • gitpython 3.1.27 develop
  • idna 3.3 develop
  • importlib-resources 5.7.1 develop
  • iniconfig 1.1.1 develop
  • isort 5.10.1 develop
  • jinja2 3.1.2 develop
  • jsonschema 4.5.1 develop
  • jupyter-core 4.10.0 develop
  • markupsafe 2.1.1 develop
  • mccabe 0.6.1 develop
  • nbformat 5.4.0 develop
  • packaging 21.3 develop
  • plac 1.3.5 develop
  • pluggy 1.0.0 develop
  • psutil 5.9.0 develop
  • pulp 2.6.0 develop
  • py 1.11.0 develop
  • pycodestyle 2.7.0 develop
  • pyflakes 2.3.1 develop
  • pyparsing 3.0.9 develop
  • pyrsistent 0.18.1 develop
  • pytest 6.2.5 develop
  • pytest-cov 2.12.1 develop
  • pywin32 304 develop
  • pyyaml 6.0 develop
  • ratelimiter 1.2.0.post0 develop
  • requests 2.27.1 develop
  • retry 0.9.2 develop
  • smart-open 6.0.0 develop
  • smmap 5.0.0 develop
  • snakemake 7.7.0 develop
  • stopit 1.1.2 develop
  • tabulate 0.8.9 develop
  • toposort 1.7 develop
  • traitlets 5.2.1.post0 develop
  • urllib3 1.26.9 develop
  • wrapt 1.14.1 develop
  • yte 1.4.0 develop
  • black 22.3.0
  • click 8.1.3
  • colorama 0.4.4
  • importlib-metadata 1.7.0
  • mypy-extensions 0.4.3
  • pathspec 0.9.0
  • platformdirs 2.5.2
  • toml 0.10.2
  • tomli 2.0.1
  • typed-ast 1.5.3
  • typing-extensions 4.2.0
  • zipp 3.8.0
pyproject.toml pypi
  • flake8 ^3.7.9 develop
  • isort ^5.1.0 develop
  • pytest ^6.2.5 develop
  • pytest-cov ^2.8.1 develop
  • snakemake ^7.7 develop
  • black ^22.1.0
  • click ^8.0.0
  • importlib_metadata ^1.7.0
  • python ^3.7.0
  • toml ^0.10.2
.github/workflows/ci.yaml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • codecov/codecov-action v3 composite
  • snok/install-poetry v1 composite
.github/workflows/conventional-prs.yaml actions
  • amannn/action-semantic-pull-request v3.4.0 composite
.github/workflows/release-please.yaml actions
  • GoogleCloudPlatform/release-please-action v2 composite
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • pypa/gh-action-pypi-publish master composite
  • snok/install-poetry v1 composite