xstack 2.0.2__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.
- xstack/__init__.py +167 -0
- xstack/address.py +137 -0
- xstack/app/__init__.py +36 -0
- xstack/app/__main__.py +5 -0
- xstack/app/application.py +692 -0
- xstack/app/config.py +139 -0
- xstack/app/delegate.py +292 -0
- xstack/app/demo.py +42 -0
- xstack/app/dialogs.py +492 -0
- xstack/app/log_view.py +632 -0
- xstack/app/menu.py +362 -0
- xstack/app/options.py +664 -0
- xstack/app/resources.py +20 -0
- xstack/app/runner.py +35 -0
- xstack/app/settings.py +89 -0
- xstack/app/tree.py +582 -0
- xstack/attributes.py +212 -0
- xstack/compat.py +96 -0
- xstack/component.py +1175 -0
- xstack/constants.py +16 -0
- xstack/stack.py +1078 -0
- xstack/test/__init__.py +0 -0
- xstack/test/components.py +360 -0
- xstack/test/test_stack.py +1314 -0
- xstack-2.0.2.dist-info/METADATA +162 -0
- xstack-2.0.2.dist-info/RECORD +29 -0
- xstack-2.0.2.dist-info/WHEEL +5 -0
- xstack-2.0.2.dist-info/licenses/LICENSE +21 -0
- xstack-2.0.2.dist-info/top_level.txt +1 -0
xstack/attributes.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
import signalling
|
|
3
|
+
|
|
4
|
+
from . import address
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# --------------------------------------------------------------------------------------
|
|
8
|
+
class _Attribute:
|
|
9
|
+
"""
|
|
10
|
+
This represents an exposed attribute to a component. Typically, an option allows
|
|
11
|
+
a component to tailor its build to the specific needs and expectations of the user
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
# ----------------------------------------------------------------------------------
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
name: str,
|
|
18
|
+
value: typing.Any = None,
|
|
19
|
+
description: str = "",
|
|
20
|
+
group: str = "",
|
|
21
|
+
should_inherit: bool = False,
|
|
22
|
+
pre_expose: bool = False,
|
|
23
|
+
hidden: bool = False,
|
|
24
|
+
component=None,
|
|
25
|
+
):
|
|
26
|
+
super().__init__()
|
|
27
|
+
|
|
28
|
+
self._name: str = name
|
|
29
|
+
self._value: typing.Any = value
|
|
30
|
+
self._description: str = description
|
|
31
|
+
self._group: str = group
|
|
32
|
+
self._should_inherit: bool = should_inherit
|
|
33
|
+
self._component = component
|
|
34
|
+
self._pre_expose: bool = pre_expose
|
|
35
|
+
self._hidden: bool = hidden
|
|
36
|
+
|
|
37
|
+
# -- Declare our signals which allow events to tie into them
|
|
38
|
+
self.value_changed = signalling.Signal()
|
|
39
|
+
|
|
40
|
+
# ----------------------------------------------------------------------------------
|
|
41
|
+
def name(self) -> str:
|
|
42
|
+
"""
|
|
43
|
+
Returns the name of the option
|
|
44
|
+
"""
|
|
45
|
+
return self._name
|
|
46
|
+
|
|
47
|
+
# ----------------------------------------------------------------------------------
|
|
48
|
+
def description(self) -> str:
|
|
49
|
+
"""
|
|
50
|
+
Returns the description of the option
|
|
51
|
+
"""
|
|
52
|
+
return self._description
|
|
53
|
+
|
|
54
|
+
# ----------------------------------------------------------------------------------
|
|
55
|
+
def group(self):
|
|
56
|
+
"""
|
|
57
|
+
Returns the group this node should result within
|
|
58
|
+
"""
|
|
59
|
+
return self._group
|
|
60
|
+
|
|
61
|
+
# ----------------------------------------------------------------------------------
|
|
62
|
+
def set(self, value: typing.Any):
|
|
63
|
+
"""
|
|
64
|
+
Sets the value of the option and emits a change event call
|
|
65
|
+
"""
|
|
66
|
+
self._value = value
|
|
67
|
+
self.value_changed.emit()
|
|
68
|
+
|
|
69
|
+
# ----------------------------------------------------------------------------------
|
|
70
|
+
def get(self, resolved=True) -> typing.Any:
|
|
71
|
+
"""
|
|
72
|
+
Returns the value of the option
|
|
73
|
+
"""
|
|
74
|
+
# -- If we're set as an address, return the value of the attribute
|
|
75
|
+
# -- we are pointing to rather than the address
|
|
76
|
+
if resolved and address.is_address(self._value):
|
|
77
|
+
return address.get_attribute(self._value, self.component().stack).get()
|
|
78
|
+
|
|
79
|
+
return self._value
|
|
80
|
+
|
|
81
|
+
# ----------------------------------------------------------------------------------
|
|
82
|
+
def should_pre_expose(self) -> bool:
|
|
83
|
+
return self._pre_expose
|
|
84
|
+
|
|
85
|
+
# ----------------------------------------------------------------------------------
|
|
86
|
+
def should_inherit(self):
|
|
87
|
+
"""
|
|
88
|
+
Sets the value of the option and emits a change event call
|
|
89
|
+
"""
|
|
90
|
+
return self._should_inherit
|
|
91
|
+
|
|
92
|
+
# ----------------------------------------------------------------------------------
|
|
93
|
+
def serialise(self):
|
|
94
|
+
"""
|
|
95
|
+
Serialises the option down to a json serialisable dictionary
|
|
96
|
+
"""
|
|
97
|
+
return dict(
|
|
98
|
+
name=self.name(),
|
|
99
|
+
value=self.get(resolved=False),
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# ----------------------------------------------------------------------------------
|
|
103
|
+
def component(self):
|
|
104
|
+
return self._component
|
|
105
|
+
|
|
106
|
+
# ----------------------------------------------------------------------------------
|
|
107
|
+
def is_address(self):
|
|
108
|
+
return address.is_address(self._value)
|
|
109
|
+
|
|
110
|
+
# ----------------------------------------------------------------------------------
|
|
111
|
+
def hidden(self):
|
|
112
|
+
return self._hidden
|
|
113
|
+
|
|
114
|
+
# ----------------------------------------------------------------------------------
|
|
115
|
+
def set_hidden(self, value: bool):
|
|
116
|
+
self._hidden = value
|
|
117
|
+
|
|
118
|
+
# ----------------------------------------------------------------------------------
|
|
119
|
+
def set_pre_expose(self, value: bool):
|
|
120
|
+
self._pre_expose = value
|
|
121
|
+
|
|
122
|
+
# ----------------------------------------------------------------------------------
|
|
123
|
+
def hook_to_parent(self, tags=None, fallback_to_default=True):
|
|
124
|
+
|
|
125
|
+
# -- If this attributes component has no parent, we do nothing
|
|
126
|
+
if not self._component.parent:
|
|
127
|
+
return
|
|
128
|
+
|
|
129
|
+
# -- If we have tags, then attempt to connect based on those tags
|
|
130
|
+
if tags:
|
|
131
|
+
if not isinstance(tags, list):
|
|
132
|
+
tags = [tags]
|
|
133
|
+
|
|
134
|
+
for output in self._component.parent.outputs():
|
|
135
|
+
for tag in tags:
|
|
136
|
+
if tag in output.name().lower():
|
|
137
|
+
self.set(output.address())
|
|
138
|
+
return
|
|
139
|
+
|
|
140
|
+
# -- If we did not match with tags, but we are allowed to fallback
|
|
141
|
+
# -- to the default, then do that now.
|
|
142
|
+
if fallback_to_default and self._component.parent.default_output():
|
|
143
|
+
self.set(self._component.parent.default_output().address())
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
# --------------------------------------------------------------------------------------
|
|
147
|
+
class Option(_Attribute):
|
|
148
|
+
|
|
149
|
+
# ----------------------------------------------------------------------------------
|
|
150
|
+
def __init__(self, *args, **kwargs):
|
|
151
|
+
super().__init__(*args, **kwargs)
|
|
152
|
+
|
|
153
|
+
# ----------------------------------------------------------------------------------
|
|
154
|
+
def address(self):
|
|
155
|
+
return address.form_address(
|
|
156
|
+
self,
|
|
157
|
+
"option",
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# --------------------------------------------------------------------------------------
|
|
161
|
+
class Input(_Attribute):
|
|
162
|
+
|
|
163
|
+
# ----------------------------------------------------------------------------------
|
|
164
|
+
def __init__(self, validate, *args, **kwargs):
|
|
165
|
+
super().__init__(*args, **kwargs)
|
|
166
|
+
|
|
167
|
+
self._validate = validate
|
|
168
|
+
|
|
169
|
+
# ----------------------------------------------------------------------------------
|
|
170
|
+
def requires_validation(self) -> bool:
|
|
171
|
+
"""
|
|
172
|
+
Returns true if this requirement requires validation
|
|
173
|
+
"""
|
|
174
|
+
return self._validate
|
|
175
|
+
|
|
176
|
+
# ----------------------------------------------------------------------------------
|
|
177
|
+
def validate(self) -> bool:
|
|
178
|
+
"""
|
|
179
|
+
Return whether this requirement has hard requirement to be fulfilled
|
|
180
|
+
"""
|
|
181
|
+
if self.get(resolved=False):
|
|
182
|
+
return True
|
|
183
|
+
return False
|
|
184
|
+
|
|
185
|
+
# ----------------------------------------------------------------------------------
|
|
186
|
+
def address(self):
|
|
187
|
+
return address.form_address(
|
|
188
|
+
self,
|
|
189
|
+
"input",
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
# --------------------------------------------------------------------------------------
|
|
194
|
+
class Output(_Attribute):
|
|
195
|
+
|
|
196
|
+
# ----------------------------------------------------------------------------------
|
|
197
|
+
def __init__(self, is_default=False, *args, **kwargs):
|
|
198
|
+
super().__init__(*args, **kwargs)
|
|
199
|
+
self._is_default = is_default
|
|
200
|
+
|
|
201
|
+
def is_default(self):
|
|
202
|
+
return self._is_default
|
|
203
|
+
|
|
204
|
+
def set_default(self, value):
|
|
205
|
+
self._is_default = value
|
|
206
|
+
|
|
207
|
+
# ----------------------------------------------------------------------------------
|
|
208
|
+
def address(self):
|
|
209
|
+
return address.form_address(
|
|
210
|
+
self,
|
|
211
|
+
"output",
|
|
212
|
+
)
|
xstack/compat.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module is here to manage when the serialised data format
|
|
3
|
+
changes.
|
|
4
|
+
|
|
5
|
+
It will cycle through all the old formats, raising the format
|
|
6
|
+
structure up to the latest format.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
def to_latest(data: dict) -> dict:
|
|
10
|
+
"""
|
|
11
|
+
This will raise the given data format to the latest format.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
The data block to raise ot the latest format where required.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
The data in the latest format.
|
|
18
|
+
"""
|
|
19
|
+
# -- If there is no data given then we do nothing but
|
|
20
|
+
# -- return what we were given.
|
|
21
|
+
if not data:
|
|
22
|
+
return data
|
|
23
|
+
|
|
24
|
+
# -- Cycle the converters in order, and each converter will
|
|
25
|
+
# -- raise the format to the subsequent version.
|
|
26
|
+
for converter in converters:
|
|
27
|
+
data = converter(data)
|
|
28
|
+
|
|
29
|
+
# -- Return the raised data format.
|
|
30
|
+
return data
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def original_to_galaxy(data):
|
|
34
|
+
"""
|
|
35
|
+
This will convert data from the original format to the galaxy
|
|
36
|
+
format. The galaxy format being the second format type.
|
|
37
|
+
"""
|
|
38
|
+
# -- If this data is not in an original format we do not
|
|
39
|
+
# -- need to convert.
|
|
40
|
+
if data.get("format", None) != None:
|
|
41
|
+
return data
|
|
42
|
+
|
|
43
|
+
# -- We have an original data file, so we need to convert to
|
|
44
|
+
# -- the galaxy format.
|
|
45
|
+
new_data = dict(
|
|
46
|
+
label=data["label"],
|
|
47
|
+
tree=list(),
|
|
48
|
+
additional_data=data.get("additional_data", dict())
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def add_children(parent_block, build_order_data):
|
|
52
|
+
for child_data in build_order_data["children"]:
|
|
53
|
+
child_uuid = child_data["uuid"]
|
|
54
|
+
child_component_data = data["components"][child_uuid]
|
|
55
|
+
galaxy_child_data = _convert_block_to_galaxy(child_component_data)
|
|
56
|
+
parent_block["children"].append(galaxy_child_data)
|
|
57
|
+
# -- Add the children
|
|
58
|
+
add_children(parent_block=galaxy_child_data, build_order_data=child_data)
|
|
59
|
+
|
|
60
|
+
# -- Cycle the build order
|
|
61
|
+
for build_order_item in data["build_order"]:
|
|
62
|
+
uuid = build_order_item["uuid"]
|
|
63
|
+
component_data = data["components"][uuid]
|
|
64
|
+
galaxy_component_data = _convert_block_to_galaxy(component_data)
|
|
65
|
+
|
|
66
|
+
# -- Add the new data
|
|
67
|
+
new_data["tree"].append(galaxy_component_data)
|
|
68
|
+
|
|
69
|
+
# -- Add the children
|
|
70
|
+
add_children(galaxy_component_data, build_order_item)
|
|
71
|
+
|
|
72
|
+
return new_data
|
|
73
|
+
|
|
74
|
+
def _convert_block_to_galaxy(block):
|
|
75
|
+
new_block = dict()
|
|
76
|
+
new_block["label"] = block["label"]
|
|
77
|
+
new_block["uuid"] = block["uuid"]
|
|
78
|
+
new_block["component_type"] = block["component_type"]
|
|
79
|
+
new_block["enabled"] = block["enabled"]
|
|
80
|
+
new_block["options"] = dict()
|
|
81
|
+
new_block["inputs"] = dict()
|
|
82
|
+
new_block["children"] = list()
|
|
83
|
+
|
|
84
|
+
for option in block["options"]:
|
|
85
|
+
new_block["options"][option["name"]] = option["value"]
|
|
86
|
+
|
|
87
|
+
for input_ in block["inputs"]:
|
|
88
|
+
new_block["inputs"][input_["name"]] = input_["value"]
|
|
89
|
+
|
|
90
|
+
return new_block
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# -- All data is run through this converter list
|
|
94
|
+
converters = [
|
|
95
|
+
original_to_galaxy,
|
|
96
|
+
]
|