-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdvc_entry.py
More file actions
29 lines (20 loc) · 966 Bytes
/
Copy pathdvc_entry.py
File metadata and controls
29 lines (20 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Create an entry in the dvc.yaml file for the particular plot."""
from __future__ import annotations
import pathlib
import yaml
from plotting_examples.extract_year_name import extract_year_name_from_plot_py
def add_to_dvc(*, path: pathlib.Path) -> None:
"""Add stages to dvc.yaml based on given path."""
year, name = extract_year_name_from_plot_py(file=str(path))
dvc = yaml.safe_load(pathlib.Path("dvc.yaml").read_text(encoding="utf8"))
stage_name = f"{year}_{name}"
if stage_name not in dvc["stages"]:
# Project not yet added to dvc.yaml
dvc["stages"][stage_name] = {
"wdir": ".",
"cmd": f"poetry run python -m plotting_examples.{year}.{name}.plot",
"deps": [f"plotting_examples/{year}/{name}/plot.py"],
"outs": [{f"images/{year}/{name}.png": {"cache": False}}],
}
with pathlib.Path("dvc.yaml").open("w") as file:
file.write(yaml.dump(dvc))