swarmauri_evaluator_subprocess 0.3.0.dev4__tar.gz → 0.3.0.dev34__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.
@@ -0,0 +1,181 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_evaluator_subprocess
3
+ Version: 0.3.0.dev34
4
+ Summary: A subprocess-based evaluator for executing and measuring program performance in isolated subprocesses
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: subprocess,evaluation,sandboxing,program execution,resource limits,performance measurement,testing,security,swarm,ai,swarmauri,sdk,standards,evaluator
8
+ Author: Jacob Stewart
9
+ Author-email: jacob@swarmauri.com
10
+ Requires-Python: >=3.10,<3.13
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Development Status :: 3 - Alpha
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Classifier: Topic :: Software Development :: Testing
20
+ Classifier: Topic :: System :: Monitoring
21
+ Classifier: Programming Language :: Python
22
+ Classifier: Programming Language :: Python :: 3
23
+ Classifier: Programming Language :: Python :: 3 :: Only
24
+ Requires-Dist: swarmauri_base
25
+ Requires-Dist: swarmauri_core
26
+ Description-Content-Type: text/markdown
27
+
28
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
29
+
30
+ <p align="center">
31
+ <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
32
+ <img src="https://img.shields.io/pypi/dm/swarmauri_evaluator_subprocess" alt="PyPI - Downloads"/></a>
33
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_evaluator_subprocess/">
34
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_evaluator_subprocess.svg"/></a>
35
+ <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
36
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri_evaluator_subprocess" alt="PyPI - Python Version"/></a>
37
+ <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
38
+ <img src="https://img.shields.io/pypi/l/swarmauri_evaluator_subprocess" alt="PyPI - License"/></a>
39
+ <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
40
+ <img src="https://img.shields.io/pypi/v/swarmauri_evaluator_subprocess?label=swarmauri_evaluator_subprocess&color=green" alt="PyPI - swarmauri_evaluator_subprocess"/></a>
41
+ </p>
42
+
43
+ ---
44
+
45
+ # Swarmauri Evaluator Subprocess
46
+
47
+ `SubprocessEvaluator` executes programs inside sandboxed subprocesses while
48
+ enforcing CPU, memory, and file size quotas. It captures stdout/stderr, tracks
49
+ exit codes, and returns a normalized score plus structured metadata describing
50
+ each run.
51
+
52
+ ## Highlights
53
+
54
+ - Apply CPU timeouts, memory ceilings, file size limits, and process count caps
55
+ before user code starts (`resource.setrlimit`).
56
+ - Automatically choose the appropriate command: launch executables directly or
57
+ wrap Python and shell scripts with the correct interpreter.
58
+ - Compare stdout against an `expected_output` string and annotate mismatches in
59
+ the result metadata.
60
+ - Record execution context (`command`, `args`, `working_dir`) alongside
61
+ collected streams for easy debugging.
62
+ - Aggregate multiple runs with reason counts, timeout rates, and success rates
63
+ via `aggregate_scores`.
64
+
65
+ ## Installation
66
+
67
+ Pick the tool that matches your workflow:
68
+
69
+ ```bash
70
+ # pip
71
+ pip install swarmauri_evaluator_subprocess
72
+
73
+ # Poetry
74
+ poetry add swarmauri_evaluator_subprocess
75
+
76
+ # uv
77
+ uv add swarmauri_evaluator_subprocess
78
+ ```
79
+
80
+ ## Quickstart
81
+
82
+ The example below writes a temporary Python script to disk, wraps it in a small
83
+ `IProgram` implementation, and evaluates it inside a subprocess. The evaluator
84
+ returns `1.0` when the exit code is in `success_exit_codes` and, when provided,
85
+ stdout matches `expected_output`.
86
+
87
+ ```python
88
+ from pathlib import Path
89
+ import tempfile
90
+
91
+ from swarmauri_evaluator_subprocess import SubprocessEvaluator
92
+ from swarmauri_core.programs.IProgram import DiffType, IProgram
93
+
94
+
95
+ class ScriptProgram(IProgram):
96
+ """Minimal IProgram wrapper for a script stored on disk."""
97
+
98
+ def __init__(self, path: Path):
99
+ self._path = Path(path)
100
+
101
+ # Required IProgram interface methods -------------------------------
102
+ def diff(self, other: IProgram) -> DiffType: # pragma: no cover - example
103
+ return {}
104
+
105
+ def apply_diff(self, diff: DiffType) -> "ScriptProgram": # pragma: no cover
106
+ return ScriptProgram(self._path)
107
+
108
+ def validate(self) -> bool: # pragma: no cover
109
+ return self._path.exists()
110
+
111
+ def clone(self) -> "ScriptProgram": # pragma: no cover
112
+ return ScriptProgram(self._path)
113
+
114
+ # Methods consumed by SubprocessEvaluator ---------------------------
115
+ def get_path(self) -> str:
116
+ return str(self._path)
117
+
118
+ def is_executable(self) -> bool:
119
+ return False
120
+
121
+
122
+ def run_example(expected_output: str = "hello from subprocess\n"):
123
+ evaluator = SubprocessEvaluator(timeout=5)
124
+
125
+ with tempfile.TemporaryDirectory() as tmpdir:
126
+ script_path = Path(tmpdir) / "echo.py"
127
+ script_path.write_text("print('hello from subprocess')\n", encoding="utf-8")
128
+
129
+ program = ScriptProgram(script_path)
130
+
131
+ score, metadata = evaluator.evaluate(
132
+ program,
133
+ expected_output=expected_output,
134
+ )
135
+
136
+ return score, metadata
137
+
138
+
139
+ def main():
140
+ score, metadata = run_example()
141
+ print("Score:", score)
142
+ print("Stdout:", metadata["stdout"].strip())
143
+ print("Reason:", metadata["reason"])
144
+
145
+
146
+ if __name__ == "__main__":
147
+ main()
148
+ ```
149
+
150
+ ### Evaluation options
151
+
152
+ `SubprocessEvaluator.evaluate(program, **kwargs)` accepts runtime controls in
153
+ addition to the evaluator's model fields:
154
+
155
+ | Argument | Description |
156
+ | ---------------- | ----------- |
157
+ | `args` | List of command-line arguments appended to the prepared command. |
158
+ | `input_data` | String provided on stdin; useful for feeding sample input. |
159
+ | `expected_output`| Optional stdout string; mismatches lower the score to `0.7`. |
160
+ | `timeout` | Overrides the evaluator's `timeout` for a single run. |
161
+
162
+ ### Returned metadata
163
+
164
+ Each evaluation returns `(score, metadata)` where `metadata` always contains:
165
+
166
+ - `stdout`, `stderr`, and `exit_code` from the subprocess.
167
+ - `timed_out` flag plus a human-readable `reason` such as `success`,
168
+ `timeout`, or `exit_code_<value>`.
169
+ - `command`, `args`, and `working_dir` to show how the program was launched.
170
+ - `execution_time` (seconds) measured by the evaluator wrapper.
171
+
172
+ When aggregating multiple runs, `aggregate_scores` adds `reason_counts`,
173
+ `timeout_rate`, `success_rate`, and `total_executions` to the combined
174
+ metadata so callers can evaluate fleet-wide behavior.
175
+
176
+
177
+ ## Want to help?
178
+
179
+ If you want to contribute to swarmauri-sdk, read up on our
180
+ [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
181
+ that will help you get started.
@@ -0,0 +1,154 @@
1
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
2
+
3
+ <p align="center">
4
+ <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
5
+ <img src="https://img.shields.io/pypi/dm/swarmauri_evaluator_subprocess" alt="PyPI - Downloads"/></a>
6
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_evaluator_subprocess/">
7
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_evaluator_subprocess.svg"/></a>
8
+ <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
9
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri_evaluator_subprocess" alt="PyPI - Python Version"/></a>
10
+ <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
11
+ <img src="https://img.shields.io/pypi/l/swarmauri_evaluator_subprocess" alt="PyPI - License"/></a>
12
+ <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
13
+ <img src="https://img.shields.io/pypi/v/swarmauri_evaluator_subprocess?label=swarmauri_evaluator_subprocess&color=green" alt="PyPI - swarmauri_evaluator_subprocess"/></a>
14
+ </p>
15
+
16
+ ---
17
+
18
+ # Swarmauri Evaluator Subprocess
19
+
20
+ `SubprocessEvaluator` executes programs inside sandboxed subprocesses while
21
+ enforcing CPU, memory, and file size quotas. It captures stdout/stderr, tracks
22
+ exit codes, and returns a normalized score plus structured metadata describing
23
+ each run.
24
+
25
+ ## Highlights
26
+
27
+ - Apply CPU timeouts, memory ceilings, file size limits, and process count caps
28
+ before user code starts (`resource.setrlimit`).
29
+ - Automatically choose the appropriate command: launch executables directly or
30
+ wrap Python and shell scripts with the correct interpreter.
31
+ - Compare stdout against an `expected_output` string and annotate mismatches in
32
+ the result metadata.
33
+ - Record execution context (`command`, `args`, `working_dir`) alongside
34
+ collected streams for easy debugging.
35
+ - Aggregate multiple runs with reason counts, timeout rates, and success rates
36
+ via `aggregate_scores`.
37
+
38
+ ## Installation
39
+
40
+ Pick the tool that matches your workflow:
41
+
42
+ ```bash
43
+ # pip
44
+ pip install swarmauri_evaluator_subprocess
45
+
46
+ # Poetry
47
+ poetry add swarmauri_evaluator_subprocess
48
+
49
+ # uv
50
+ uv add swarmauri_evaluator_subprocess
51
+ ```
52
+
53
+ ## Quickstart
54
+
55
+ The example below writes a temporary Python script to disk, wraps it in a small
56
+ `IProgram` implementation, and evaluates it inside a subprocess. The evaluator
57
+ returns `1.0` when the exit code is in `success_exit_codes` and, when provided,
58
+ stdout matches `expected_output`.
59
+
60
+ ```python
61
+ from pathlib import Path
62
+ import tempfile
63
+
64
+ from swarmauri_evaluator_subprocess import SubprocessEvaluator
65
+ from swarmauri_core.programs.IProgram import DiffType, IProgram
66
+
67
+
68
+ class ScriptProgram(IProgram):
69
+ """Minimal IProgram wrapper for a script stored on disk."""
70
+
71
+ def __init__(self, path: Path):
72
+ self._path = Path(path)
73
+
74
+ # Required IProgram interface methods -------------------------------
75
+ def diff(self, other: IProgram) -> DiffType: # pragma: no cover - example
76
+ return {}
77
+
78
+ def apply_diff(self, diff: DiffType) -> "ScriptProgram": # pragma: no cover
79
+ return ScriptProgram(self._path)
80
+
81
+ def validate(self) -> bool: # pragma: no cover
82
+ return self._path.exists()
83
+
84
+ def clone(self) -> "ScriptProgram": # pragma: no cover
85
+ return ScriptProgram(self._path)
86
+
87
+ # Methods consumed by SubprocessEvaluator ---------------------------
88
+ def get_path(self) -> str:
89
+ return str(self._path)
90
+
91
+ def is_executable(self) -> bool:
92
+ return False
93
+
94
+
95
+ def run_example(expected_output: str = "hello from subprocess\n"):
96
+ evaluator = SubprocessEvaluator(timeout=5)
97
+
98
+ with tempfile.TemporaryDirectory() as tmpdir:
99
+ script_path = Path(tmpdir) / "echo.py"
100
+ script_path.write_text("print('hello from subprocess')\n", encoding="utf-8")
101
+
102
+ program = ScriptProgram(script_path)
103
+
104
+ score, metadata = evaluator.evaluate(
105
+ program,
106
+ expected_output=expected_output,
107
+ )
108
+
109
+ return score, metadata
110
+
111
+
112
+ def main():
113
+ score, metadata = run_example()
114
+ print("Score:", score)
115
+ print("Stdout:", metadata["stdout"].strip())
116
+ print("Reason:", metadata["reason"])
117
+
118
+
119
+ if __name__ == "__main__":
120
+ main()
121
+ ```
122
+
123
+ ### Evaluation options
124
+
125
+ `SubprocessEvaluator.evaluate(program, **kwargs)` accepts runtime controls in
126
+ addition to the evaluator's model fields:
127
+
128
+ | Argument | Description |
129
+ | ---------------- | ----------- |
130
+ | `args` | List of command-line arguments appended to the prepared command. |
131
+ | `input_data` | String provided on stdin; useful for feeding sample input. |
132
+ | `expected_output`| Optional stdout string; mismatches lower the score to `0.7`. |
133
+ | `timeout` | Overrides the evaluator's `timeout` for a single run. |
134
+
135
+ ### Returned metadata
136
+
137
+ Each evaluation returns `(score, metadata)` where `metadata` always contains:
138
+
139
+ - `stdout`, `stderr`, and `exit_code` from the subprocess.
140
+ - `timed_out` flag plus a human-readable `reason` such as `success`,
141
+ `timeout`, or `exit_code_<value>`.
142
+ - `command`, `args`, and `working_dir` to show how the program was launched.
143
+ - `execution_time` (seconds) measured by the evaluator wrapper.
144
+
145
+ When aggregating multiple runs, `aggregate_scores` adds `reason_counts`,
146
+ `timeout_rate`, `success_rate`, and `total_executions` to the combined
147
+ metadata so callers can evaluate fleet-wide behavior.
148
+
149
+
150
+ ## Want to help?
151
+
152
+ If you want to contribute to swarmauri-sdk, read up on our
153
+ [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
154
+ that will help you get started.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "swarmauri_evaluator_subprocess"
3
- version = "0.3.0.dev4"
3
+ version = "0.3.0.dev34"
4
4
  description = "A subprocess-based evaluator for executing and measuring program performance in isolated subprocesses"
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
@@ -17,8 +17,11 @@ classifiers = [
17
17
  "Topic :: Software Development :: Libraries",
18
18
  "Topic :: Software Development :: Testing",
19
19
  "Topic :: System :: Monitoring",
20
+ "Programming Language :: Python",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3 :: Only",
20
23
  ]
21
- authors = [{ name = "SwarmAuri Team", email = "info@swarmauri.com" }]
24
+ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
22
25
  keywords = [
23
26
  "subprocess",
24
27
  "evaluation",
@@ -31,6 +34,9 @@ keywords = [
31
34
  "swarm",
32
35
  "ai",
33
36
  "swarmauri",
37
+ "sdk",
38
+ "standards",
39
+ "evaluator",
34
40
  ]
35
41
  dependencies = ["swarmauri_core", "swarmauri_base"]
36
42
 
@@ -47,6 +53,7 @@ markers = [
47
53
  "xfail: Expected failures",
48
54
  "acceptance: Acceptance tests",
49
55
  "perf: Performance tests that measure execution time and resource usage",
56
+ "example: README-backed examples",
50
57
  ]
51
58
  timeout = 300
52
59
  log_cli = true
@@ -1,48 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: swarmauri_evaluator_subprocess
3
- Version: 0.3.0.dev4
4
- Summary: A subprocess-based evaluator for executing and measuring program performance in isolated subprocesses
5
- License: Apache-2.0
6
- Keywords: subprocess,evaluation,sandboxing,program execution,resource limits,performance measurement,testing,security,swarm,ai,swarmauri
7
- Author: SwarmAuri Team
8
- Author-email: info@swarmauri.com
9
- Requires-Python: >=3.10,<3.13
10
- Classifier: License :: OSI Approved :: Apache Software License
11
- Classifier: Natural Language :: English
12
- Classifier: Programming Language :: Python :: 3.10
13
- Classifier: Programming Language :: Python :: 3.11
14
- Classifier: Programming Language :: Python :: 3.12
15
- Classifier: Development Status :: 3 - Alpha
16
- Classifier: Intended Audience :: Developers
17
- Classifier: Topic :: Software Development :: Libraries
18
- Classifier: Topic :: Software Development :: Testing
19
- Classifier: Topic :: System :: Monitoring
20
- Requires-Dist: swarmauri_base
21
- Requires-Dist: swarmauri_core
22
- Description-Content-Type: text/markdown
23
-
24
- ![Swamauri Logo](https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png)
25
-
26
- <p align="center">
27
- <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
28
- <img src="https://img.shields.io/pypi/dm/swarmauri_evaluator_subprocess" alt="PyPI - Downloads"/></a>
29
- <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
30
- <img src="https://img.shields.io/pypi/pyversions/swarmauri_evaluator_subprocess" alt="PyPI - Python Version"/></a>
31
- <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
32
- <img src="https://img.shields.io/pypi/l/swarmauri_evaluator_subprocess" alt="PyPI - License"/></a>
33
- <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
34
- <img src="https://img.shields.io/pypi/v/swarmauri_evaluator_subprocess?label=swarmauri_evaluator_subprocess&color=green" alt="PyPI - swarmauri_evaluator_subprocess"/></a>
35
- </p>
36
-
37
- ---
38
-
39
- # Swarmauri Evaluator Subprocess
40
-
41
- A subprocess-based evaluator for executing and measuring program performance in isolated subprocesses.
42
-
43
- ## Installation
44
-
45
- ```bash
46
- pip install swarmauri_evaluator_subprocess
47
- ```
48
-
@@ -1,24 +0,0 @@
1
- ![Swamauri Logo](https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png)
2
-
3
- <p align="center">
4
- <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
5
- <img src="https://img.shields.io/pypi/dm/swarmauri_evaluator_subprocess" alt="PyPI - Downloads"/></a>
6
- <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
7
- <img src="https://img.shields.io/pypi/pyversions/swarmauri_evaluator_subprocess" alt="PyPI - Python Version"/></a>
8
- <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
9
- <img src="https://img.shields.io/pypi/l/swarmauri_evaluator_subprocess" alt="PyPI - License"/></a>
10
- <a href="https://pypi.org/project/swarmauri_evaluator_subprocess/">
11
- <img src="https://img.shields.io/pypi/v/swarmauri_evaluator_subprocess?label=swarmauri_evaluator_subprocess&color=green" alt="PyPI - swarmauri_evaluator_subprocess"/></a>
12
- </p>
13
-
14
- ---
15
-
16
- # Swarmauri Evaluator Subprocess
17
-
18
- A subprocess-based evaluator for executing and measuring program performance in isolated subprocesses.
19
-
20
- ## Installation
21
-
22
- ```bash
23
- pip install swarmauri_evaluator_subprocess
24
- ```