ocean-runner 0.1.0__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.
- ocean_runner-0.1.0/.gitignore +6 -0
- ocean_runner-0.1.0/LICENSE +7 -0
- ocean_runner-0.1.0/PKG-INFO +179 -0
- ocean_runner-0.1.0/README.md +156 -0
- ocean_runner-0.1.0/pyproject.toml +34 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 spin3l
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ocean-runner
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python PyPI package template
|
|
5
|
+
Project-URL: Homepage, https://github.com/AgrospAI/ocean-runner
|
|
6
|
+
Project-URL: Issues, https://github.com/AgrospAI/ocean-runner/issues
|
|
7
|
+
Author-email: John Doe <john.doe@foo.bar>
|
|
8
|
+
License: Copyright 2025 spin3l
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: oceanprotocol-job-details==0.2.4
|
|
21
|
+
Requires-Dist: pytest>=8.4.2
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# ocean-runner
|
|
25
|
+
|
|
26
|
+
Ocean Runner is a package that brings a fluent API for APP creation and running in the scope of OceanProtocol.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Minimal Example
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import random
|
|
35
|
+
from ocean_runner import Algorithm, Config
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
Algorithm().run(lambda _: random.randint()).save_results()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
To use minimally the API, you can just provide a callback to the run method, defaulting for the rest of behaviours. This code snippet will:
|
|
42
|
+
|
|
43
|
+
- Read the OceanProtocol JobDetails from the environment variables and use default file paths.
|
|
44
|
+
- Generate a random integer.
|
|
45
|
+
- Store the result in a "result.txt" file within the default outputs path.
|
|
46
|
+
|
|
47
|
+
### Tuning
|
|
48
|
+
|
|
49
|
+
#### Application Config
|
|
50
|
+
|
|
51
|
+
The application configuration can be tweaked by passing a Config instance to its' constructor.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
Algorithm(
|
|
55
|
+
Config(
|
|
56
|
+
custom_input: ... # dataclass
|
|
57
|
+
# Custom algorithm parameters dataclass.
|
|
58
|
+
|
|
59
|
+
error_callback: ... # Callable[[Exception], None]
|
|
60
|
+
# Callback to run on exceptions.
|
|
61
|
+
|
|
62
|
+
logger: ... # type: logging.Logger
|
|
63
|
+
# Custom logger to use.
|
|
64
|
+
|
|
65
|
+
environment: ...
|
|
66
|
+
# type: ocean_runner.Environment. Mock of environment variables.
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import logging
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@dataclass
|
|
76
|
+
class CustomInput:
|
|
77
|
+
foobar: string
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
logger = logging.getLogger(__name__)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
Algorithm(
|
|
84
|
+
Config(
|
|
85
|
+
custom_input: CustomInput,
|
|
86
|
+
"""
|
|
87
|
+
Load the Algorithm's Custom Input into a CustomInput dataclass instance.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
error_callback: lambda ex: logger.exception(ex),
|
|
91
|
+
"""
|
|
92
|
+
Run this callback when an exception is caught
|
|
93
|
+
NOTE: it's not recommended to catch exceptions this way. Should re-raise and halt the execution.
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
logger: logger,
|
|
97
|
+
"""
|
|
98
|
+
Custom logger to use in the Algorithm.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
environment: Environment(
|
|
102
|
+
base_dir: "./_data",
|
|
103
|
+
"""
|
|
104
|
+
Custom data path to use test data.
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
dids: '["17feb697190d9f5912e064307006c06019c766d35e4e3f239ebb69fb71096e42"]',
|
|
108
|
+
"""
|
|
109
|
+
Dataset DID.
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
transformation_did: "1234",
|
|
113
|
+
"""
|
|
114
|
+
Random transformation DID to use while testing.
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
secret: "1234",
|
|
118
|
+
"""
|
|
119
|
+
Random secret to use while testing.
|
|
120
|
+
"""
|
|
121
|
+
)
|
|
122
|
+
"""
|
|
123
|
+
Should not be needed in production algorithms, used to mock environment variables, defaults to using env.
|
|
124
|
+
"""
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Default behaviours
|
|
131
|
+
|
|
132
|
+
### Default implementations
|
|
133
|
+
|
|
134
|
+
As seen in the minimal example, all methods implemented in `Algorithm` have a default implementation which will be commented here.
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
|
|
138
|
+
(
|
|
139
|
+
Algorithm()
|
|
140
|
+
|
|
141
|
+
"""
|
|
142
|
+
Default constructor, will use default values of Config.
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
.validate()
|
|
146
|
+
|
|
147
|
+
"""
|
|
148
|
+
Will validate the algorithm's job detail instance, checking for the existence of:
|
|
149
|
+
- `job_details.ddos`
|
|
150
|
+
- `job_details.files`
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
.run()
|
|
154
|
+
|
|
155
|
+
"""
|
|
156
|
+
Has NO default implementation, must pass a callback that returns a result of any type.
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
.save_results()
|
|
160
|
+
|
|
161
|
+
"""
|
|
162
|
+
Stores the result of running the algorithm in "outputs/results.txt"
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Job Details
|
|
171
|
+
|
|
172
|
+
To load the OceanProtocol JobDetails instance, the program will read some environment variables, they can be mocked passing an instance of `Environment` through the configuration of the algorithm.
|
|
173
|
+
|
|
174
|
+
Environment variables:
|
|
175
|
+
- *DIDS*: Input dataset(s) DID's.
|
|
176
|
+
- *TRANSFORMATION_DID*: Algorithm DID.
|
|
177
|
+
- *SECRET*: Algorithm secret.
|
|
178
|
+
- *BASE_DIR* (optional, default='/data'): Base path to the OceanProtocol data directories.
|
|
179
|
+
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# ocean-runner
|
|
2
|
+
|
|
3
|
+
Ocean Runner is a package that brings a fluent API for APP creation and running in the scope of OceanProtocol.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
### Minimal Example
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
import random
|
|
12
|
+
from ocean_runner import Algorithm, Config
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
Algorithm().run(lambda _: random.randint()).save_results()
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
To use minimally the API, you can just provide a callback to the run method, defaulting for the rest of behaviours. This code snippet will:
|
|
19
|
+
|
|
20
|
+
- Read the OceanProtocol JobDetails from the environment variables and use default file paths.
|
|
21
|
+
- Generate a random integer.
|
|
22
|
+
- Store the result in a "result.txt" file within the default outputs path.
|
|
23
|
+
|
|
24
|
+
### Tuning
|
|
25
|
+
|
|
26
|
+
#### Application Config
|
|
27
|
+
|
|
28
|
+
The application configuration can be tweaked by passing a Config instance to its' constructor.
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
Algorithm(
|
|
32
|
+
Config(
|
|
33
|
+
custom_input: ... # dataclass
|
|
34
|
+
# Custom algorithm parameters dataclass.
|
|
35
|
+
|
|
36
|
+
error_callback: ... # Callable[[Exception], None]
|
|
37
|
+
# Callback to run on exceptions.
|
|
38
|
+
|
|
39
|
+
logger: ... # type: logging.Logger
|
|
40
|
+
# Custom logger to use.
|
|
41
|
+
|
|
42
|
+
environment: ...
|
|
43
|
+
# type: ocean_runner.Environment. Mock of environment variables.
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import logging
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class CustomInput:
|
|
54
|
+
foobar: string
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
logger = logging.getLogger(__name__)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Algorithm(
|
|
61
|
+
Config(
|
|
62
|
+
custom_input: CustomInput,
|
|
63
|
+
"""
|
|
64
|
+
Load the Algorithm's Custom Input into a CustomInput dataclass instance.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
error_callback: lambda ex: logger.exception(ex),
|
|
68
|
+
"""
|
|
69
|
+
Run this callback when an exception is caught
|
|
70
|
+
NOTE: it's not recommended to catch exceptions this way. Should re-raise and halt the execution.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
logger: logger,
|
|
74
|
+
"""
|
|
75
|
+
Custom logger to use in the Algorithm.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
environment: Environment(
|
|
79
|
+
base_dir: "./_data",
|
|
80
|
+
"""
|
|
81
|
+
Custom data path to use test data.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
dids: '["17feb697190d9f5912e064307006c06019c766d35e4e3f239ebb69fb71096e42"]',
|
|
85
|
+
"""
|
|
86
|
+
Dataset DID.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
transformation_did: "1234",
|
|
90
|
+
"""
|
|
91
|
+
Random transformation DID to use while testing.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
secret: "1234",
|
|
95
|
+
"""
|
|
96
|
+
Random secret to use while testing.
|
|
97
|
+
"""
|
|
98
|
+
)
|
|
99
|
+
"""
|
|
100
|
+
Should not be needed in production algorithms, used to mock environment variables, defaults to using env.
|
|
101
|
+
"""
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Default behaviours
|
|
108
|
+
|
|
109
|
+
### Default implementations
|
|
110
|
+
|
|
111
|
+
As seen in the minimal example, all methods implemented in `Algorithm` have a default implementation which will be commented here.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
|
|
115
|
+
(
|
|
116
|
+
Algorithm()
|
|
117
|
+
|
|
118
|
+
"""
|
|
119
|
+
Default constructor, will use default values of Config.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
.validate()
|
|
123
|
+
|
|
124
|
+
"""
|
|
125
|
+
Will validate the algorithm's job detail instance, checking for the existence of:
|
|
126
|
+
- `job_details.ddos`
|
|
127
|
+
- `job_details.files`
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
.run()
|
|
131
|
+
|
|
132
|
+
"""
|
|
133
|
+
Has NO default implementation, must pass a callback that returns a result of any type.
|
|
134
|
+
"""
|
|
135
|
+
|
|
136
|
+
.save_results()
|
|
137
|
+
|
|
138
|
+
"""
|
|
139
|
+
Stores the result of running the algorithm in "outputs/results.txt"
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Job Details
|
|
148
|
+
|
|
149
|
+
To load the OceanProtocol JobDetails instance, the program will read some environment variables, they can be mocked passing an instance of `Environment` through the configuration of the algorithm.
|
|
150
|
+
|
|
151
|
+
Environment variables:
|
|
152
|
+
- *DIDS*: Input dataset(s) DID's.
|
|
153
|
+
- *TRANSFORMATION_DID*: Algorithm DID.
|
|
154
|
+
- *SECRET*: Algorithm secret.
|
|
155
|
+
- *BASE_DIR* (optional, default='/data'): Base path to the OceanProtocol data directories.
|
|
156
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "ocean-runner"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A Python PyPI package template"
|
|
5
|
+
authors = [{ name = "John Doe", email = "john.doe@foo.bar" }]
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
license = { file = "LICENSE" }
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Programming Language :: Python :: 3",
|
|
11
|
+
"Operating System :: OS Independent",
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"oceanprotocol-job-details==0.2.4",
|
|
16
|
+
"pytest>=8.4.2",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/AgrospAI/ocean-runner"
|
|
21
|
+
Issues = "https://github.com/AgrospAI/ocean-runner/issues"
|
|
22
|
+
|
|
23
|
+
[tool.pytest.ini_options]
|
|
24
|
+
pythonpath = "ocean-runner"
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["hatchling"]
|
|
28
|
+
build-backend = "hatchling.build"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.sdist]
|
|
31
|
+
include = ["ocean-runner"]
|
|
32
|
+
|
|
33
|
+
[tool.hatch.build.targets.wheel]
|
|
34
|
+
include = ["ocean-runner"]
|