xstack 2.0.2__tar.gz

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-2.0.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Michael Malinowski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
xstack-2.0.2/PKG-INFO ADDED
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: xstack
3
+ Version: 2.0.2
4
+ Summary: xstack is an execution framework
5
+ Home-page: https://github.com/mikemalinowski/xstack
6
+ Author: Mike Malinowski
7
+ Author-email: mike.external@outlook.com
8
+ Keywords: xstack
9
+ Classifier: Programming Language :: Python
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: factories
15
+ Requires-Dist: signalling
16
+ Dynamic: author
17
+ Dynamic: author-email
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: keywords
23
+ Dynamic: license-file
24
+ Dynamic: requires-dist
25
+ Dynamic: summary
26
+
27
+
28
+ # xstack
29
+
30
+ xstack is an execution framework which allows a developer to define components which
31
+ can then be added to the stack - declaring options, requirements and outputs.
32
+
33
+ ![xstack Image](xstack/app/_res/icon.png)
34
+
35
+ ## Installing
36
+
37
+ You can install xstack using `pip install xstack`
38
+
39
+ ## Getting Started
40
+
41
+ The stack can be executed to run sequentially from top to bottom, from a specific
42
+ point, to a specific point or individiaully.
43
+
44
+ Below is an example of what it looks like to add components to the stack, manipulate
45
+ the build order and execute a stack
46
+
47
+ ```python
48
+ import xstack
49
+
50
+ COMPONENT_PATH = "location/to/where/you/store/your/components"
51
+
52
+ # -- Create a new stack. When we create a stack we need to tell it where
53
+ # -- to look for components
54
+ stack = xstack.Stack(
55
+ component_paths=[COMPONENT_PATH],
56
+ )
57
+
58
+ # -- Add a component of type "RunTestComponent" into the stack. Note that you
59
+ # -- can see this component within the /test directory of xstack
60
+ component_a = stack.add_component(
61
+ label="test a",
62
+ component_type="RunTestComponent",
63
+ )
64
+
65
+ # -- Add the same component type again.
66
+ component_b = stack.add_component(
67
+ label="test b",
68
+ component_type="RunTestComponent",
69
+ )
70
+
71
+ # -- Our stack now has two components in it, by default these will be in
72
+ # -- a flat list and ordered based on the order they were added. Here we will
73
+ # -- make component_a a child of component_b - meaning that component_a will
74
+ # -- always execute after component_b
75
+ stack.set_build_position(
76
+ component_a,
77
+ parent=component_b,
78
+ )
79
+
80
+ # -- Execute the whole stack
81
+ stack.build()
82
+
83
+ # -- Execute just a single component
84
+ stack.build(build_only=component_a)
85
+ ```
86
+
87
+ Defining a component is relatively simple...
88
+
89
+ ```python
90
+ import xstack
91
+
92
+ class MyXStackComponent(xstack.Component):
93
+
94
+ # -- Every component needs an identifier which can be used to differentiate
95
+ # -- it from other components
96
+ identifier = "MyExample"
97
+
98
+ def __init__(self, *args, **kwargs):
99
+ super(MyXStackComponent, self).__init__(*args, **kwargs)
100
+
101
+ # -- Declare a requirement. A Requirement is an attribute of a component
102
+ # -- that typically expects to be filled before execution. By default
103
+ # -- all requirements will be validated for a value before executing.
104
+ self.declare_requirement(
105
+ name="example_requirement",
106
+ value="",
107
+ group="Some Requirements",
108
+ )
109
+
110
+ # -- Options are considered to be attributes which are not essential to
111
+ # -- be set but might tailor or alter what the result is
112
+ self.declare_option(
113
+ name="test_option",
114
+ value="foo",
115
+ pre_expose=True,
116
+ )
117
+
118
+ # -- An output is an attribute which this component promises to fullful
119
+ # -- during the execution. This is useful because instead of specifying a
120
+ # -- value to a requirement, you can infact specify an output attribute
121
+ # -- address, and the value will be resolved at execution time.
122
+ self.declare_output(
123
+ name="result"
124
+ )
125
+
126
+ # -- This function is where we write any code that should be run during the
127
+ # -- stack execution
128
+ def run(self):
129
+ return self.option("test_option").get() == "bar"
130
+
131
+ ```
132
+
133
+ # App
134
+
135
+ This is a Qt based application/widget which is designed to visualise an xstack stack.
136
+
137
+ The app is not a requirement for using xstack, but can be used as a front end to build
138
+ and execute stacks.
139
+
140
+ ![xstack Image](xstack/app/_res/xstack_demo.png)
141
+
142
+ ## Installing
143
+
144
+ You can install the xstack_app using `pip install xstack_app`
145
+
146
+ Note: This requires either PySide2 or PySide6 to also be available.
147
+
148
+ ## Running
149
+
150
+ ```python
151
+ import xstack
152
+
153
+ xstack.launch(blocking=True)
154
+ ```
155
+
156
+ If you want to run it with some example components, you can run:
157
+
158
+ ```python
159
+ import xstack
160
+
161
+ xstack.launch_demo(blocking=True)
162
+ ```
xstack-2.0.2/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
xstack-2.0.2/setup.py ADDED
@@ -0,0 +1,31 @@
1
+ import os
2
+ import setuptools
3
+
4
+ if os.path.exists('README.md'):
5
+ with open('README.md', 'r') as fh:
6
+ long_description = fh.read()
7
+
8
+ else:
9
+ long_description = 'A python package for developing stack based execution tools'
10
+
11
+ setuptools.setup(
12
+ name='xstack',
13
+ version='2.0.2',
14
+ author='Mike Malinowski',
15
+ author_email='mike.external@outlook.com',
16
+ description='xstack is an execution framework',
17
+ long_description=long_description,
18
+ long_description_content_type='text/markdown',
19
+ url='https://github.com/mikemalinowski/xstack',
20
+ packages=setuptools.find_packages(),
21
+ classifiers=[
22
+ 'Programming Language :: Python',
23
+ 'License :: OSI Approved :: MIT License',
24
+ 'Operating System :: OS Independent',
25
+ ],
26
+ install_requires=[
27
+ "factories",
28
+ "signalling",
29
+ ],
30
+ keywords="xstack",
31
+ )
@@ -0,0 +1,167 @@
1
+ """
2
+ xstack is a hierarchical component execution framework. Components as classes
3
+ which expose parameters (Requirements and Options) and implement a run method
4
+ which is exectuted.
5
+
6
+ The stack itself is a hierarchical list, where a component can be made a child
7
+ or parent of other components. The execution of the stack will always respect
8
+ the hierarchical order.
9
+
10
+ The stack can be triggered to execute the whole stack, all children of a particular
11
+ component (including itself) or just a single component.
12
+
13
+ Component classes are searched for through an abstract factory. You can declare
14
+ folder paths using the XSTACK_COMPONENT_PATHS environment variable, or you can
15
+ register component classes directly using any of the following:
16
+
17
+ ```
18
+ stack = Stack()
19
+ stack.component_library.register_path(path)
20
+ stack.component_library.register_module(path_to_py_file)
21
+ stack.component_library.register_item(component_class)
22
+ ```
23
+
24
+ Components can be super simple or quite complex depending on its needs. Here is an
25
+ example of a very simple Component:
26
+
27
+ ```
28
+ import xstack
29
+
30
+ class MyComponent(xstack.Component):
31
+
32
+ identifier = "MyCustomComponent"
33
+
34
+ def run(self):
35
+ print("Running in my custom component")
36
+ ```
37
+
38
+ However, a component can also expose Requirements and Options. Any external code
39
+ or tools should only ever interact with the component through these two methods.
40
+
41
+ Requirements and Options are almost identical at a code level, but conceptually they
42
+ are quite different. A Requirement is considered to be an expected input needed in
43
+ order to evaluate the component whilst an Option is considered to be something that
44
+ alters how the end result my appear.
45
+
46
+ At a code level, the only different is that Requirements can be set to always
47
+ validate, and if they do not have a value set for them they will fail validation
48
+ during the building of the stack.
49
+
50
+ Here is an example of a component using options and requirements.
51
+
52
+ ```
53
+ class ResprayVehicle(xstack.Component):
54
+ identifier = "respray_vehicle"
55
+
56
+ def __init__(self, *args, **kwargs):
57
+ super().__init__(*args, **kwargs)
58
+
59
+ self.declare_requirement(
60
+ name="vehicle_instance",
61
+ value=None,
62
+ validate=True,
63
+ )
64
+
65
+ self.declare_option(
66
+ name="color",
67
+ value="orange",
68
+ )
69
+
70
+ def run(self):
71
+ vehicle = self.requirement("vehicle_instance").get()
72
+ color = self.option("color").get()
73
+
74
+ print(f"respraying {vehicle} to be {color}")
75
+ ```
76
+ In this example we see that we have exposed "vehicle_instance" as a requirement as
77
+ in this instance, we always need a vehicle to paint. We then expose the color as an
78
+ option with a default value.
79
+
80
+ Registering the components with the stack does not add them to the stack, it just
81
+ makes them available to the stack. You can add components to the stack using the
82
+ following syntax:
83
+
84
+ ```
85
+ stack = Stack()
86
+
87
+ stack.add_component(
88
+ label="Example",
89
+ component_type="MyCustomComponentIdentifier",
90
+ )
91
+ ```
92
+
93
+ All components must inherit from xstack.Component, and therefore you will need to
94
+ provide your class with an identifier. This is the component_type.
95
+
96
+ Once a component has been added to the stack you can execute that stack using
97
+
98
+ stack.build()
99
+
100
+ Stacks are hierarchical, so you can add multiple components and form a hierarchical
101
+ relationship, such as...
102
+
103
+ ```
104
+ stack = Stack()
105
+
106
+ # -- Create three components, they will execute in the order
107
+ # -- they are added by default
108
+ component_a = stack.add_component(
109
+ label="A",
110
+ component_type="MyCustomComponent",
111
+ )
112
+
113
+ component_b = stack.add_component(
114
+ label="B",
115
+ component_type="MyCustomComponent",
116
+ )
117
+
118
+ component_c = stack.add_component(
119
+ label="C",
120
+ component_type="MyCustomComponent",
121
+ )
122
+
123
+ # -- At the moment, the order is completely flat, and we can choose
124
+ # -- to change that order by doing this. Component A was added first, so it
125
+ # -- would have a build position of zero by default. By setting it to 1 it means
126
+ # -- that component b will now move to the top of the list, and component a will
127
+ # -- execute after it
128
+ stack.set_build_position(
129
+ component_a,
130
+ index=1,
131
+ )
132
+
133
+ # -- As well as changing the order, we can make it hierarchical. Lets make
134
+ # -- component_a be a child of component_c. By doing this we can always guarantee
135
+ # -- that component_a will always execute after component_c, even if component_c
136
+ # -- is moved in the hierarchy.
137
+ stack.set_build_position(
138
+ component_a,
139
+ parent=component_c,
140
+ )
141
+ ```
142
+ Whilst a hierarchical structure in this form can always be flattened - and is always
143
+ executed in a linear fashion, it can make for a much more intuitive format for
144
+ categories of executions.
145
+ """
146
+ # -- Expose the stack. This is the main class of the module and handles the
147
+ # -- execution of the components
148
+ from .stack import Stack
149
+
150
+ # -- Expose the Component. All components must ultimately inherit from this class
151
+ from .component import Component
152
+ from .component import MissingComponent
153
+
154
+ from . import address
155
+ from . import constants
156
+
157
+ # -- Expose the app if Qt is available. We do not fail the module
158
+ # -- load if Qt is not present as we allow xstack to run headless
159
+ try:
160
+ from . import app
161
+ from .app.demo import launch_demo
162
+ from .app import launch
163
+
164
+ except ImportError:
165
+ pass
166
+
167
+ __version__ = "2.0.2"
@@ -0,0 +1,137 @@
1
+ """
2
+ This module handles the logic around resolving and constructing attribute
3
+ addresses within a stack.
4
+
5
+ Addresses always take the form of
6
+
7
+ [COMPONENT LABEL].[CATEGORY].[ATTRIBUTE NAME]
8
+ """
9
+ import re
10
+
11
+ ADDRESS_REGEX = re.compile(r"\[.*\]\.\[(option|input|output)\]\.\[.*\]")
12
+
13
+
14
+ # --------------------------------------------------------------------------------------
15
+ def get_label(address):
16
+ """
17
+ Returns the label part of the address
18
+ """
19
+ try:
20
+ return address.split(".")[0][1:-1]
21
+
22
+ except IndexError:
23
+ return None
24
+
25
+
26
+ # --------------------------------------------------------------------------------------
27
+ def get_category(address):
28
+ """
29
+ Returns the category (or type) part of the address
30
+ """
31
+ try:
32
+ return address.split(".")[1][1:-1]
33
+
34
+ except IndexError:
35
+ return None
36
+
37
+
38
+
39
+ # --------------------------------------------------------------------------------------
40
+ def get_attribute_name(address):
41
+ """
42
+ Returns the attribute name from the address
43
+ """
44
+ try:
45
+ return address.split(".")[2][1:-1]
46
+
47
+ except IndexError:
48
+ return None
49
+
50
+
51
+ # --------------------------------------------------------------------------------------
52
+ def get_attribute(address, stack):
53
+ """
54
+ This will convert an address to an actual attribute within the stack
55
+
56
+ Args:
57
+ address: Address to resolve
58
+ stack: Stack to get attribute from
59
+
60
+ Returns:
61
+ xstack.Attribute
62
+ """
63
+
64
+ # -- Break the address into its component parts
65
+ component_label = get_label(address)
66
+ category = get_category(address)
67
+ attribute_name = get_attribute_name(address)
68
+
69
+ # -- Attempt to find a matching component
70
+ component = _get_component_with_label(
71
+ component_label,
72
+ stack,
73
+ )
74
+
75
+ # -- Switch out what we are looking for based on the classification
76
+ if category == "option":
77
+ return component.option(attribute_name)
78
+
79
+ if category == "input":
80
+ return component.input(attribute_name)
81
+
82
+ if category == "output":
83
+ return component.output(attribute_name)
84
+
85
+ return None
86
+
87
+
88
+ # --------------------------------------------------------------------------------------
89
+ def form_address(attribute, category):
90
+ """
91
+ Given an attribute, we will form an address from it
92
+ """
93
+ return f"[{attribute.component().label()}].[{category}].[{attribute.name()}]"
94
+
95
+
96
+ # --------------------------------------------------------------------------------------
97
+ def is_address(address):
98
+ """
99
+ This will test whether the value being given is recognised as an address
100
+ """
101
+ if isinstance(address, str) and ADDRESS_REGEX.search(address):
102
+ return True
103
+
104
+ return False
105
+
106
+
107
+ # --------------------------------------------------------------------------------------
108
+ def _get_component_with_label(label, stack):
109
+ """
110
+ This is a private funciton that cycles the components of a stack looking
111
+ for the first component with a matching label
112
+ """
113
+ for component in stack.components():
114
+ if component.label() == label:
115
+ return component
116
+
117
+ return None
118
+
119
+
120
+ # --------------------------------------------------------------------------------------
121
+ def _get_uuid_from_label(label, stack):
122
+ """
123
+ Given a component label, this will return the uuid of that component
124
+ """
125
+ component = _get_component_with_label(label, stack)
126
+ return component.uuid() if component else None
127
+
128
+
129
+ # --------------------------------------------------------------------------------------
130
+ def _is_uuid(data):
131
+ """
132
+ Convenience function to check whether the data we are given is a uuid formed string
133
+ """
134
+ if str(data).count("-") == 4 and len(str(data)) == 36:
135
+ return True
136
+
137
+ return False
@@ -0,0 +1,36 @@
1
+ """
2
+ The xstack_app is a Qt based ui application which allows a user to create
3
+ new stack instances and populate them with components as well as executing
4
+ the stack.
5
+
6
+ xstack is considered a library rather than a tool, so the likelyhood is that
7
+ you will want to import this module into your own and then tailor the ui to
8
+ look at your own locations for components.
9
+
10
+ This can be done using the AppConfig class. You can subclass this and use it
11
+ to tell the AppWindow/AppWidget where it should look for components. The config
12
+ class also allows you to alter the terminology used in the application to be
13
+ more meaningful to your use cases.
14
+
15
+ To test this module you can simply run:
16
+
17
+ ```
18
+ import xstack_app
19
+ xstack_app.launch()
20
+ ```
21
+
22
+ Alternatively, if you want to test the app with some example components which are
23
+ used by the unit tests of xstack, you can run this:
24
+
25
+ ```
26
+ import xstack_app
27
+ xstack_app.launch_demo()
28
+ ```
29
+ """
30
+ from .application import launch
31
+ from .application import AppWindow
32
+ from .application import AppWidget
33
+
34
+ from .config import AppConfig
35
+ from . import application
36
+ from . import resources
@@ -0,0 +1,5 @@
1
+ import xstack
2
+
3
+
4
+ if __name__ == '__main__':
5
+ xstack.launch_demo()