recopytex/recopytex.py

51 lines
1.1 KiB
Python
Raw Normal View History

2019-08-04 14:25:44 +00:00
#!/usr/bin/env python
# encoding: utf-8
import click
from pathlib import Path
import yaml
import sys
import papermill as pm
with open("recoconfig.yml", "r") as config:
config = yaml.load(config, Loader=yaml.FullLoader)
@click.group()
def cli():
pass
@cli.command()
def print_config():
click.echo(config.key())
@cli.command()
@click.argument("csv_file")
def report(csv_file):
csv = Path(csv_file)
if not csv.exists():
click.echo(f"{csv_file} does not exists")
sys.exit(1)
if csv.suffix != ".csv":
click.echo(f"{csv_file} has to be a csv file")
sys.exit(1)
*a, tribe, assessment_file = csv_file.split("/")
assessment_desc = assessment_file.split(".")[0]
assessment_name = assessment_desc.split("_")[-1].capitalize()
template = Path(config["templates"]) / "tpl_evaluation.ipynb"
dest = Path(config["output"]) / tribe / assessment_name / f"{assessment_name}.ipynb"
dest.parent.mkdir(parents=True, exist_ok=True)
pm.execute_notebook(
str(template), str(dest), parameters=dict(tribe=tribe, assessment=assessment_name)
)
if __name__ == "__main__":
cli()