wexample-runner 10.0.2__tar.gz → 10.0.4__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.
Files changed (18) hide show
  1. wexample_runner-10.0.4/PKG-INFO +111 -0
  2. wexample_runner-10.0.4/README.md +93 -0
  3. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/pyproject.toml +2 -2
  4. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/runner/abstract_docker_runner.py +0 -0
  5. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/runner/docker_attached_runner.py +0 -0
  6. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/tests/.gitkeep +0 -0
  7. wexample_runner-10.0.2/PKG-INFO +0 -294
  8. wexample_runner-10.0.2/README.md +0 -276
  9. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/__init__.py +0 -0
  10. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/py.typed +0 -0
  11. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/runner/__init__.py +0 -0
  12. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/runner/abstract_runner.py +0 -0
  13. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/runner/docker_runner.py +0 -0
  14. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/runner/local_runner.py +0 -0
  15. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/runner/ssh_runner.py +0 -0
  16. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/runner_config.py +0 -0
  17. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/runner_registry.py +0 -0
  18. {wexample_runner-10.0.2 → wexample_runner-10.0.4}/src/wexample_runner/runner_result.py +0 -0
@@ -0,0 +1,111 @@
1
+ Metadata-Version: 2.1
2
+ Name: wexample-runner
3
+ Version: 10.0.4
4
+ Summary: Executes commands across local, SSH, and Docker environments through a unified runner interface with lifecycle management (build, start, stop, destroy)
5
+ Author-Email: weeger <contact@wexample.com>
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Project-URL: homepage, https://github.com/wexample/python-runner
11
+ Requires-Python: >=3.10
12
+ Requires-Dist: paramiko>=3.0.0
13
+ Requires-Dist: wexample-helpers>=20.6.0
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest; extra == "dev"
16
+ Requires-Dist: pytest-cov; extra == "dev"
17
+ Description-Content-Type: text/markdown
18
+
19
+ # runner
20
+
21
+ Version: 10.0.4
22
+
23
+ Executes commands across local, SSH, and Docker environments through a unified runner interface with lifecycle management (build, start, stop, destroy)
24
+
25
+ ## Table of Contents
26
+
27
+ - [Install](#install)
28
+ - [Tests](#tests)
29
+ - [Roadmap](#roadmap)
30
+ - [Status Compatibility](#status-compatibility)
31
+ - [Useful Links](#useful-links)
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install wexample-runner
37
+ ```
38
+
39
+ Requires Python >=3.10.
40
+
41
+ ## Tests
42
+
43
+ This project uses `pytest` for testing and `pytest-cov` for code coverage analysis.
44
+
45
+ ### Installation
46
+
47
+ First, install the required testing dependencies:
48
+ ```bash
49
+ .venv/bin/python -m pip install pytest pytest-cov
50
+ ```
51
+
52
+ ### Basic Usage
53
+
54
+ Run all tests with coverage:
55
+ ```bash
56
+ .venv/bin/python -m pytest --cov --cov-report=html
57
+ ```
58
+
59
+ ### Common Commands
60
+ ```bash
61
+ # Run tests with coverage for a specific module
62
+ .venv/bin/python -m pytest --cov=your_module
63
+
64
+ # Show which lines are not covered
65
+ .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing
66
+
67
+ # Generate an HTML coverage report
68
+ .venv/bin/python -m pytest --cov=your_module --cov-report=html
69
+
70
+ # Combine terminal and HTML reports
71
+ .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing --cov-report=html
72
+
73
+ # Run specific test file with coverage
74
+ .venv/bin/python -m pytest tests/test_file.py --cov=your_module --cov-report=term-missing
75
+ ```
76
+
77
+ ### Viewing HTML Reports
78
+
79
+ After generating an HTML report, open `htmlcov/index.html` in your browser to view detailed line-by-line coverage information.
80
+
81
+ ### Coverage Threshold
82
+
83
+ To enforce a minimum coverage percentage:
84
+ ```bash
85
+ .venv/bin/python -m pytest --cov=your_module --cov-fail-under=80
86
+ ```
87
+
88
+ This will cause the test suite to fail if coverage drops below 80%.
89
+
90
+ ## Known Limitations & Roadmap
91
+
92
+ Current limitations and planned features are tracked in the GitHub issues.
93
+
94
+ See the [project roadmap](https://github.com/wexample/python-runner/issues) for upcoming features and improvements.
95
+
96
+ ## Status & Compatibility
97
+
98
+ **Maturity**: Production-ready
99
+
100
+ **Python Support**: >=3.10
101
+
102
+ **OS Support**: Linux, macOS, Windows
103
+
104
+ **Status**: Actively maintained
105
+
106
+ ## Useful Links
107
+
108
+ - **Homepage**: https://github.com/wexample/python-runner
109
+ - **Issue Tracker**: https://github.com/wexample/python-runner/issues
110
+ - **Discussions**: https://github.com/wexample/python-runner/discussions
111
+ - **PyPI**: [pypi.org/project/wexample-runner](https://pypi.org/project/wexample-runner/)
@@ -0,0 +1,93 @@
1
+ # runner
2
+
3
+ Version: 10.0.4
4
+
5
+ Executes commands across local, SSH, and Docker environments through a unified runner interface with lifecycle management (build, start, stop, destroy)
6
+
7
+ ## Table of Contents
8
+
9
+ - [Install](#install)
10
+ - [Tests](#tests)
11
+ - [Roadmap](#roadmap)
12
+ - [Status Compatibility](#status-compatibility)
13
+ - [Useful Links](#useful-links)
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install wexample-runner
19
+ ```
20
+
21
+ Requires Python >=3.10.
22
+
23
+ ## Tests
24
+
25
+ This project uses `pytest` for testing and `pytest-cov` for code coverage analysis.
26
+
27
+ ### Installation
28
+
29
+ First, install the required testing dependencies:
30
+ ```bash
31
+ .venv/bin/python -m pip install pytest pytest-cov
32
+ ```
33
+
34
+ ### Basic Usage
35
+
36
+ Run all tests with coverage:
37
+ ```bash
38
+ .venv/bin/python -m pytest --cov --cov-report=html
39
+ ```
40
+
41
+ ### Common Commands
42
+ ```bash
43
+ # Run tests with coverage for a specific module
44
+ .venv/bin/python -m pytest --cov=your_module
45
+
46
+ # Show which lines are not covered
47
+ .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing
48
+
49
+ # Generate an HTML coverage report
50
+ .venv/bin/python -m pytest --cov=your_module --cov-report=html
51
+
52
+ # Combine terminal and HTML reports
53
+ .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing --cov-report=html
54
+
55
+ # Run specific test file with coverage
56
+ .venv/bin/python -m pytest tests/test_file.py --cov=your_module --cov-report=term-missing
57
+ ```
58
+
59
+ ### Viewing HTML Reports
60
+
61
+ After generating an HTML report, open `htmlcov/index.html` in your browser to view detailed line-by-line coverage information.
62
+
63
+ ### Coverage Threshold
64
+
65
+ To enforce a minimum coverage percentage:
66
+ ```bash
67
+ .venv/bin/python -m pytest --cov=your_module --cov-fail-under=80
68
+ ```
69
+
70
+ This will cause the test suite to fail if coverage drops below 80%.
71
+
72
+ ## Known Limitations & Roadmap
73
+
74
+ Current limitations and planned features are tracked in the GitHub issues.
75
+
76
+ See the [project roadmap](https://github.com/wexample/python-runner/issues) for upcoming features and improvements.
77
+
78
+ ## Status & Compatibility
79
+
80
+ **Maturity**: Production-ready
81
+
82
+ **Python Support**: >=3.10
83
+
84
+ **OS Support**: Linux, macOS, Windows
85
+
86
+ **Status**: Actively maintained
87
+
88
+ ## Useful Links
89
+
90
+ - **Homepage**: https://github.com/wexample/python-runner
91
+ - **Issue Tracker**: https://github.com/wexample/python-runner/issues
92
+ - **Discussions**: https://github.com/wexample/python-runner/discussions
93
+ - **PyPI**: [pypi.org/project/wexample-runner](https://pypi.org/project/wexample-runner/)
@@ -6,7 +6,7 @@ build-backend = "pdm.backend"
6
6
 
7
7
  [project]
8
8
  name = "wexample-runner"
9
- version = "10.0.2"
9
+ version = "10.0.4"
10
10
  description = "Executes commands across local, SSH, and Docker environments through a unified runner interface with lifecycle management (build, start, stop, destroy)"
11
11
  authors = [
12
12
  { name = "weeger", email = "contact@wexample.com" },
@@ -19,7 +19,7 @@ classifiers = [
19
19
  ]
20
20
  dependencies = [
21
21
  "paramiko>=3.0.0",
22
- "wexample-helpers>=20.5.0",
22
+ "wexample-helpers>=20.6.0",
23
23
  ]
24
24
 
25
25
  [project.readme]
@@ -1,294 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: wexample-runner
3
- Version: 10.0.2
4
- Summary: Executes commands across local, SSH, and Docker environments through a unified runner interface with lifecycle management (build, start, stop, destroy)
5
- Author-Email: weeger <contact@wexample.com>
6
- License: MIT
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
9
- Classifier: Operating System :: OS Independent
10
- Project-URL: homepage, https://github.com/wexample/python-runner
11
- Requires-Python: >=3.10
12
- Requires-Dist: paramiko>=3.0.0
13
- Requires-Dist: wexample-helpers>=20.5.0
14
- Provides-Extra: dev
15
- Requires-Dist: pytest; extra == "dev"
16
- Requires-Dist: pytest-cov; extra == "dev"
17
- Description-Content-Type: text/markdown
18
-
19
- # runner
20
-
21
- Version: 10.0.2
22
-
23
- `wexample-runner` gives Python ≥ 3.10 code a single `execute(cmd)` call that runs shell commands on the local machine via subprocess, on a remote server over SSH (paramiko), or inside a Docker container — without the caller branching on the target environment. Every runner follows the same `build / start / stop / destroy` lifecycle and returns a `RunnerResult` dataclass carrying `stdout`, `stderr`, and `exit_code`. It targets developers who automate operations across mixed execution environments and want one interface that works regardless of where the command lands.
24
-
25
- ## Table of Contents
26
-
27
- - [Installation](#installation)
28
- - [Quickstart](#quickstart)
29
- - [Tests](#tests)
30
- - [Architecture](#architecture)
31
- - [Integration in the Suite](#integration-in-the-suite)
32
- - [Dependencies](#dependencies)
33
- - [Versioning & Compatibility Policy](#versioning--compatibility-policy)
34
- - [License](#license)
35
- - [About us](#about-us)
36
- - [Known Limitations & Roadmap](#known-limitations--roadmap)
37
- - [Status & Compatibility](#status--compatibility)
38
- - [Useful Links](#useful-links)
39
- - [Migration Notes](#migration-notes)
40
-
41
- ## Installation
42
-
43
- ```bash
44
- pip install wexample-runner
45
- ```
46
-
47
- Requires Python >=3.10.
48
-
49
- ## Quickstart
50
-
51
- Install the package:
52
-
53
- ```bash
54
- pip install wexample-runner
55
- ```
56
-
57
- `LocalRunner` runs commands on the local machine with no setup:
58
-
59
- ```python
60
- from wexample_runner.runner.local_runner import LocalRunner
61
-
62
- runner = LocalRunner()
63
- result = runner.execute(["echo", "hello"])
64
-
65
- print(result.stdout) # hello\n
66
- print(result.exit_code) # 0
67
- print(result.is_success()) # True
68
- ```
69
-
70
- `execute` accepts a list of arguments or a plain shell string and always returns a `RunnerResult` dataclass carrying `stdout`, `stderr`, and `exit_code`.
71
-
72
- To raise instead of checking the exit code manually:
73
-
74
- ```python
75
- result.raise_on_error()
76
- ```
77
-
78
- ## Tests
79
-
80
- This project uses `pytest` for testing and `pytest-cov` for code coverage analysis.
81
-
82
- ### Installation
83
-
84
- First, install the required testing dependencies:
85
- ```bash
86
- .venv/bin/python -m pip install pytest pytest-cov
87
- ```
88
-
89
- ### Basic Usage
90
-
91
- Run all tests with coverage:
92
- ```bash
93
- .venv/bin/python -m pytest --cov --cov-report=html
94
- ```
95
-
96
- ### Common Commands
97
- ```bash
98
- # Run tests with coverage for a specific module
99
- .venv/bin/python -m pytest --cov=your_module
100
-
101
- # Show which lines are not covered
102
- .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing
103
-
104
- # Generate an HTML coverage report
105
- .venv/bin/python -m pytest --cov=your_module --cov-report=html
106
-
107
- # Combine terminal and HTML reports
108
- .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing --cov-report=html
109
-
110
- # Run specific test file with coverage
111
- .venv/bin/python -m pytest tests/test_file.py --cov=your_module --cov-report=term-missing
112
- ```
113
-
114
- ### Viewing HTML Reports
115
-
116
- After generating an HTML report, open `htmlcov/index.html` in your browser to view detailed line-by-line coverage information.
117
-
118
- ### Coverage Threshold
119
-
120
- To enforce a minimum coverage percentage:
121
- ```bash
122
- .venv/bin/python -m pytest --cov=your_module --cov-fail-under=80
123
- ```
124
-
125
- This will cause the test suite to fail if coverage drops below 80%.
126
-
127
- ## Architecture
128
-
129
- The package is organised around one abstract base, one result dataclass, one optional config dataclass, one registry, and five concrete runner classes. Every public entry point funnels through `AbstractRunner.execute()` and every response comes back as a `RunnerResult`.
130
-
131
- ### Abstract base
132
-
133
- src/wexample_runner/runner/abstract_runner.py defines the contract every runner implements.
134
-
135
- **Lifecycle** — four methods cover the full arc of an environment:
136
-
137
- | Method | Responsibility |
138
- |---|---|
139
- | `build()` | Prepare the environment (build image, verify connectivity). No-op by default. |
140
- | `start()` | Make the environment ready to receive commands. No-op by default. |
141
- | `stop()` | Pause without removing anything. |
142
- | `destroy()` | Remove completely. |
143
-
144
- `ensure_running()` composes `build()` then `start()`. The class also implements the context manager protocol: `__enter__` calls `ensure_running()`, `__exit__` calls `stop()` and, when `ephemeral=True`, `destroy()`.
145
-
146
- **Execution** — the one abstract method every subclass must provide:
147
-
148
- ```python
149
- def execute(
150
- self,
151
- cmd: list[str] | str,
152
- workdir: str | None = None,
153
- env: dict[str, str] | None = None,
154
- ) -> RunnerResult:
155
- ```
156
-
157
- ### Result
158
-
159
- src/wexample_runner/runner_result.py is a plain dataclass. Every `execute()` call returns one:
160
-
161
- ```python
162
- @dataclass
163
- class RunnerResult:
164
- exit_code: int
165
- stderr: str
166
- stdout: str
167
- ```
168
-
169
- Two helpers cover the common patterns: `is_success()` returns `exit_code == 0`; `raise_on_error()` raises `RuntimeError` on non-zero exit, embedding `stderr` or `stdout` in the message.
170
-
171
- ### Configuration
172
-
173
- src/wexample_runner/runner_config.py is an optional declarative layer for Docker-based runners. It groups the fields a runner needs at construction time — `dockerfile`, `image_name`, `mount_path`, `container_workdir`, `volumes`, and `ephemeral` — into one object a caller can pass around rather than threading individual keyword arguments.
174
-
175
- ### Registry
176
-
177
- src/wexample_runner/runner_registry.py holds named `AbstractRunner` instances. It extends `SharedRegistry` from `wexample_helpers`, which provides a class-level singleton via `.shared()` alongside ordinary instantiation for isolated registries.
178
-
179
- Callers register a pre-configured runner under an explicit string key and retrieve it by the same key:
180
-
181
- ```python
182
- RunnerRegistry.shared().register(runner, key="prod")
183
- runner = RunnerRegistry.shared().get_or_raise("prod")
184
- ```
185
-
186
- `status()` introspects every registered runner and returns a list of dicts with `name`, `type`, `is_built`, `is_running`, and `ephemeral`.
187
-
188
- ### Concrete runners
189
-
190
- ### LocalRunner
191
-
192
- src/wexample_runner/runner/local_runner.py runs commands on the local machine through `wexample_helpers.helper.shell.shell_run`. Both `is_built` and `is_running` always return `True`; the runner has no lifecycle to manage. `execute()` captures stdout and stderr with `capture=True` and returns them in a `RunnerResult`.
193
-
194
- ### SshRunner
195
-
196
- src/wexample_runner/runner/ssh_runner.py wraps a `paramiko.SSHClient`. The connection is opened in `start()` and closed in `stop()`. `execute()` assembles a shell string: if `cmd` is a list it joins it with `shlex.join`, prepends `cd {workdir} &&` when a workdir is given, and prefixes environment variables as `KEY=value` pairs before calling `exec_command`. `is_running` inspects the paramiko transport's active state.
197
-
198
- ### AbstractDockerRunner
199
-
200
- src/wexample_runner/runner/abstract_docker_runner.py provides the shared `docker exec` logic used by both Docker subclasses. `execute()` builds a `docker exec` invocation:
201
-
202
- ```
203
- docker exec [--user U] [-w workdir] [-e K=V ...] <container_name> <cmd>
204
- ```
205
-
206
- It also provides `rebase_path(host_path)`, which translates an absolute host path to its equivalent inside the container by matching it against the deepest registered volume mount. The `_find_mount_for` helper picks the longest matching mount so nested mounts take priority.
207
-
208
- ### DockerRunner
209
-
210
- src/wexample_runner/runner/docker_runner.py owns its container end-to-end. `build()` calls `docker_build_image` when the image does not exist yet. `start()` creates the container with `docker_run_container` (pinning it to the current host uid:gid) or restarts an existing stopped one with `docker_start_container`. `destroy()` stops the container, removes it, then removes the image. `is_built` checks whether the image exists via `docker_image_exists`.
211
-
212
- ### DockerAttachedRunner
213
-
214
- src/wexample_runner/runner/docker_attached_runner.py attaches to a container it does not own. `start()` raises `RuntimeError` if the container is not already running; `stop()` is a no-op; `destroy()` always raises to prevent accidental removal. `rebase_path()` extends the base implementation by lazily loading the container's actual mounts from Docker via `docker_container_mounts` when no volumes have been configured.
215
-
216
- ### Call path
217
-
218
- A command reaches the target environment in four steps:
219
-
220
- 1. **Optionally prepare** — the caller calls `ensure_running()` (or uses the runner as a context manager). This triggers `build()` then `start()`. For `LocalRunner` and `SshRunner.build()` these are no-ops; for `DockerRunner` they build the image and create or restart the container; for `SshRunner.start()` the paramiko connection is opened.
221
-
222
- 2. **Call `execute(cmd)`** — the caller passes a list of arguments or a raw shell string, with optional `workdir` and `env` overrides.
223
-
224
- 3. **Backend dispatch** — `LocalRunner` forwards to `shell_run`; `SshRunner` assembles a shell string and calls `exec_command`; the Docker runners assemble a `docker exec` invocation and forward it to `shell_run`.
225
-
226
- 4. **Result** — the backend's stdout, stderr, and exit code are wrapped in a `RunnerResult` and returned to the caller unchanged.
227
-
228
- ## Integration in the Suite
229
-
230
- This package is part of the Wexample Suite — a collection of high-quality, modular tools designed to work seamlessly together across multiple languages and environments.
231
-
232
- ### Related Packages
233
-
234
- The suite includes packages for configuration management, file handling, prompts, and more. Each package can be used independently or as part of the integrated suite.
235
-
236
- ## Dependencies
237
-
238
- - paramiko: >=3.0.0
239
- - wexample-helpers: >=20.5.0
240
-
241
- ## Versioning & Compatibility Policy
242
-
243
- Wexample packages follow **Semantic Versioning** (SemVer):
244
-
245
- - **MAJOR**: Breaking changes
246
- - **MINOR**: New features, backward compatible
247
- - **PATCH**: Bug fixes, backward compatible
248
-
249
- We maintain backward compatibility within major versions and provide clear migration guides for breaking changes.
250
-
251
- ## License
252
-
253
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
254
-
255
- Free to use in both personal and commercial projects.
256
-
257
- ## About us
258
-
259
- [Wexample](https://wexample.com) stands as a cornerstone of the digital ecosystem — a collective of seasoned engineers, researchers, and creators driven by a relentless pursuit of technological excellence. More than a media platform, it has grown into a vibrant community where innovation meets craftsmanship, and where every line of code reflects a commitment to clarity, durability, and shared intelligence.
260
-
261
- This packages suite embodies this spirit. Trusted by professionals and enthusiasts alike, it delivers a consistent, high-quality foundation for modern development — open, elegant, and battle-tested. Its reputation is built on years of collaboration, refinement, and rigorous attention to detail, making it a natural choice for those who demand both robustness and beauty in their tools.
262
-
263
- Wexample cultivates a culture of mastery. Each package, each contribution carries the mark of a community that values precision, ethics, and innovation — a community proud to shape the future of digital craftsmanship.
264
-
265
- Built and maintained by [Romain Weeger](https://weeger.io).
266
-
267
- ## Known Limitations & Roadmap
268
-
269
- Current limitations and planned features are tracked in the GitHub issues.
270
-
271
- See the [project roadmap](https://github.com/wexample/python-runner/issues) for upcoming features and improvements.
272
-
273
- ## Status & Compatibility
274
-
275
- **Maturity**: Production-ready
276
-
277
- **Python Support**: >=3.10
278
-
279
- **OS Support**: Linux, macOS, Windows
280
-
281
- **Status**: Actively maintained
282
-
283
- ## Useful Links
284
-
285
- - **Homepage**: https://github.com/wexample/python-runner
286
- - **Issue Tracker**: https://github.com/wexample/python-runner/issues
287
- - **Discussions**: https://github.com/wexample/python-runner/discussions
288
- - **PyPI**: [pypi.org/project/wexample-runner](https://pypi.org/project/wexample-runner/)
289
-
290
- ## Migration Notes
291
-
292
- When upgrading between major versions, refer to the migration guides in the documentation.
293
-
294
- Breaking changes are clearly documented with upgrade paths and examples.
@@ -1,276 +0,0 @@
1
- # runner
2
-
3
- Version: 10.0.2
4
-
5
- `wexample-runner` gives Python ≥ 3.10 code a single `execute(cmd)` call that runs shell commands on the local machine via subprocess, on a remote server over SSH (paramiko), or inside a Docker container — without the caller branching on the target environment. Every runner follows the same `build / start / stop / destroy` lifecycle and returns a `RunnerResult` dataclass carrying `stdout`, `stderr`, and `exit_code`. It targets developers who automate operations across mixed execution environments and want one interface that works regardless of where the command lands.
6
-
7
- ## Table of Contents
8
-
9
- - [Installation](#installation)
10
- - [Quickstart](#quickstart)
11
- - [Tests](#tests)
12
- - [Architecture](#architecture)
13
- - [Integration in the Suite](#integration-in-the-suite)
14
- - [Dependencies](#dependencies)
15
- - [Versioning & Compatibility Policy](#versioning--compatibility-policy)
16
- - [License](#license)
17
- - [About us](#about-us)
18
- - [Known Limitations & Roadmap](#known-limitations--roadmap)
19
- - [Status & Compatibility](#status--compatibility)
20
- - [Useful Links](#useful-links)
21
- - [Migration Notes](#migration-notes)
22
-
23
- ## Installation
24
-
25
- ```bash
26
- pip install wexample-runner
27
- ```
28
-
29
- Requires Python >=3.10.
30
-
31
- ## Quickstart
32
-
33
- Install the package:
34
-
35
- ```bash
36
- pip install wexample-runner
37
- ```
38
-
39
- `LocalRunner` runs commands on the local machine with no setup:
40
-
41
- ```python
42
- from wexample_runner.runner.local_runner import LocalRunner
43
-
44
- runner = LocalRunner()
45
- result = runner.execute(["echo", "hello"])
46
-
47
- print(result.stdout) # hello\n
48
- print(result.exit_code) # 0
49
- print(result.is_success()) # True
50
- ```
51
-
52
- `execute` accepts a list of arguments or a plain shell string and always returns a `RunnerResult` dataclass carrying `stdout`, `stderr`, and `exit_code`.
53
-
54
- To raise instead of checking the exit code manually:
55
-
56
- ```python
57
- result.raise_on_error()
58
- ```
59
-
60
- ## Tests
61
-
62
- This project uses `pytest` for testing and `pytest-cov` for code coverage analysis.
63
-
64
- ### Installation
65
-
66
- First, install the required testing dependencies:
67
- ```bash
68
- .venv/bin/python -m pip install pytest pytest-cov
69
- ```
70
-
71
- ### Basic Usage
72
-
73
- Run all tests with coverage:
74
- ```bash
75
- .venv/bin/python -m pytest --cov --cov-report=html
76
- ```
77
-
78
- ### Common Commands
79
- ```bash
80
- # Run tests with coverage for a specific module
81
- .venv/bin/python -m pytest --cov=your_module
82
-
83
- # Show which lines are not covered
84
- .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing
85
-
86
- # Generate an HTML coverage report
87
- .venv/bin/python -m pytest --cov=your_module --cov-report=html
88
-
89
- # Combine terminal and HTML reports
90
- .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing --cov-report=html
91
-
92
- # Run specific test file with coverage
93
- .venv/bin/python -m pytest tests/test_file.py --cov=your_module --cov-report=term-missing
94
- ```
95
-
96
- ### Viewing HTML Reports
97
-
98
- After generating an HTML report, open `htmlcov/index.html` in your browser to view detailed line-by-line coverage information.
99
-
100
- ### Coverage Threshold
101
-
102
- To enforce a minimum coverage percentage:
103
- ```bash
104
- .venv/bin/python -m pytest --cov=your_module --cov-fail-under=80
105
- ```
106
-
107
- This will cause the test suite to fail if coverage drops below 80%.
108
-
109
- ## Architecture
110
-
111
- The package is organised around one abstract base, one result dataclass, one optional config dataclass, one registry, and five concrete runner classes. Every public entry point funnels through `AbstractRunner.execute()` and every response comes back as a `RunnerResult`.
112
-
113
- ### Abstract base
114
-
115
- src/wexample_runner/runner/abstract_runner.py defines the contract every runner implements.
116
-
117
- **Lifecycle** — four methods cover the full arc of an environment:
118
-
119
- | Method | Responsibility |
120
- |---|---|
121
- | `build()` | Prepare the environment (build image, verify connectivity). No-op by default. |
122
- | `start()` | Make the environment ready to receive commands. No-op by default. |
123
- | `stop()` | Pause without removing anything. |
124
- | `destroy()` | Remove completely. |
125
-
126
- `ensure_running()` composes `build()` then `start()`. The class also implements the context manager protocol: `__enter__` calls `ensure_running()`, `__exit__` calls `stop()` and, when `ephemeral=True`, `destroy()`.
127
-
128
- **Execution** — the one abstract method every subclass must provide:
129
-
130
- ```python
131
- def execute(
132
- self,
133
- cmd: list[str] | str,
134
- workdir: str | None = None,
135
- env: dict[str, str] | None = None,
136
- ) -> RunnerResult:
137
- ```
138
-
139
- ### Result
140
-
141
- src/wexample_runner/runner_result.py is a plain dataclass. Every `execute()` call returns one:
142
-
143
- ```python
144
- @dataclass
145
- class RunnerResult:
146
- exit_code: int
147
- stderr: str
148
- stdout: str
149
- ```
150
-
151
- Two helpers cover the common patterns: `is_success()` returns `exit_code == 0`; `raise_on_error()` raises `RuntimeError` on non-zero exit, embedding `stderr` or `stdout` in the message.
152
-
153
- ### Configuration
154
-
155
- src/wexample_runner/runner_config.py is an optional declarative layer for Docker-based runners. It groups the fields a runner needs at construction time — `dockerfile`, `image_name`, `mount_path`, `container_workdir`, `volumes`, and `ephemeral` — into one object a caller can pass around rather than threading individual keyword arguments.
156
-
157
- ### Registry
158
-
159
- src/wexample_runner/runner_registry.py holds named `AbstractRunner` instances. It extends `SharedRegistry` from `wexample_helpers`, which provides a class-level singleton via `.shared()` alongside ordinary instantiation for isolated registries.
160
-
161
- Callers register a pre-configured runner under an explicit string key and retrieve it by the same key:
162
-
163
- ```python
164
- RunnerRegistry.shared().register(runner, key="prod")
165
- runner = RunnerRegistry.shared().get_or_raise("prod")
166
- ```
167
-
168
- `status()` introspects every registered runner and returns a list of dicts with `name`, `type`, `is_built`, `is_running`, and `ephemeral`.
169
-
170
- ### Concrete runners
171
-
172
- ### LocalRunner
173
-
174
- src/wexample_runner/runner/local_runner.py runs commands on the local machine through `wexample_helpers.helper.shell.shell_run`. Both `is_built` and `is_running` always return `True`; the runner has no lifecycle to manage. `execute()` captures stdout and stderr with `capture=True` and returns them in a `RunnerResult`.
175
-
176
- ### SshRunner
177
-
178
- src/wexample_runner/runner/ssh_runner.py wraps a `paramiko.SSHClient`. The connection is opened in `start()` and closed in `stop()`. `execute()` assembles a shell string: if `cmd` is a list it joins it with `shlex.join`, prepends `cd {workdir} &&` when a workdir is given, and prefixes environment variables as `KEY=value` pairs before calling `exec_command`. `is_running` inspects the paramiko transport's active state.
179
-
180
- ### AbstractDockerRunner
181
-
182
- src/wexample_runner/runner/abstract_docker_runner.py provides the shared `docker exec` logic used by both Docker subclasses. `execute()` builds a `docker exec` invocation:
183
-
184
- ```
185
- docker exec [--user U] [-w workdir] [-e K=V ...] <container_name> <cmd>
186
- ```
187
-
188
- It also provides `rebase_path(host_path)`, which translates an absolute host path to its equivalent inside the container by matching it against the deepest registered volume mount. The `_find_mount_for` helper picks the longest matching mount so nested mounts take priority.
189
-
190
- ### DockerRunner
191
-
192
- src/wexample_runner/runner/docker_runner.py owns its container end-to-end. `build()` calls `docker_build_image` when the image does not exist yet. `start()` creates the container with `docker_run_container` (pinning it to the current host uid:gid) or restarts an existing stopped one with `docker_start_container`. `destroy()` stops the container, removes it, then removes the image. `is_built` checks whether the image exists via `docker_image_exists`.
193
-
194
- ### DockerAttachedRunner
195
-
196
- src/wexample_runner/runner/docker_attached_runner.py attaches to a container it does not own. `start()` raises `RuntimeError` if the container is not already running; `stop()` is a no-op; `destroy()` always raises to prevent accidental removal. `rebase_path()` extends the base implementation by lazily loading the container's actual mounts from Docker via `docker_container_mounts` when no volumes have been configured.
197
-
198
- ### Call path
199
-
200
- A command reaches the target environment in four steps:
201
-
202
- 1. **Optionally prepare** — the caller calls `ensure_running()` (or uses the runner as a context manager). This triggers `build()` then `start()`. For `LocalRunner` and `SshRunner.build()` these are no-ops; for `DockerRunner` they build the image and create or restart the container; for `SshRunner.start()` the paramiko connection is opened.
203
-
204
- 2. **Call `execute(cmd)`** — the caller passes a list of arguments or a raw shell string, with optional `workdir` and `env` overrides.
205
-
206
- 3. **Backend dispatch** — `LocalRunner` forwards to `shell_run`; `SshRunner` assembles a shell string and calls `exec_command`; the Docker runners assemble a `docker exec` invocation and forward it to `shell_run`.
207
-
208
- 4. **Result** — the backend's stdout, stderr, and exit code are wrapped in a `RunnerResult` and returned to the caller unchanged.
209
-
210
- ## Integration in the Suite
211
-
212
- This package is part of the Wexample Suite — a collection of high-quality, modular tools designed to work seamlessly together across multiple languages and environments.
213
-
214
- ### Related Packages
215
-
216
- The suite includes packages for configuration management, file handling, prompts, and more. Each package can be used independently or as part of the integrated suite.
217
-
218
- ## Dependencies
219
-
220
- - paramiko: >=3.0.0
221
- - wexample-helpers: >=20.5.0
222
-
223
- ## Versioning & Compatibility Policy
224
-
225
- Wexample packages follow **Semantic Versioning** (SemVer):
226
-
227
- - **MAJOR**: Breaking changes
228
- - **MINOR**: New features, backward compatible
229
- - **PATCH**: Bug fixes, backward compatible
230
-
231
- We maintain backward compatibility within major versions and provide clear migration guides for breaking changes.
232
-
233
- ## License
234
-
235
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
236
-
237
- Free to use in both personal and commercial projects.
238
-
239
- ## About us
240
-
241
- [Wexample](https://wexample.com) stands as a cornerstone of the digital ecosystem — a collective of seasoned engineers, researchers, and creators driven by a relentless pursuit of technological excellence. More than a media platform, it has grown into a vibrant community where innovation meets craftsmanship, and where every line of code reflects a commitment to clarity, durability, and shared intelligence.
242
-
243
- This packages suite embodies this spirit. Trusted by professionals and enthusiasts alike, it delivers a consistent, high-quality foundation for modern development — open, elegant, and battle-tested. Its reputation is built on years of collaboration, refinement, and rigorous attention to detail, making it a natural choice for those who demand both robustness and beauty in their tools.
244
-
245
- Wexample cultivates a culture of mastery. Each package, each contribution carries the mark of a community that values precision, ethics, and innovation — a community proud to shape the future of digital craftsmanship.
246
-
247
- Built and maintained by [Romain Weeger](https://weeger.io).
248
-
249
- ## Known Limitations & Roadmap
250
-
251
- Current limitations and planned features are tracked in the GitHub issues.
252
-
253
- See the [project roadmap](https://github.com/wexample/python-runner/issues) for upcoming features and improvements.
254
-
255
- ## Status & Compatibility
256
-
257
- **Maturity**: Production-ready
258
-
259
- **Python Support**: >=3.10
260
-
261
- **OS Support**: Linux, macOS, Windows
262
-
263
- **Status**: Actively maintained
264
-
265
- ## Useful Links
266
-
267
- - **Homepage**: https://github.com/wexample/python-runner
268
- - **Issue Tracker**: https://github.com/wexample/python-runner/issues
269
- - **Discussions**: https://github.com/wexample/python-runner/discussions
270
- - **PyPI**: [pypi.org/project/wexample-runner](https://pypi.org/project/wexample-runner/)
271
-
272
- ## Migration Notes
273
-
274
- When upgrading between major versions, refer to the migration guides in the documentation.
275
-
276
- Breaking changes are clearly documented with upgrade paths and examples.