-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint to get project workflow
- Loading branch information
1 parent
5248030
commit ab3e082
Showing
6 changed files
with
1,472 additions
and
9 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
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,32 @@ | ||
"""Functionality for working with DVC.""" | ||
|
||
import os | ||
import tempfile | ||
from dvc.commands import dag | ||
from dvc.repo import Repo | ||
import yaml | ||
|
||
|
||
def make_mermaid_diagram(pipeline: dict) -> str: | ||
"""Create a Mermaid diagram from a pipeline file (typically ``dvc.yaml``). | ||
This is a little hacky since we need to create a Git and DVC repo in order | ||
to run the commands in DVC. | ||
""" | ||
wd_orig = os.getcwd() | ||
try: | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
os.chdir(tmpdirname) | ||
with open("dvc.yaml", "w") as f: | ||
yaml.safe_dump(pipeline, f) | ||
with Repo.init( | ||
".", | ||
no_scm=True, | ||
force=False, | ||
subdir=False, | ||
) as repo: | ||
d = dag._build(repo) | ||
mm = dag._show_mermaid(d, markdown=False) | ||
finally: | ||
os.chdir(wd_orig) | ||
return mm |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Tests for the ``dvc`` module.""" | ||
|
||
from app.dvc import make_mermaid_diagram | ||
|
||
|
||
def test_make_mermaid_diagram(): | ||
pipeline = { | ||
"stages": { | ||
"do-something": { | ||
"cmd": "echo sup", | ||
"deps": ["somefile.py"], | ||
"outs": ["something.png"], | ||
}, | ||
"do-something-else": { | ||
"cmd": "echo sup2", | ||
"deps": ["something.png"], | ||
"outs": ["else.pdf"], | ||
}, | ||
} | ||
} | ||
mm = make_mermaid_diagram(pipeline) | ||
return mm |
Oops, something went wrong.