Skip to content

Commit e6cb2d3

Browse files
feat(api): plan (#2909)
1 parent 36263eb commit e6cb2d3

File tree

15 files changed

+702
-190
lines changed

15 files changed

+702
-190
lines changed

docs/reference/api.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,16 @@ Renku Python API
3232

3333
.. automodule:: renku.ui.api.models.dataset
3434

35+
.. _api-plan:
36+
37+
``Plan, CompositePlan``
38+
-----------------------
39+
40+
.. automodule:: renku.ui.api.models.plan
41+
3542
.. _api-run:
3643

3744
``Inputs, Outputs, and Parameters``
3845
-----------------------------------
3946

40-
.. automodule:: renku.ui.api.models.run
47+
.. automodule:: renku.ui.api.models.parameter

renku/command/workflow.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ def _remove_workflow(name: str, force: bool, plan_gateway: IPlanGateway):
131131
communication.confirm(prompt_text, abort=True, warning=True)
132132

133133
plan = plan or workflows[name]
134-
plan.unfreeze()
135-
plan.invalidated_at = local_now()
136-
plan.freeze()
134+
plan.delete()
137135

138136

139137
def remove_workflow_command():

renku/domain_model/workflow/parameter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ def generate_id(plan_id: str, position: Optional[int] = None, postfix: str = Non
179179
plan_id, parameter_type="parameters", position=position, postfix=postfix
180180
)
181181

182+
def __repr__(self):
183+
return (
184+
f"<Parameter '{self.name}': {self.actual_value} (default: {self.default_value}, prefix: {self.prefix}, "
185+
f"position: {self.position})>"
186+
)
187+
182188
def _get_default_name(self) -> str:
183189
return self._generate_name(base="parameter")
184190

renku/domain_model/workflow/plan.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def validate_name(name: str):
8686
"""Check a name for invalid characters."""
8787
if not re.match("[a-zA-Z0-9-_]+", name):
8888
raise errors.ParameterError(
89-
f"Name {name} contains illegal characters. Only characters, numbers, _ and - are allowed."
89+
f"Name {name} contains illegal characters. Only English letters, numbers, _ and - are allowed."
9090
)
9191

9292
def assign_new_id(self) -> str:
@@ -183,6 +183,16 @@ def __init__(
183183
duplicates_string = ", ".join(duplicates)
184184
raise errors.ParameterError(f"Duplicate input, output or parameter names found: {duplicates_string}")
185185

186+
@property
187+
def keywords_csv(self) -> str:
188+
"""Comma-separated list of keywords associated with workflow."""
189+
return ", ".join(self.keywords)
190+
191+
@property
192+
def deleted(self) -> bool:
193+
"""True if plan is deleted."""
194+
return self.invalidated_at is not None
195+
186196
def is_similar_to(self, other: "Plan") -> bool:
187197
"""Return true if plan has the same inputs/outputs/arguments as another plan."""
188198

@@ -288,11 +298,6 @@ def is_derivation(self) -> bool:
288298
"""Return if an ``Plan`` has correct derived_from."""
289299
return self.derived_from is not None and self.id != self.derived_from
290300

291-
@property
292-
def keywords_csv(self):
293-
"""Comma-separated list of keywords associated with workflow."""
294-
return ", ".join(self.keywords)
295-
296301
def to_argv(self, with_streams: bool = False) -> List[Any]:
297302
"""Convert a Plan into argv list."""
298303
arguments = itertools.chain(self.inputs, self.outputs, self.parameters)
@@ -336,6 +341,12 @@ def copy(self):
336341
"""
337342
return copy.deepcopy(self)
338343

344+
def delete(self, when: datetime = local_now()):
345+
"""Mark a plan as deleted."""
346+
self.unfreeze()
347+
self.invalidated_at = when
348+
self.freeze()
349+
339350

340351
class PlanDetailsJson(marshmallow.Schema):
341352
"""Serialize a plan to a response object."""

renku/ui/api/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"""Renku API."""
1919

2020
from renku.ui.api.models.dataset import Dataset
21+
from renku.ui.api.models.parameter import Input, Link, Mapping, Output, Parameter
22+
from renku.ui.api.models.plan import CompositePlan, Plan
2123
from renku.ui.api.models.project import Project
22-
from renku.ui.api.models.run import Input, Output, Parameter
2324

24-
__all__ = ("Dataset", "Input", "Output", "Parameter", "Project")
25+
__all__ = ("CompositePlan", "Dataset", "Input", "Link", "Mapping", "Output", "Parameter", "Plan", "Project")

renku/ui/api/models/dataset.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
from operator import attrgetter
4343
from pathlib import Path
44-
from typing import Optional
44+
from typing import List, Optional
4545

4646
from renku.command.command_builder.database_dispatcher import DatabaseDispatcher
4747
from renku.domain_model import dataset as core_dataset
@@ -73,14 +73,14 @@ def __init__(self):
7373
self._files = []
7474

7575
@classmethod
76-
def _from_dataset(cls, dataset: core_dataset.Dataset):
76+
def _from_dataset(cls, dataset: core_dataset.Dataset) -> "Dataset":
7777
"""Create an instance from Dataset metadata.
7878
7979
Args:
8080
dataset(core_dataset.Dataset): The core dataset to wrap.
8181
8282
Returns:
83-
An API ``Dataset`` wrapping a core dataset.
83+
Dataset: An API ``Dataset`` wrapping a core dataset.
8484
"""
8585
self = cls()
8686
self._dataset = dataset
@@ -90,14 +90,14 @@ def _from_dataset(cls, dataset: core_dataset.Dataset):
9090

9191
@staticmethod
9292
@ensure_project_context
93-
def list(project):
93+
def list(project) -> List["Dataset"]:
9494
"""List all datasets in a project.
9595
9696
Args:
9797
project: The current project
9898
9999
Returns:
100-
A list of all datasets in the supplied project.
100+
List["Dataset"]: A list of all datasets in the supplied project.
101101
"""
102102
client = project.client
103103
if not client or not client.has_graph_files():

0 commit comments

Comments
 (0)