Skip to content

Commit

Permalink
Add snakemake reporter plugin skeleton
Browse files Browse the repository at this point in the history
Created a new reporter from the Snakemake plugin template
Added some documentation to README
  • Loading branch information
fbartusch committed Jun 7, 2024
1 parent befd0dd commit 83f3fac
Show file tree
Hide file tree
Showing 12 changed files with 409 additions and 0 deletions.
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,84 @@
# ro-crate_snakemake_tooling
Collection of python tools for processing snakemake metadata for RO-Crate creation


## Snakemake reporter plugin

Documentation how the wrroc reporter plugin is built.

### Setup poetry

Poetry is used for setting up a new plugin from a template.
In my experience, the Python version used here has to match the Python version used with Snakemake environment, otherwise the plugin does not work.
But this should be a solvable problem.

```
conda create --name poetry python=3.12
conda activate poetry
pip install poetry
```

### Create new plugin from the template

Note: The poetry project was added to this repository.
You only have to install the poetry plugin and can use the project in this repository.

```
# Install poetry plugin via
poetry self add poetry-snakemake-plugin
# Create a new poetry project via
poetry new snakemake-report-plugin-wrroc
cd snakemake-report-plugin-wrroc
# Scaffold the project as a snakemake report plugin
poetry scaffold-snakemake-report-plugin
# Next, edit the scaffolded code according to your needs, and publish
# the resulting plugin into a github repository. The scaffold command also
# creates github actions workflows that will immediately start to check and test
# the plugin.
```

### Implement plugin

Implement the report `render` method here:

```
snakemake-report-plugin-wrroc/snakemake_report_plugin_wrroc/__init__.py
```

For plugin development one can take a look what information the base class [ReporterBase](https://github.com/snakemake/snakemake-interface-report-plugins/blob/main/snakemake_interface_report_plugins/reporter.py) provides.

### Build and install plugin

Build wheel and tar.gz:

```
poetry build
```

Install the plugin.

```
pip install --force-reinstall dist/snakemake_report_plugin_wrroc-0.1.0-py3-none-any.whl
```

Snakemake should find the plugin! Note that there are many copy&paste errors for the reporter plugin, even in the poetry template repository. Most of the time the term `executor plugin` is used instead of `reporter plugin`.

```
snakemake -h
[...]
wrroc executor settings:
--report-wrroc-myparam VALUE
Some help text (default: <dataclasses._MISSING_TYPE object at 0x7f0091b3f140>)
```

### Create a report

Test the reporter plugin in the skim2mt directory, where the `.snakemake/metadata` resides:

```
snakemake --reporter wrroc
```
94 changes: 94 additions & 0 deletions snakemake-report-plugin-wrroc/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CI

on:
push:
branches:
- main
pull_request:

env:
PYTHON_VERSION: 3.11

jobs:
formatting:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install poetry
run: pip install poetry

- name: Determine dependencies
run: poetry lock

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: poetry

- name: Install Dependencies using Poetry
run: poetry install

- name: Check formatting
run: poetry run black --check .

linting:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install poetry
run: pip install poetry

- name: Determine dependencies
run: poetry lock

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: poetry

- name: Install Dependencies using Poetry
run: poetry install

- name: Check code
run: poetry run flake8

testing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install poetry
run: pip install poetry

- name: Determine dependencies
run: poetry lock

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: poetry

- name: Install dependencies
run: poetry install

- name: Run pytest
run: poetry run coverage run -m pytest tests/tests.py

- name: Run Coverage
run: poetry run coverage report -m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: PR
on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize

jobs:
title-format:
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53 changes: 53 additions & 0 deletions snakemake-report-plugin-wrroc/.github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
on:
push:
branches:
- main

name: release-please

env:
PYTHON_VERSION: 3.11

jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
- uses: GoogleCloudPlatform/release-please-action@v3
id: release
with:
release-type: python
package-name: snakemake-report-plugin-wrroc

publish:
runs-on: ubuntu-latest
needs: release-please
if: ${{ needs.release-please.outputs.release_created }}
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install poetry
run: pip install poetry

- name: Determine dependencies
run: poetry lock

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: poetry

- name: Install Dependencies using Poetry
run: |
poetry install
- name: Publish to PyPi
env:
PYPI_USERNAME: __token__
PYPI_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: poetry publish --build --username $PYPI_USERNAME --password $PYPI_PASSWORD
Empty file.
Binary file not shown.
Binary file not shown.
61 changes: 61 additions & 0 deletions snakemake-report-plugin-wrroc/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions snakemake-report-plugin-wrroc/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[build-system]
requires = [ "poetry-core",]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "snakemake-report-plugin-wrroc"
version = "0.1.0"
description = ""
authors = [ "fbartusch <[email protected]>",]
readme = "README.md"
repository = "https://github.com/your/plugin"
documentation = "https://snakemake.github.io/snakemake-plugin-catalog/plugins/report/wrroc.html"

[tool.poetry.dependencies]
python = "^3.12"
snakemake-interface-common = "^1.17.2"
snakemake-interface-report-plugins = "^1.0.0"
7 changes: 7 additions & 0 deletions snakemake-report-plugin-wrroc/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
# Recommend matching the black line length (default 88),
# rather than using the flake8 default of 79:
max-line-length = 88
extend-ignore =
# See https://github.com/PyCQA/pycodestyle/issues/373
E203,
Loading

0 comments on commit 83f3fac

Please sign in to comment.