digitalhub 0.9.0b1__py3-none-any.whl → 0.9.0b3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of digitalhub might be problematic. Click here for more details.

@@ -79,7 +79,7 @@ class Entity(Base):
79
79
  Abstract export method.
80
80
  """
81
81
 
82
- def add_relationship(self, relation: str, source: str, dest: str) -> None:
82
+ def add_relationship(self, relation: str, dest: str, source: str | None = None) -> None:
83
83
  """
84
84
  Add relationship to entity metadata.
85
85
 
@@ -87,10 +87,10 @@ class Entity(Base):
87
87
  ----------
88
88
  relation : str
89
89
  The type of relationship.
90
+ dest : str
91
+ The target entity.
90
92
  source : str
91
93
  The source entity.
92
- dest : str
93
- The target entity..
94
94
 
95
95
  Returns
96
96
  -------
@@ -98,7 +98,9 @@ class Entity(Base):
98
98
  """
99
99
  if self.metadata.relationships is None:
100
100
  self.metadata.relationships = []
101
- obj = {"type": relation, "source": source, "dest": dest}
101
+ obj = {"type": relation, "dest": dest}
102
+ if source is not None:
103
+ obj["source"] = source
102
104
  self.metadata.relationships.append(obj)
103
105
 
104
106
  def to_dict(self) -> dict:
@@ -559,7 +559,7 @@ class OperationsProcessor:
559
559
  context = self._get_context(kwargs["project"])
560
560
  obj = build_entity_from_params(**kwargs)
561
561
  if context.is_running:
562
- obj.add_relationship(Relationship.PRODUCEDBY.value, obj.key, context.get_run_ctx())
562
+ obj.add_relationship(Relationship.PRODUCEDBY.value, context.get_run_ctx())
563
563
 
564
564
  new_obj: MaterialEntity = self._create_context_entity(context, obj.ENTITY_TYPE, obj.to_dict())
565
565
  new_obj = build_entity_from_dict(new_obj)
@@ -79,11 +79,11 @@ class Function(ExecutableEntity):
79
79
  task = self._get_or_create_task(task_kind)
80
80
 
81
81
  # Run function from task
82
- run = task.run(run_kind, local_execution, **kwargs)
82
+ run = task.run(run_kind, save=False, local_execution=local_execution, **kwargs)
83
83
 
84
84
  # Set as run's parent
85
- run.add_relationship(Relationship.RUN_OF.value, run.key + ":" + run.id, self.key)
86
- run.save(update=True)
85
+ run.add_relationship(Relationship.RUN_OF.value, self.key)
86
+ run.save()
87
87
 
88
88
  # If execution is done by DHCore backend, return the object
89
89
  if not local_execution:
@@ -4,8 +4,8 @@ import typing
4
4
 
5
5
  from digitalhub.entities._base.unversioned.entity import UnversionedEntity
6
6
  from digitalhub.entities._commons.enums import EntityTypes
7
- from digitalhub.entities.run.crud import delete_run, get_run, new_run
8
- from digitalhub.factory.api import get_entity_type_from_kind, get_executable_kind
7
+ from digitalhub.entities._operations.processor import processor
8
+ from digitalhub.factory.api import build_entity_from_params, get_entity_type_from_kind, get_executable_kind
9
9
 
10
10
  if typing.TYPE_CHECKING:
11
11
  from digitalhub.entities._base.entity.metadata import Metadata
@@ -42,6 +42,7 @@ class Task(UnversionedEntity):
42
42
  def run(
43
43
  self,
44
44
  run_kind: str,
45
+ save: bool = True,
45
46
  local_execution: bool = False,
46
47
  **kwargs,
47
48
  ) -> Run:
@@ -66,6 +67,7 @@ class Task(UnversionedEntity):
66
67
  exec_type = get_entity_type_from_kind(exec_kind)
67
68
  kwargs[exec_type] = getattr(self.spec, exec_type)
68
69
  return self.new_run(
70
+ save=save,
69
71
  project=self.project,
70
72
  task=self._get_task_string(),
71
73
  kind=run_kind,
@@ -88,21 +90,25 @@ class Task(UnversionedEntity):
88
90
  # CRUD Methods for Run
89
91
  ##############################
90
92
 
91
- def new_run(self, **kwargs) -> Run:
93
+ def new_run(self, save: bool = True, **kwargs) -> Run:
92
94
  """
93
95
  Create a new run.
94
96
 
95
97
  Parameters
96
98
  ----------
99
+ save : bool
100
+ Flag to indicate save.
97
101
  **kwargs : dict
98
- Keyword arguments.
102
+ Keyword arguments to build run. See new_run().
99
103
 
100
104
  Returns
101
105
  -------
102
106
  Run
103
107
  Run object.
