Skip to content

Commit 2e1353c

Browse files
Workflow parsing (#17)
* Add workflow parsing * Add a test --------- Co-authored-by: Tomasz Kwiatkowski <[email protected]>
1 parent 4243470 commit 2e1353c

23 files changed

+994
-174
lines changed

example_graphs/example.json renamed to example_workflows/example.json

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"name": "Example workflow",
23
"external_objects" : [
34
"example-object"
45
],
@@ -7,6 +8,7 @@
78
"registers" : 3,
89
"tasks" : [
910
{
11+
"name": "Example script",
1012
"input_registers" : [
1113
1
1214
],
@@ -19,6 +21,7 @@
1921
"type" : "script"
2022
},
2123
{
24+
"name": "Example execution",
2225
"exclusive" : true,
2326
"filesystems" : [
2427
{

example_graphs/run.json renamed to example_workflows/run.json

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"name": "Run the tests and grade the results",
23
"external_objects": [
34
"abc0a.in",
45
"abc0b.in",
@@ -14,7 +15,7 @@
1415
"sol.e"
1516
],
1617
"observable_objects": [],
17-
"observable_registers": 0,
18+
"observable_registers": 1,
1819
"registers": 19,
1920
"tasks": [
2021
{
@@ -35,7 +36,7 @@
3536
}
3637
],
3738
"hard_time_limit": 2137,
38-
"mount_namespace": [
39+
"mount_namespaces": [
3940
{
4041
"mountpoints": [
4142
{
@@ -67,6 +68,7 @@
6768
"/exe",
6869
"</in"
6970
],
71+
"environment": [],
7072
"image" : "/exe",
7173
"mount_namespace" : 0,
7274
"pid_namespace" : 0,
@@ -105,7 +107,7 @@
105107
}
106108
],
107109
"hard_time_limit": 2137,
108-
"mount_namespace": [
110+
"mount_namespaces": [
109111
{
110112
"mountpoints": [
111113
{
@@ -137,6 +139,7 @@
137139
"/exe",
138140
"</in"
139141
],
142+
"environment": [],
140143
"image" : "/exe",
141144
"mount_namespace" : 0,
142145
"pid_namespace" : 0,
@@ -175,7 +178,7 @@
175178
}
176179
],
177180
"hard_time_limit": 2137,
178-
"mount_namespace": [
181+
"mount_namespaces": [
179182
{
180183
"mountpoints": [
181184
{
@@ -207,6 +210,7 @@
207210
"/exe",
208211
"</in"
209212
],
213+
"environment": [],
210214
"image" : "/exe",
211215
"mount_namespace" : 0,
212216
"pid_namespace" : 0,
@@ -245,7 +249,7 @@
245249
}
246250
],
247251
"hard_time_limit": 2137,
248-
"mount_namespace": [
252+
"mount_namespaces": [
249253
{
250254
"mountpoints": [
251255
{
@@ -277,6 +281,7 @@
277281
"/exe",
278282
"</in"
279283
],
284+
"environment": [],
280285
"image" : "/exe",
281286
"mount_namespace" : 0,
282287
"pid_namespace" : 0,
@@ -315,7 +320,7 @@
315320
}
316321
],
317322
"hard_time_limit": 2137,
318-
"mount_namespace": [
323+
"mount_namespaces": [
319324
{
320325
"mountpoints": [
321326
{
@@ -347,6 +352,7 @@
347352
"/exe",
348353
"</in"
349354
],
355+
"environment": [],
350356
"image" : "/exe",
351357
"mount_namespace" : 0,
352358
"pid_namespace" : 0,
@@ -389,7 +395,7 @@
389395
}
390396
],
391397
"hard_time_limit": 2137,
392-
"mount_namespace": [
398+
"mount_namespaces": [
393399
{
394400
"mountpoints": [
395401
{
@@ -434,6 +440,7 @@
434440
"/out",
435441
"wzo_out"
436442
],
443+
"environment": [],
437444
"image" : "/chk",
438445
"mount_namespace" : 0,
439446
"pid_namespace" : 0,
@@ -476,7 +483,7 @@
476483
}
477484
],
478485
"hard_time_limit": 2137,
479-
"mount_namespace": [
486+
"mount_namespaces": [
480487
{
481488
"mountpoints": [
482489
{
@@ -521,6 +528,7 @@
521528
"/out",
522529
"wzo_out"
523530
],
531+
"environment": [],
524532
"image" : "/chk",
525533
"mount_namespace" : 0,
526534
"pid_namespace" : 0,
@@ -563,7 +571,7 @@
563571
}
564572
],
565573
"hard_time_limit": 2137,
566-
"mount_namespace": [
574+
"mount_namespaces": [
567575
{
568576
"mountpoints": [
569577
{
@@ -608,6 +616,7 @@
608616
"/out",
609617
"wzo_out"
610618
],
619+
"environment": [],
611620
"image" : "/chk",
612621
"mount_namespace" : 0,
613622
"pid_namespace" : 0,
@@ -650,7 +659,7 @@
650659
}
651660
],
652661
"hard_time_limit": 2137,
653-
"mount_namespace": [
662+
"mount_namespaces": [
654663
{
655664
"mountpoints": [
656665
{
@@ -695,6 +704,7 @@
695704
"/out",
696705
"wzo_out"
697706
],
707+
"environment": [],
698708
"image" : "/chk",
699709
"mount_namespace" : 0,
700710
"pid_namespace" : 0,
@@ -737,7 +747,7 @@
737747
}
738748
],
739749
"hard_time_limit": 2137,
740-
"mount_namespace": [
750+
"mount_namespaces": [
741751
{
742752
"mountpoints": [
743753
{
@@ -782,6 +792,7 @@
782792
"/out",
783793
"wzo_out"
784794
],
795+
"environment": [],
785796
"image" : "/chk",
786797
"mount_namespace" : 0,
787798
"pid_namespace" : 0,
@@ -855,7 +866,8 @@
855866
"name": "Grade group 1",
856867
"reactive": true,
857868
"input_registers": [13, 14],
858-
"output_registers": [17]
869+
"output_registers": [17],
870+
"script": "<PLACEHOLDER>"
859871
},
860872
{
861873
"type": "script",

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tests =
3232
pytest
3333
pytest-cov
3434
pytest-xdist
35+
deepdiff
3536
django_tests =
3637
pytest-django
3738
django =

src/sio3pack/graph/__init__.py

-3
This file was deleted.

src/sio3pack/graph/graph.py

-17
This file was deleted.

src/sio3pack/graph/node.py

-7
This file was deleted.

src/sio3pack/packages/package/model.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
from typing import Any
33

44
from sio3pack import LocalFile
5+
from sio3pack.exceptions import SIO3PackException
56
from sio3pack.files import File
6-
from sio3pack.graph import Graph, GraphOperation
77
from sio3pack.packages.exceptions import UnknownPackageType
88
from sio3pack.packages.package.handler import NoDjangoHandler
99
from sio3pack.test import Test
1010
from sio3pack.utils.archive import Archive
1111
from sio3pack.utils.classinit import RegisteredSubclassesBase
12-
13-
from sio3pack.exceptions import SIO3PackException
12+
from sio3pack.workflow import Workflow, WorkflowOperation
1413

1514

1615
def wrap_exceptions(func):
@@ -20,7 +19,7 @@ def decorator(*args, **kwargs):
2019
try:
2120
return func(*args, **kwargs)
2221
except SIO3PackException:
23-
raise # Do not wrap SIO3PackExceptions again
22+
raise # Do not wrap SIO3PackExceptions again
2423
except Exception as e:
2524
raise SIO3PackException(f"SIO3Pack raised an exception in {func.__name__} function.", e)
2625

@@ -135,15 +134,15 @@ def get_test(self, test_id: str) -> Test:
135134
pass
136135

137136
@wrap_exceptions
138-
def get_unpack_graph(self) -> GraphOperation | None:
137+
def get_unpack_graph(self) -> WorkflowOperation | None:
139138
pass
140139

141140
@wrap_exceptions
142-
def get_run_graph(self, file: File, tests: list[Test] | None = None) -> GraphOperation | None:
141+
def get_run_graph(self, file: File, tests: list[Test] | None = None) -> WorkflowOperation | None:
143142
pass
144143

145144
@wrap_exceptions
146-
def get_save_outs_graph(self, tests: list[Test] | None = None) -> GraphOperation | None:
145+
def get_save_outs_graph(self, tests: list[Test] | None = None) -> WorkflowOperation | None:
147146
pass
148147

149148
@wrap_exceptions

src/sio3pack/packages/sinolpack/model.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import yaml
66

77
from sio3pack.files import File, LocalFile
8-
from sio3pack.graph import Graph, GraphManager, GraphOperation
98
from sio3pack.packages.exceptions import ImproperlyConfigured
109
from sio3pack.packages.package import Package
1110
from sio3pack.packages.sinolpack.enums import ModelSolutionKind
1211
from sio3pack.util import naturalsort_key
1312
from sio3pack.utils.archive import Archive, UnrecognizedArchiveFormat
13+
from sio3pack.workflow import Workflow, WorkflowManager, WorkflowOperation
1414

1515

1616
class Sinolpack(Package):
@@ -101,8 +101,8 @@ def _from_file(self, file: LocalFile, django_settings=None):
101101
self.rootdir = file.path
102102

103103
try:
104-
graph_file = self.get_in_root("graph.json")
105-
self.graph_manager = GraphManager.from_file(graph_file)
104+
graph_file = self.get_in_root("workflow.json")
105+
self.graph_manager = WorkflowManager.from_file(graph_file)
106106
except FileNotFoundError:
107107
self.has_custom_graph = False
108108

@@ -116,10 +116,10 @@ def _from_db(self, problem_id: int):
116116
if not self.django_enabled:
117117
raise ImproperlyConfigured("sio3pack is not installed with Django support.")
118118

119-
def _default_graph_manager(self) -> GraphManager:
120-
return GraphManager(
119+
def _default_graph_manager(self) -> WorkflowManager:
120+
return WorkflowManager(
121121
{
122-
"unpack": Graph.from_dict(
122+
"unpack": Workflow.from_json(
123123
{
124124
"name": "unpack",
125125
# ...
@@ -178,7 +178,7 @@ def _process_package(self):
178178
self._process_attachments()
179179

180180
if not self.has_custom_graph:
181-
# Create the graph with processed files.
181+
# Create the workflow with processed files.
182182
# TODO: Uncomment this line when Graph will work.
183183
# self.graph_manager = self._default_graph_manager()
184184
pass
@@ -283,8 +283,8 @@ def sort_key(model_solution):
283283
def _process_prog_files(self):
284284
"""
285285
Process all files in the problem's program directory that are used.
286-
Saves all models solution files. If the problem has a custom graph file,
287-
takes the files that are used in the graph. Otherwise, ingen, inwer and
286+
Saves all models solution files. If the problem has a custom workflow file,
287+
takes the files that are used in the workflow. Otherwise, ingen, inwer and
288288
files in `extra_compilation_files` and `extra_execution_files` from config
289289
are saved.
290290
"""
@@ -374,9 +374,9 @@ def _process_attachments(self):
374374
if os.path.isfile(os.path.join(attachments_dir, attachment))
375375
]
376376

377-
def get_unpack_graph(self) -> GraphOperation | None:
377+
def get_unpack_graph(self) -> WorkflowOperation | None:
378378
try:
379-
return GraphOperation(
379+
return WorkflowOperation(
380380
self.graph_manager.get("unpack"),
381381
True,
382382
self._unpack_return_data,

0 commit comments

Comments
 (0)