Skip to content

Commit

Permalink
Update template documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
grst committed Jan 27, 2025
1 parent f67c66b commit 14870f5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
63 changes: 62 additions & 1 deletion docs/user_guide/templates.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
# Project and stage templates

TODO
DSO provides a templating engine that allows to quickly bootrstap a project (`dso init`), folder, or stages (`dso create`).
Templates are based on [jinja2](https://jinja.palletsprojects.com/en/stable/templates/).

## Available templates

DSO currently comes with the following templates:

Project templates:

- [default](https://github.com/Boehringer-Ingelheim/dso/tree/main/src/dso/templates/init/default) - Default template, with
integration of `git`, `dvc`, `uv`, `pre-commit`, and `editorconfig`.

Folder templates:

- [default](https://github.com/Boehringer-Ingelheim/dso/tree/main/src/dso/templates/folder/default) - This one is very minimal, just a folder with `dvc.yaml` and `params.in.yaml` files.

Stage templates:

- [quarto](https://github.com/Boehringer-Ingelheim/dso/tree/main/src/dso/templates/stage/quarto) - Template for quarto notebook in R
- [bash](https://github.com/Boehringer-Ingelheim/dso/tree/main/src/dso/templates/stage/bash) - Template for executing a bash snippet

The source code of the templates can be [inspected on GitHub](https://github.com/Boehringer-Ingelheim/dso/tree/main/src/dso/templates).
Templates shipped with DSO are [licensed](https://github.com/Boehringer-Ingelheim/dso/blob/main/src/dso/templates/LICENSE) under the Creative Commons Zero v1.0
Universal license.

## Using custom template libraries

Currently, dso only supports the internal templates mentioned above. However, we plan to add support to custom
stage templates soon. This enables some interesting use-cases:

- Organization-specific templates: Use templates that make it easier to comply with internal processes or apply
corporate design.
- Best-practice codebases: Start off common analysis types off a predefined template. We believe that some analyses
require more flexibility than predefined worflows such as nf-core, but can still benefit from a structured
"base" document to get started with.

## Writing templates

Template directories are recursively copied to their destination and files are rendered with [jinja2](https://jinja.palletsprojects.com/en/stable/templates/).
You can use all features of jinja2 such as `if/else` blocks or loops. Additionally, you have access to the
following variables:

Available variables for **project** templates:

| variable | content |
| ------------------- | ----------------------------------------------------- |
| project_name | project/folder name as provided to the `dso init` CLI |
| project_description | description as provided to the `dso init` CLI |

Available variables for **folder** templates:

| variable | content |
| ----------- | ------------------------------------------------------ |
| folder_name | folder name as provided to the `dso create folder` CLI |

Available variables for **stage** templates:

| variable | content |
| ----------------- | ----------------------------------------------------- |
| stage_name | folder name as provided to the `dso create stage` CLI |
| stage_description | description as provided to the `dso create stage` CLI |
| stage_path | Path to the stage relative to the project root |
2 changes: 1 addition & 1 deletion src/dso/cli/_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def dso_create_folder(name: str | None = None):

target_dir.mkdir(exist_ok=True)

instantiate_template(get_template_path("folder", template), target_dir, stage_name=name)
instantiate_template(get_template_path("folder", template), target_dir, folder_name=name)
log.info("[green]Folder created successfully.")
compile_all_configs([target_dir])

Expand Down

0 comments on commit 14870f5

Please sign in to comment.