104
108
  """
105
- return new_run(**kwargs)
109
+ if save:
110
+ return processor.create_context_entity(**kwargs)
111
+ return build_entity_from_params(**kwargs)
106
112
 
107
113
  def get_run(self, entity_key: str) -> Run:
108
114
  """
@@ -118,9 +124,9 @@ class Task(UnversionedEntity):
118
124
  Run
119
125
  Run object.
120
126
  """
121
- return get_run(entity_key)
127
+ return processor.read_context_entity(entity_key)
122
128
 
123
- def delete_run(self, entity_key: str) -> None:
129
+ def delete_run(self, entity_key: str) -> dict:
124
130
  """
125
131
  Delete run.
126
132
 
@@ -131,6 +137,7 @@ class Task(UnversionedEntity):
131
137
 
132
138
  Returns
133
139
  -------
134
- None
140
+ dict
141
+ Response from backend.
135
142
  """
136
- delete_run(entity_key)
143
+ return processor.delete_context_entity(entity_key)
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  import typing
4
4
 
5
5
  from digitalhub.entities._base.executable.entity import ExecutableEntity
6
- from digitalhub.entities._commons.enums import EntityTypes
6
+ from digitalhub.entities._commons.enums import EntityTypes, Relationship
7
7
  from digitalhub.factory.api import get_run_kind, get_task_kind_from_action
8
8
  from digitalhub.utils.exceptions import BackendError
9
9
 
@@ -44,7 +44,7 @@ class Workflow(ExecutableEntity):
44
44
  def run(
45
45
  self,
46
46
  action: str,
47
- wait: bool = True,
47
+ wait: bool = False,
48
48
  log_info: bool = True,
49
49
  **kwargs,
50
50
  ) -> Run:
@@ -55,7 +55,10 @@ class Workflow(ExecutableEntity):
55
55
  ----------
56
56
  action : str
57
57
  Action to execute.
58
-
58
+ wait : bool
59
+ Flag to wait for execution to finish.
60
+ log_info : bool
61
+ Flag to log information while waiting.
59
62
  **kwargs : dict
60
63
  Keyword arguments passed to Run builder.
61
64
 
@@ -76,7 +79,12 @@ class Workflow(ExecutableEntity):
76
79
  raise BackendError("Cannot run workflow with local backend.")
77
80
 
78
81
  # Run task
79
- run = task.run(run_kind, local_execution=False, **kwargs)
82
+ run = task.run(run_kind, save=False, local_execution=False, **kwargs)
83
+
84
+ # Set as run's parent
85
+ run.add_relationship(Relationship.RUN_OF.value, self.key)
86
+ run.save()
87
+
80
88
  if wait:
81
89
  return run.wait(log_info=log_info)
82
90
  return run
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: digitalhub
3
- Version: 0.9.0b1
3
+ Version: 0.9.0b3
4
4
  Summary: Python SDK for Digitalhub
5
5
  Author-email: Fondazione Bruno Kessler <dslab@fbk.eu>, Matteo Martini <mmartini@fbk.eu>
6
6
  License: Apache License
@@ -27,7 +27,7 @@ digitalhub/entities/_base/context/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeR
27
27
  digitalhub/entities/_base/context/entity.py,sha256=4IWC6f0YKpEBPCXrKlkkvnOqT1urQ4mbjwre4LUWxk4,3270
28
28
  digitalhub/entities/_base/entity/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  digitalhub/entities/_base/entity/builder.py,sha256=vegnR3aBLhuA371vFVQvMXX4KfpVFl-Z7h1ydt6r6Hg,4518
30
- digitalhub/entities/_base/entity/entity.py,sha256=5QP7ZFZ3fjdC6dL26J4TAc_gAsz4esTYR97PIRiwk04,3162
30
+ digitalhub/entities/_base/entity/entity.py,sha256=BFVKE5CToh4JOdwseAGMhdpoCiD3kaGRhNA9SuRCixE,3223
31
31
  digitalhub/entities/_base/entity/metadata.py,sha256=_ogwoo7NOExxVPml9h1vbbAryFiAVpuEuSBQsd_VRjU,2261
32
32
  digitalhub/entities/_base/entity/spec.py,sha256=t0sPXHCb8zyWyMW_UvTfGyUkG_CUEGz427kvGhsQ8s0,1500
33
33
  digitalhub/entities/_base/entity/status.py,sha256=NHB1kLHefoMhhkt_2BFPNojbWMW_Nc8TTGFQNOiyOt0,1044
@@ -58,7 +58,7 @@ digitalhub/entities/_commons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
58
58
  digitalhub/entities/_commons/enums.py,sha256=pjhbOMzAABRPbV6XNt-2Lyn2kLWIFBAwpeboCtvnz1w,1861
59
59
  digitalhub/entities/_commons/utils.py,sha256=_HL6zFSCL_2ug4LpXcxK1MJQQhWL34wj1B2q0Ie0TKU,1792
60
60
  digitalhub/entities/_operations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
61
- digitalhub/entities/_operations/processor.py,sha256=yi-L_mltue3WN8xM5Y-zpwUCb4x4psW5uwd1Lx7Rxo4,46663
61
+ digitalhub/entities/_operations/processor.py,sha256=C5LHmV19Ovk5e4E329TbkdYqIrJ26UOQjnkYBHQk018,46654
62
62
  digitalhub/entities/artifact/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
63
63
  digitalhub/entities/artifact/crud.py,sha256=y69PyoWAYOx-Pl_wnds3M0xSLNbADpdV_xG4zElJ0aI,7824
64
64
  digitalhub/entities/artifact/utils.py,sha256=NNzD2AcIJzmV_Jo_8k5ZcSp2arKcZ07CCIYKn2lvoKM,1320
@@ -100,7 +100,7 @@ digitalhub/entities/function/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
100
100
  digitalhub/entities/function/crud.py,sha256=1-fRWVmOXVV305p0GW0n02FEcengw7QxLxxgxsCC7eM,6592
101
101
  digitalhub/entities/function/_base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
102
102
  digitalhub/entities/function/_base/builder.py,sha256=xTVOpH3GYU-BqtzMEuI3uMtLLvF9IYfrVYMVPkkJc2g,2035
103
- digitalhub/entities/function/_base/entity.py,sha256=VhUQsC5EyJQpCU6FMDRqLIrlJt18g8I6AKd1ZO7320U,3100
103
+ digitalhub/entities/function/_base/entity.py,sha256=YYFxtLAZEhcWOzGlGjqRPXmGRb8wBK1KOXyVPo9ZGSw,3093
104
104
  digitalhub/entities/function/_base/spec.py,sha256=SjCtp3JBUTPTLMY_TE8wM1HPKVl7jH_wFEqQXBj1rfo,274
105
105
  digitalhub/entities/function/_base/status.py,sha256=N-Z1hw13qV7kWFJLQPaH3rRZ2z7AvZeuWYER95lG344,170
106
106
  digitalhub/entities/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -159,7 +159,7 @@ digitalhub/entities/task/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
159
159
  digitalhub/entities/task/crud.py,sha256=_TOgqPvD4bOcfxMPJLCzPe4fz_87AP27RG5cC2941oY,5199
160
160
  digitalhub/entities/task/_base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
161
161
  digitalhub/entities/task/_base/builder.py,sha256=21WEbycCR8yaOPcLLcAITaoQ4ZmBNXJXB-Oy0VfSPrg,2358
162
- digitalhub/entities/task/_base/entity.py,sha256=KGueJ64puhS7DAzG0_-XZSlUmVIOPOFJbtj1S8iWrpg,3179
162
+ digitalhub/entities/task/_base/entity.py,sha256=hOTFxWgSrEs2UPrd9pDZAbdWnL_OrkHr6PwxnAkYG2A,3531
163
163
  digitalhub/entities/task/_base/models.py,sha256=lrkQfKEqqMboiDgtqVdTdlFx4FCH_ksJ2Jku1nK6ARw,4741
164
164
  digitalhub/entities/task/_base/spec.py,sha256=2p_QmhXdTXFrkwNyXtEgzUmc4YyedjS-zsnWsvxJDjw,2412
165
165
  digitalhub/entities/task/_base/status.py,sha256=FCSSQscQ0dHEpXdc5vSrIkTXon9FNNOr0M1KVh2ZVAA,162
@@ -168,7 +168,7 @@ digitalhub/entities/workflow/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
168
168
  digitalhub/entities/workflow/crud.py,sha256=O_Zq30NG-cy7RU1GG88XNi8ids7vrRJAR95PTMYncGM,6517
169
169
  digitalhub/entities/workflow/_base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
170
170
  digitalhub/entities/workflow/_base/builder.py,sha256=wRgot2pbXjc-Cw549uDo1zFOGKdE7wVqxCboeNoXe-Q,2035
171
- digitalhub/entities/workflow/_base/entity.py,sha256=TFteC2Bpg71qrQ0ni9qnowZUYT3WQ_toEmt2BJIdUeM,2228
171
+ digitalhub/entities/workflow/_base/entity.py,sha256=yQKsoJqWRRgYVQJ0wWvu4krx1DpRM9JL4Irb_874Kqs,2516
172
172
  digitalhub/entities/workflow/_base/spec.py,sha256=UoKOUEqKDFACQwctDWfwhro77m3kvjhLDGOhhfRvEzQ,274
173
173
  digitalhub/entities/workflow/_base/status.py,sha256=W0j0CNdu9o2vbk0awpnDrpgwf_fZpgdtct4s0BxRdyk,170
174
174
  digitalhub/factory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -222,8 +222,9 @@ test/local/CRUD/test_artifacts.py,sha256=Y3J_C7SDRSsQd2SGIZjPIOvyTL92B1sTFrUONG3
222
222
  test/local/CRUD/test_dataitems.py,sha256=LQqTzI59uwTGy4zoq8jL0yWVe2W9vXlatkgDU9aB6xg,2968
223
223
  test/local/CRUD/test_models.py,sha256=msosbZuRwIMbZtmi3ZaOva4TjQ4lrzkNu9AguIFhrSo,2929
224
224
  test/local/imports/test_imports.py,sha256=W-YugO0rpJwvtWp57MXaXfEmE-f5iWuCiLY-n0ZU4z8,1271
225
- digitalhub-0.9.0b1.dist-info/LICENSE.txt,sha256=_yVOtnbW7Ss28mp058UEEc1X4Rgj8-kQBP_kj8_Sc88,11585
226
- digitalhub-0.9.0b1.dist-info/METADATA,sha256=US6XAu95Ktv0yNGQJxqOwkfMLyzPDPsKFS5eb8A-wvk,15316
227
- digitalhub-0.9.0b1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
228
- digitalhub-0.9.0b1.dist-info/top_level.txt,sha256=ae9pDfCF27ZoaVAxuBKONMP0lm5P-N_I-e-no1WlvD8,16
229
- digitalhub-0.9.0b1.dist-info/RECORD,,
225
+ test/local/instances/test_validate.py,sha256=bGPKRFR_Tb5nlzzmI_ty_6UVUvYGseE2-pkNVoGWeO0,1842
226
+ digitalhub-0.9.0b3.dist-info/LICENSE.txt,sha256=_yVOtnbW7Ss28mp058UEEc1X4Rgj8-kQBP_kj8_Sc88,11585
227
+ digitalhub-0.9.0b3.dist-info/METADATA,sha256=3AXEwBDEr7vREKj1Jt-IySOXq_h9_QeAAjpuE6eM2VQ,15316
228
+ digitalhub-0.9.0b3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
229
+ digitalhub-0.9.0b3.dist-info/top_level.txt,sha256=ae9pDfCF27ZoaVAxuBKONMP0lm5P-N_I-e-no1WlvD8,16
230
+ digitalhub-0.9.0b3.dist-info/RECORD,,
@@ -0,0 +1,55 @@
1
+ import os
2
+ import pytest
3
+ from glob import glob
4
+ from pathlib import Path
5
+ import json
6
+ from jsonschema import validate
7
+ from digitalhub.factory.factory import factory
8
+
9
+ entities_path = "test/local/instances/entities"
10
+ schemas_path = "test/local/instances/schemas"
11
+
12
+ # Build dict: kind -> path to schema file
13
+ schemas = {}
14
+ for path_to_schema in glob(f"{schemas_path}/**/*.json", recursive=True):
15
+ kind = Path(path_to_schema).stem
16
+ schemas[kind] = path_to_schema
17
+
18
+ # Build dict: name of file to validate -> full path to file
19
+ entity_paths = {}
20
+ for path_to_file in glob(f"{entities_path}/**/*.json", recursive=True):
21
+ file_name = os.path.basename(path_to_file)
22
+
23
+ # If a file in a nested directory causes a name collision, use its full path as name
24
+ if file_name in entity_paths:
25
+ file_name = path_to_file
26
+
27
+ entity_paths[file_name] = path_to_file
28
+
29
+ # Build object from JSON file using factory
30
+ def build_obj(entity_file_path):
31
+ with open(entity_file_path) as f:
32
+ entity = json.load(f)
33
+
34
+ kind = entity["kind"]
35
+ spec = entity["spec"]
36
+
37
+ built = factory.build_spec(kind, **spec)
38
+ return built.to_dict(), kind
39
+
40
+ # Validate built object against its kind's schema
41
+ def is_valid(built, kind):
42
+ with open(schemas[kind]) as schema_file:
43
+ schema = json.load(schema_file)
44
+
45
+ validate(instance=built, schema=schema)
46
+ return True
47
+
48
+ # Tests that each JSON file contained in the specified path can successfully be
49
+ # used to generate an object through the factory, and that each generated object,
50
+ # when exported to dict, validates (through jsonschema) against its kind's schema.
51
+ class TestValidate:
52
+ @pytest.mark.parametrize('file_name', list(entity_paths.keys()))
53
+ def test_validate(self, file_name):
54
+ built, kind = build_obj(f"{entity_paths[file_name]}")
55
+ assert is_valid(built, kind)