-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from beardymcjohnface/dev
DEV: Can now double-handle --profile
- Loading branch information
Showing
12 changed files
with
174 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: Codecov | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: | ||
- '.github/**' | ||
- 'build/**' | ||
- 'tests/**' | ||
- '{{cookiecutter.project_slug}}/**' | ||
pull_request: | ||
branches: [ "main" ] | ||
paths: | ||
- '.github/**' | ||
- 'build/**' | ||
- 'tests/**' | ||
- '{{cookiecutter.project_slug}}/**' | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
tests: | ||
name: "Codecov using python ${{ matrix.python-version }} on ${{ matrix.os }}" | ||
runs-on: ${{ matrix.os }} | ||
|
||
defaults: | ||
run: | ||
shell: bash -el {0} | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
python-version: ["3.10"] | ||
|
||
steps: | ||
- uses: "actions/checkout@v3" | ||
with: | ||
fetch-depth: 0 | ||
|
||
# Setup env | ||
- uses: conda-incubator/setup-miniconda@v2 | ||
with: | ||
activate-environment: snaketool | ||
environment-file: build/environment.yaml | ||
python-version: ${{ matrix.python-version }} | ||
auto-activate-base: false | ||
|
||
- name: "Setup Snaketool on ${{ matrix.os }} for Python ${{ matrix.python-version }}" | ||
run: | | ||
cookiecutter --no-input ./ | ||
cd my_snaketool/ | ||
python -m pip install --upgrade pip | ||
pip install . | ||
- name: "Generate coverage report on ${{ matrix.os }} for Python ${{ matrix.python-version }}" | ||
run: | | ||
pip install pytest pytest-cov | ||
pytest --cov=./ --cov-report=xml --cov-append | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
file: coverage.xml | ||
fail_ci_if_error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# Snakemake config | ||
input: | ||
output: '{{cookiecutter.project_slug}}.out/' | ||
log: '{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}.log' | ||
# Namespaced config file example | ||
{{cookiecutter.project_slug}}: | ||
args: # Command line args will be (over)written here at runtime | ||
input: | ||
output: | ||
# Add customisable config here |
2 changes: 2 additions & 0 deletions
2
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/system_config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{cookiecutter.project_slug}}: | ||
# Config you don't want users to change |
43 changes: 9 additions & 34 deletions
43
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/workflow/Snakefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,24 @@ | ||
import glob | ||
|
||
# Update default config with runtime config | ||
configfile: os.path.join(workflow.basedir, "../", "config", "config.yaml") | ||
configfile: os.path.join(workflow.basedir, "../", "config", "system_config.yaml") | ||
config.update(config["{{cookiecutter.project_slug}}"]) # convenience if using namespaced config | ||
|
||
configfile: os.path.join(workflow.basedir, '../', 'config', 'config.yaml') | ||
|
||
|
||
# Concatenate Snakemake's own log file with the master log file | ||
def copy_log_file(): | ||
files = glob.glob(os.path.join(".snakemake", "log", "*.snakemake.log")) | ||
if not files: | ||
return None | ||
current_log = max(files, key=os.path.getmtime) | ||
shell("cat " + current_log + " >> " + config['log']) | ||
|
||
onsuccess: | ||
copy_log_file() | ||
|
||
onerror: | ||
copy_log_file() | ||
|
||
|
||
# Target file | ||
outTouch = os.path.join(config['output'], config['input']) | ||
|
||
|
||
# Mark target rules | ||
target_rules = [] | ||
def targetRule(fn): | ||
assert fn.__name__.startswith('__') | ||
target_rules.append(fn.__name__[2:]) | ||
return fn | ||
# Rules files | ||
include: os.path.join(workflow.basedir, "rules", "preflight.smk") | ||
include: os.path.join(workflow.basedir, "rules", "example.smk") | ||
|
||
|
||
# Target rules | ||
@targetRule | ||
rule all: | ||
input: | ||
outTouch | ||
targets | ||
|
||
|
||
@targetRule | ||
rule print_targets: | ||
run: | ||
print("\nTop level rules are: \n", file=sys.stderr) | ||
print("* " + "\n* ".join(target_rules) + "\n\n", file=sys.stderr) | ||
|
||
|
||
rule yeet: | ||
output: | ||
touch(outTouch) |
5 changes: 5 additions & 0 deletions
5
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/workflow/envs/example.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: python | ||
channels: | ||
- defaults | ||
dependencies: | ||
- python>=3.9 |
11 changes: 11 additions & 0 deletions
11
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/workflow/rules/example.smk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
rule example: | ||
output: | ||
os.path.join(dirs["results"], "example.done") | ||
conda: | ||
os.path.join(dirs["envs"], "example.yaml") | ||
benchmark: | ||
os.path.join(dirs["bench"], "example.txt") | ||
log: | ||
os.path.join(dirs["logs"], "example.err") | ||
script: | ||
os.path.join(dirs["scripts"], "example.py") |
43 changes: 43 additions & 0 deletions
43
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/workflow/rules/preflight.smk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
# Directories | ||
dirs = { | ||
"logs": os.path.join(config["args"]["output"], "logs"), | ||
"bench": os.path.join(config["args"]["output"], "bench"), | ||
"results": os.path.join(config["args"]["output"], "results"), | ||
"envs": os.path.join(workflow.basedir, "envs"), | ||
"scripts": os.path.join(workflow.basedir, "scripts") | ||
} | ||
|
||
|
||
# Targets | ||
targets = [ | ||
os.path.join(dirs["results"], "example.done") | ||
] | ||
|
||
|
||
# Misc | ||
target_rules = [] | ||
|
||
|
||
def targetRule(fn): | ||
"""Mark rules as target rules for rule print_targets""" | ||
assert fn.__name__.startswith("__") | ||
target_rules.append(fn.__name__[2:]) | ||
return fn | ||
|
||
|
||
def copy_log_file(): | ||
"""Concatenate Snakemake log to output log file""" | ||
import glob | ||
|
||
files = glob.glob(os.path.join(".snakemake", "log", "*.snakemake.log")) | ||
if files: | ||
current_log = max(files, key=os.path.getmtime) | ||
shell("cat " + current_log + " >> " + config["args"]["log"]) | ||
|
||
|
||
onsuccess: | ||
copy_log_file() | ||
|
||
onerror: | ||
copy_log_file() |
7 changes: 7 additions & 0 deletions
7
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/workflow/scripts/example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
def main(**kwargs): | ||
open(kwargs["output"], "w").close() | ||
|
||
|
||
if __name__ == "__main__": | ||
main(output=snakemake.output[0],) |