Skip to content

Commit eebcd27

Browse files
authored
refactor: enable build_graph to be invoked from the service (#1543)
1 parent b9719f3 commit eebcd27

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

renku/cli/log.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,9 @@
8383
"""
8484

8585
import click
86-
from git import NULL_TREE
8786

88-
from renku.core.commands.client import pass_local_client
8987
from renku.core.commands.format.graph import FORMATS
90-
from renku.core.commands.graph import Graph
88+
from renku.core.commands.graph import build_graph
9189

9290

9391
@click.command()
@@ -96,24 +94,7 @@
9694
@click.option("--no-output", is_flag=True, default=False, help="Display commands without output files.")
9795
@click.option("--strict", is_flag=True, default=False, help="Validate triples before output.")
9896
@click.argument("paths", type=click.Path(exists=False), nargs=-1)
99-
@pass_local_client(requires_migration=True)
100-
def log(client, revision, format, no_output, strict, paths):
97+
def log(revision, format, no_output, strict, paths):
10198
"""Show logs for a file."""
102-
graph = Graph(client)
103-
if not paths:
104-
start, is_range, stop = revision.partition("..")
105-
if not is_range:
106-
stop = start
107-
elif not stop:
108-
stop = "HEAD"
109-
110-
commit = client.repo.rev_parse(stop)
111-
paths = (
112-
str(client.path / item.a_path)
113-
for item in commit.diff(commit.parents or NULL_TREE)
114-
# if not item.deleted_file
115-
)
116-
117-
# NOTE shall we warn when "not no_output and not paths"?
118-
graph.build(paths=paths, revision=revision, can_be_cwl=no_output)
99+
graph = build_graph(revision, no_output, paths)
119100
FORMATS[format](graph, strict=strict)

renku/core/commands/graph.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
from pathlib import Path
2323

2424
import attr
25+
from git import NULL_TREE
2526

2627
from renku.core import errors
28+
from renku.core.commands.client import pass_local_client
2729
from renku.core.models.entities import Collection, Entity
2830
from renku.core.models.git import Range
2931
from renku.core.models.provenance.activities import Activity, ProcessRun, Usage, WorkflowRun
@@ -510,3 +512,26 @@ def workflow_has_identical_subprocesses(workflow_, subprocesses_ids_):
510512
return workflow.association.plan
511513

512514
return run
515+
516+
517+
@pass_local_client(requires_migration=True)
518+
def build_graph(client, revision, no_output, paths):
519+
"""Build graph structure."""
520+
graph = Graph(client)
521+
if not paths:
522+
start, is_range, stop = revision.partition("..")
523+
if not is_range:
524+
stop = start
525+
elif not stop:
526+
stop = "HEAD"
527+
528+
commit = client.repo.rev_parse(stop)
529+
paths = (
530+
str(client.path / item.a_path)
531+
for item in commit.diff(commit.parents or NULL_TREE)
532+
# if not item.deleted_file
533+
)
534+
535+
# NOTE shall we warn when "not no_output and not paths"?
536+
graph.build(paths=paths, revision=revision, can_be_cwl=no_output)
537+
return graph

0 commit comments

Comments
 (0)