simapy 4.6.1.dev0__py3-none-any.whl → 4.6.1.dev2__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.
- simapy/sre.py +27 -47
- {simapy-4.6.1.dev0.dist-info → simapy-4.6.1.dev2.dist-info}/METADATA +45 -49
- {simapy-4.6.1.dev0.dist-info → simapy-4.6.1.dev2.dist-info}/RECORD +6 -6
- {simapy-4.6.1.dev0.dist-info → simapy-4.6.1.dev2.dist-info}/WHEEL +1 -1
- {simapy-4.6.1.dev0.dist-info → simapy-4.6.1.dev2.dist-info}/LICENSE +0 -0
- {simapy-4.6.1.dev0.dist-info → simapy-4.6.1.dev2.dist-info}/top_level.txt +0 -0
simapy/sre.py
CHANGED
|
@@ -1,55 +1,19 @@
|
|
|
1
1
|
"""Run a command using SIMA runtime engine (sre executable)"""
|
|
2
|
-
import
|
|
2
|
+
import subprocess
|
|
3
3
|
import os
|
|
4
|
-
import re
|
|
5
4
|
from pathlib import Path
|
|
6
5
|
from typing import Sequence,Callable
|
|
7
6
|
from simapy.sima_writer import SIMAWriter
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
async def run_command(args, error_file, out_file, status_handler):
|
|
11
|
-
""""Run a command asynchronously and print output to standard out.
|
|
12
|
-
Standard err is piped to stderr.txt in the working directory"""
|
|
13
|
-
process = await asyncio.create_subprocess_exec(
|
|
14
|
-
*args, stdout=asyncio.subprocess.PIPE, stderr=error_file
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
while True:
|
|
18
|
-
# Use an awaitable to read data from stdout
|
|
19
|
-
# Read the next line of data from stdout asynchronously
|
|
20
|
-
data = await process.stdout.readline()
|
|
21
|
-
if not data:
|
|
22
|
-
break # Break the loop when there's no more data
|
|
23
|
-
sline = data.decode('utf-8')
|
|
24
|
-
if status_handler and sline.startswith("@STATUS"):
|
|
25
|
-
__parse_status(sline,status_handler)
|
|
26
|
-
else:
|
|
27
|
-
print(sline, end="\n")
|
|
28
|
-
print(sline, end="\n", file=out_file)
|
|
29
|
-
|
|
30
|
-
# Wait for the subprocess to finish
|
|
31
|
-
await process.wait()
|
|
32
|
-
if process.returncode is not None:
|
|
33
|
-
return process.returncode
|
|
34
|
-
|
|
35
|
-
def __parse_status(line: str,status_handler):
|
|
36
|
-
# A status line looks like this: @STATUS "Total" 100 1000
|
|
37
|
-
# The first number is the current value, the second is the total
|
|
38
|
-
pattern = r'@STATUS "(?P<label>\w+)" (?P<current>\d+) (?P<total>\d+)'
|
|
39
|
-
# Match the pattern in the string
|
|
40
|
-
match = re.match(pattern, line)
|
|
41
|
-
if match:
|
|
42
|
-
label = match.group('label')
|
|
43
|
-
current = int(match.group('current'))
|
|
44
|
-
total = int(match.group('total'))
|
|
45
|
-
status_handler(label,current,total)
|
|
46
|
-
|
|
47
9
|
class SIMA:
|
|
48
10
|
""""Run a command using SIMA runtime engine (sre executable)"""
|
|
49
11
|
|
|
50
12
|
def __init__(self, exe=None, fail_on_error=True):
|
|
51
13
|
self.fail_on_error = fail_on_error
|
|
52
|
-
|
|
14
|
+
# A Console handler is a function that can handle standard out from the process
|
|
15
|
+
# This can i.e. be used to parse @STATUS messages from the SIMA process wich can be used for progress indication
|
|
16
|
+
self.console_handler: Callable = None
|
|
53
17
|
if exe:
|
|
54
18
|
self.exe = exe
|
|
55
19
|
else:
|
|
@@ -59,26 +23,42 @@ class SIMA:
|
|
|
59
23
|
|
|
60
24
|
|
|
61
25
|
def run(self, working_dir, command_args: Sequence[str]):
|
|
62
|
-
"""Run the sima executable and print output to standard out.
|
|
26
|
+
"""Run the sima executable and print output to standard out.
|
|
63
27
|
Standard err is piped to stderr.txt in the working directory"""
|
|
64
28
|
|
|
65
29
|
wdir = Path(str(working_dir))
|
|
66
30
|
arguments = [self.exe]
|
|
67
|
-
arguments.extend(["-configuration", "/var/opt/sima/config"])
|
|
68
31
|
arguments.append("-consoleLog")
|
|
69
32
|
arguments.append("--progress")
|
|
70
33
|
arguments.extend(["-data", working_dir])
|
|
71
34
|
wdir.mkdir(parents=True, exist_ok=True)
|
|
72
35
|
self.__add_command_args(working_dir, arguments, command_args)
|
|
73
|
-
err_file = wdir / "stderr.txt"
|
|
74
36
|
out_file = wdir / "stdout.txt"
|
|
75
|
-
with open(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
37
|
+
with open(out_file, "w", encoding="utf8") as o_f:
|
|
38
|
+
proc = subprocess.Popen(arguments,
|
|
39
|
+
stdin=subprocess.PIPE,
|
|
40
|
+
stdout=subprocess.PIPE,
|
|
41
|
+
stderr=subprocess.STDOUT)
|
|
42
|
+
self.__read_lines(proc, o_f)
|
|
43
|
+
# Wait for the process to finish
|
|
44
|
+
exit_code = proc.wait()
|
|
79
45
|
if exit_code != 0 and self.fail_on_error:
|
|
80
46
|
raise RuntimeError(f"SIMA exited with error code {exit_code}")
|
|
81
47
|
|
|
48
|
+
def __read_lines(self,proc,out_file):
|
|
49
|
+
console_handler = self.console_handler
|
|
50
|
+
while True:
|
|
51
|
+
line = proc.stdout.readline()
|
|
52
|
+
if not line:
|
|
53
|
+
break
|
|
54
|
+
sline = line.decode(encoding="utf8").rstrip()
|
|
55
|
+
if console_handler:
|
|
56
|
+
console_handler(sline)
|
|
57
|
+
else:
|
|
58
|
+
# Print the line to standard out
|
|
59
|
+
print(sline, end="\n")
|
|
60
|
+
print(sline, end="\n", file=out_file)
|
|
61
|
+
|
|
82
62
|
def __add_command_args(self, working_dir: Path, args: Sequence, command_args: Sequence[str]):
|
|
83
63
|
"""Add command arguments to the list of arguments"""
|
|
84
64
|
if len(command_args) > 0:
|
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: simapy
|
|
3
|
-
Version: 4.6.1.
|
|
4
|
-
Summary: Python utilities for SIMA
|
|
5
|
-
Home-page: https://github.com/SINTEF/simapy
|
|
6
|
-
Author: SINTEF Ocean
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Classifier:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
48
|
-
|
|
49
|
-
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: simapy
|
|
3
|
+
Version: 4.6.1.dev2
|
|
4
|
+
Summary: Python utilities for SIMA
|
|
5
|
+
Home-page: https://github.com/SINTEF/simapy
|
|
6
|
+
Author: SINTEF Ocean
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: dmtpy (==0.3.4)
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
|
|
16
|
+
SIMAPY - Python utilities for SIMA
|
|
17
|
+
=================================================================
|
|
18
|
+
|
|
19
|
+
This Python library can be used to interact with [SIMA](https://sima.sintef.no)
|
|
20
|
+
|
|
21
|
+
Parts of the library is generated from [data models](https://github.com/SINTEF/sima-dmt-models) using a [Python code generator](https://github.com/SINTEF/dmt-gen-py)
|
|
22
|
+
|
|
23
|
+
Please examine the tests for ways to interact
|
|
24
|
+
|
|
25
|
+
Also check out the examples in [simapy-examples](https://github.com/SINTEF/simapy-examples)
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install simapy.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install simapy
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Dependencies
|
|
36
|
+
|
|
37
|
+
* [DMTPY](https://github.com/SINTEF/dmtpy)
|
|
38
|
+
|
|
39
|
+
## Authors
|
|
40
|
+
|
|
41
|
+
* **Lasse Bjermeland** - [lassebje](https://github.com/lassebje)
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
simapy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
simapy/sima_reader.py,sha256=86P_CMaz1i6o8pIzXtNBHcJj0zS6Bw8_8BVO-Wvzs5c,1364
|
|
3
3
|
simapy/sima_writer.py,sha256=MPwvooPLfGpOISxJUVlOWbtf4wVOEvgVCVsvQfLzxxY,1209
|
|
4
|
-
simapy/sre.py,sha256=
|
|
4
|
+
simapy/sre.py,sha256=Lm14wKFg1afnEhSqcry0RsD7oLGinU8P8d8jBc4pHhQ,3273
|
|
5
5
|
simapy/metocean/__init__.py,sha256=AeEF1FYpBDe46JuZ0EYJOofOuf2dwsaAdQZ0DsseB_g,39
|
|
6
6
|
simapy/metocean/metocean.py,sha256=TmfSYezAzxWLt9n_ChLKIdaIz6GxSTUu6-5wnipQz6Y,2912
|
|
7
7
|
simapy/metocean/package_info.py,sha256=6FEJ4gZkXieP2WWTA-oZO23BjQOi4YnXx3nLQY0ydYE,208
|
|
@@ -2400,8 +2400,8 @@ simapy/sima/workflow/blueprints/workflowsetitem.py,sha256=EyyxbrnPDcL-f1cgjWcH3o
|
|
|
2400
2400
|
simapy/sima/workflow/blueprints/workflowsetnode.py,sha256=UIZYi61xYtOEBzSZ5wQclUjzdAarZ8ymJ67iGARdXH4,4018
|
|
2401
2401
|
simapy/sima/workflow/blueprints/workflowtask.py,sha256=c1rpN0KRKg7zIhonXKEaAGL0c6k8-ecIcP3RK3EUD8g,1514
|
|
2402
2402
|
simapy/sima/workflow/blueprints/xytablenode.py,sha256=J-ADKlq47efkQMbay2eS0WJGtB9K0B75caOUTbj7Ogs,1667
|
|
2403
|
-
simapy-4.6.1.
|
|
2404
|
-
simapy-4.6.1.
|
|
2405
|
-
simapy-4.6.1.
|
|
2406
|
-
simapy-4.6.1.
|
|
2407
|
-
simapy-4.6.1.
|
|
2403
|
+
simapy-4.6.1.dev2.dist-info/LICENSE,sha256=F5QFv7maV1Hoof3UbIwTNKqDFoo2JykLoI_w6F4HqxI,1088
|
|
2404
|
+
simapy-4.6.1.dev2.dist-info/METADATA,sha256=PRwk_Co4_-Yc8DUENfeqgRqkSnUL-8Jlmn0ARJnjS_c,1350
|
|
2405
|
+
simapy-4.6.1.dev2.dist-info/WHEEL,sha256=00yskusixUoUt5ob_CiUp6LsnN5lqzTJpoqOFg_FVIc,92
|
|
2406
|
+
simapy-4.6.1.dev2.dist-info/top_level.txt,sha256=AVWKlvxcgSVR0H1omucqMujOVuQbcFNLjlgp3skT_1Q,7
|
|
2407
|
+
simapy-4.6.1.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|