uber-compose 3.1.0__tar.gz → 3.2.0a1__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 (97) hide show
  1. {uber_compose-3.1.0/uber_compose.egg-info → uber_compose-3.2.0a1}/PKG-INFO +1 -1
  2. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/CLI_USAGE.md +57 -4
  3. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/__init__.py +2 -1
  4. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/docker_compose_shell/exec_strategies.py +61 -3
  5. uber_compose-3.2.0a1/uber_compose/helpers/exec_result.py +53 -0
  6. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/vedro_plugin/base_structures/common_json_cli.py +32 -4
  7. uber_compose-3.2.0a1/uber_compose/version +1 -0
  8. {uber_compose-3.1.0 → uber_compose-3.2.0a1/uber_compose.egg-info}/PKG-INFO +1 -1
  9. uber_compose-3.1.0/uber_compose/helpers/exec_result.py +0 -27
  10. uber_compose-3.1.0/uber_compose/version +0 -1
  11. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/LICENSE +0 -0
  12. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/MANIFEST.in +0 -0
  13. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/README.md +0 -0
  14. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/E2E_CONTAINER_SETUP.md +0 -0
  15. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/ENV_LOCKS_FEATURE_REQUEST.md +0 -0
  16. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/EXEC_STRATEGIES.md +0 -0
  17. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/HOOKS.md +0 -0
  18. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/LLM_RULES.md +0 -0
  19. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/PARALLELISM.md +0 -0
  20. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/PLAN_CONSISTENCY.md +0 -0
  21. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/README.md +0 -0
  22. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/RELEASE_TAGS.md +0 -0
  23. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/UBER_COMPOSE_VEDRO_CONFIG.md +0 -0
  24. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/X_MIGRATION.md +0 -0
  25. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/docs/common.puml +0 -0
  26. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/requirements.txt +0 -0
  27. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/setup.cfg +0 -0
  28. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/setup.py +0 -0
  29. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/__init__.py +0 -0
  30. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/constants.py +0 -0
  31. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/docker_compose.py +0 -0
  32. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/docker_compose_shell/__init__.py +0 -0
  33. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/docker_compose_shell/interface.py +0 -0
  34. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/docker_compose_shell/types.py +0 -0
  35. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/sequence_run_types.py +0 -0
  36. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/system_docker_compose.py +0 -0
  37. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/utils/__init__.py +0 -0
  38. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/utils/compose_files.py +0 -0
  39. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/utils/compose_instance_cfg.py +0 -0
  40. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/utils/env_files.py +0 -0
  41. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/utils/process_command_output.py +0 -0
  42. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/utils/shell_process.py +0 -0
  43. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/core/utils/state_waiting.py +0 -0
  44. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/env_description/__init__.py +0 -0
  45. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/env_description/env_tools.py +0 -0
  46. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/env_description/env_types.py +0 -0
  47. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/errors/__init__.py +0 -0
  48. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/errors/migrations.py +0 -0
  49. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/errors/mounted_files.py +0 -0
  50. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/errors/up.py +0 -0
  51. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/__init__.py +0 -0
  52. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/broken_services.py +0 -0
  53. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/bytes_pickle.py +0 -0
  54. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/countdown_counter.py +0 -0
  55. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/current_env.py +0 -0
  56. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/env_id.py +0 -0
  57. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/exec_record.py +0 -0
  58. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/health_policy.py +0 -0
  59. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/hooks.py +0 -0
  60. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/jobs_result.py +0 -0
  61. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/labels.py +0 -0
  62. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/live_env.py +0 -0
  63. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/parameterization.py +0 -0
  64. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/singleton.py +0 -0
  65. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/state_keeper.py +0 -0
  66. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/helpers/workers_per_env.py +0 -0
  67. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/output/__init__.py +0 -0
  68. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/output/console.py +0 -0
  69. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/output/styles.py +0 -0
  70. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/parallel_plugin/__init__.py +0 -0
  71. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/parallel_plugin/details.py +0 -0
  72. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/parallel_plugin/grouper.py +0 -0
  73. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/parallel_plugin/grouping.py +0 -0
  74. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/parallel_plugin/planner.py +0 -0
  75. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/parallel_plugin/plugin.py +0 -0
  76. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/parallel_plugin/runner.py +0 -0
  77. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/parallel_plugin/types.py +0 -0
  78. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/parallel_plugin/worker_api.py +0 -0
  79. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/parallel_plugin/worker_filter.py +0 -0
  80. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/uber_compose.py +0 -0
  81. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/utils/__init__.py +0 -0
  82. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/utils/docker_compose_files_path.py +0 -0
  83. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/utils/docker_compose_service_deps.py +0 -0
  84. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/utils/search_docker_compose_files.py +0 -0
  85. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/utils/services_construction.py +0 -0
  86. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/vedro_plugin/__init__.py +0 -0
  87. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/vedro_plugin/base_structures/__init__.py +0 -0
  88. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/vedro_plugin/helpers/__init__.py +0 -0
  89. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/vedro_plugin/helpers/scenario_ordering.py +0 -0
  90. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/vedro_plugin/helpers/scenario_tag_processing.py +0 -0
  91. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/vedro_plugin/helpers/test_env_vars_setter.py +0 -0
  92. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/vedro_plugin/plugin.py +0 -0
  93. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose/version.py +0 -0
  94. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose.egg-info/SOURCES.txt +0 -0
  95. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose.egg-info/dependency_links.txt +0 -0
  96. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose.egg-info/requires.txt +0 -0
  97. {uber_compose-3.1.0 → uber_compose-3.2.0a1}/uber_compose.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: uber-compose
3
- Version: 3.1.0
3
+ Version: 3.2.0a1
4
4
  Summary: docker compose testing env orchestrator
5
5
  Home-page: https://github.com/ko10ok/uber-compose
6
6
  Author: Yuriy Sagitov
@@ -4,6 +4,7 @@
4
4
 
5
5
  ## Table of Contents
6
6
  - [Basic Usage](#basic-usage)
7
+ - [Execution Modes](#execution-modes)
7
8
  - [Extended Command Result](#extended-command-result)
8
9
  - [Custom JSON Parser](#custom-json-parser)
9
10
  - [CommandResult](#commandresult)
@@ -75,6 +76,53 @@ class MyCli(CommonJsonCli):
75
76
 
76
77
  ```
77
78
 
79
+ ## Execution Modes
80
+
81
+ By default, `exec()` waits until the process exits.
82
+ `wait` controls when `exec()` returns; `life_cycle_policy` controls whether a still-running command is stopped.
83
+
84
+ | Mode | Call | `exit_code` | `waiting_done_successfully` | `has_no_errors()` |
85
+ |---|---|---|---|---|
86
+ | Wait until exit (default) | `wait` omitted (`wait=ProcessExit()` by default) | actual `int` | `True` | `exit_code == 0` and `stderr == []` |
87
+ | Wait until exit, timeout | `wait` omitted, `timeout=...` | `None` | `False` | `False` |
88
+ | Detached, don't wait | `wait=None`, `kill_after_command_still_running=False` | `None` | `True` | `False` — exit code is unknown |
89
+ | Wait condition met, process stopped | callable returns `True` while process runs | `TerminatedByCondition(143/137/0)` | `True` | `True` if `stderr == []` |
90
+ | Wait condition met, process exited by itself | callable returns `True` after exit | actual `int` | `True` | `exit_code == 0` and `stderr == []` |
91
+ | Wait condition not met | callable returns `False` | `None` | `False` | `False` |
92
+
93
+ `stderr != []` makes `has_no_errors()` fail in every mode.
94
+
95
+ ```python
96
+ from time import sleep
97
+ from uber_compose import ExecLifeCyclePolicy
98
+
99
+ # Default: wait until the command exits
100
+ result = await cli.exec(command='my-app')
101
+ # exit_code=0 | waiting_done_successfully=True | stderr=[]
102
+ assert result.has_no_errors()
103
+
104
+ # Detached: return immediately, keep the process running
105
+ result = await cli.exec(
106
+ command='my-worker',
107
+ wait=None,
108
+ life_cycle_policy=ExecLifeCyclePolicy(
109
+ kill_after_command_still_running=False,
110
+ ),
111
+ )
112
+ # exit_code=None | waiting_done_successfully=True | stderr=[]
113
+ assert not result.has_no_errors() # no exit code to verify
114
+
115
+ # Wait for a condition; stop the process when it is met
116
+ result = await cli.exec(
117
+ command='tail -f /dev/null',
118
+ wait=lambda *_: sleep(1) or True,
119
+ )
120
+ # exit_code=TerminatedByCondition(143) | waiting_done_successfully=True | stderr=[]
121
+ assert result.has_no_errors()
122
+ ```
123
+
124
+ `TerminatedByCondition` is an `int` subclass used when the process was stopped because the `wait` condition returned `True`. It is truthy even for `TerminatedByCondition(0)`.
125
+
78
126
  ## Extended Command Result
79
127
 
80
128
  Extend `CommandResult` to add custom fields:
@@ -217,11 +265,16 @@ cli = CommonJsonCli(parse_json_logs=parser.parse_output_to_json)
217
265
  - **`stderr`**: `list[str | dict]` - Error logs (based on log level)
218
266
  - **`cmd`**: `str` - Executed command
219
267
  - **`env`**: `dict[str, str]` - Environment variables used
220
- - **`exit_code`**: `int | None` - Application exit code; `None` means the process did not finish
268
+ - **`exit_code`**: `int | None` - Application exit code; `None` if the process did not finish
269
+ - **`waiting_done_successfully`**: `bool` - `False` when a timeout or unmet wait condition interrupted waiting
270
+
271
+ ### `has_no_errors()`
221
272
 
222
- ### Methods
273
+ Returns `self`; the check itself happens through `__bool__`. It passes only when:
223
274
 
224
- - **`has_no_errors()`**: Returns `True` only if `stderr` is empty and `exit_code` is `0`
275
+ 1. `stderr == []`;
276
+ 2. `waiting_done_successfully is True`;
277
+ 3. `exit_code` is `TerminatedByCondition`, or `exit_code == 0`.
225
278
 
226
279
  ### Example
227
280
 
@@ -322,7 +375,7 @@ assert result.has_no_errors()
322
375
  | Parameter | Type | Default | Description |
323
376
  |-----------|------|---------|-------------|
324
377
  | `kill_before_same_old_command_running` | `bool` | `True` | Kill the previous instance of the same command if it is still running before executing a new one |
325
- | `kill_after_command_still_running` | `bool` | `True` | Kill the command if it is still running after the timeout has elapsed |
378
+ | `kill_after_command_still_running` | `bool` | `True` | Kill the command if it is still running after a timeout or after a wait condition is met |
326
379
  | `break_on_timeout` | `bool` | `True` | Stop waiting and return early if the timeout is reached |
327
380
 
328
381
  ### Basic Usage
@@ -17,6 +17,7 @@ from uber_compose.helpers.current_env import get_run_depth
17
17
  from uber_compose.helpers.current_env import is_child_project
18
18
  from uber_compose.helpers.exec_result import ExecResult
19
19
  from uber_compose.helpers.exec_result import ExecTimeout
20
+ from uber_compose.helpers.exec_result import TerminatedByCondition
20
21
  from uber_compose.helpers.health_policy import UpHealthPolicy
21
22
  from uber_compose.helpers.hooks import UberComposeEvent
22
23
  from uber_compose.helpers.live_env import LiveEnvironment
@@ -56,7 +57,7 @@ __all__ = (
56
57
  'TheUberCompose', 'SystemUberCompose',
57
58
  'Environment', 'Service', 'Env', 'OverridenService',
58
59
  'CommonJsonCli', 'CommandResult', 'ProcessExit', 'JsonParser', 'json_parser', 'ExecTimeout', 'TimeOutCheck',
59
- 'ExecLifeCyclePolicy', 'ExecResult',
60
+ 'ExecLifeCyclePolicy', 'ExecResult', 'TerminatedByCondition',
60
61
  'ExecStrategy', 'ExecContext', 'PidofExecStrategy', 'StatusFileExecStrategy',
61
62
  'VedroUberCompose', 'UpHealthPolicy', 'DEFAULT_COMPOSE', 'ComposeConfig', 'DEFAULT_ENV_DESCRIPTION',
62
63
  'LogEvents', 'LogPolicy', 'LogPolicySet',
@@ -16,6 +16,7 @@ from uber_compose.core.docker_compose_shell.types import ExecLifeCyclePolicy
16
16
  from uber_compose.core.utils.shell_process import parse_process_command_name
17
17
  from uber_compose.helpers.exec_result import ExecResult
18
18
  from uber_compose.helpers.exec_result import ExecTimeout
19
+ from uber_compose.helpers.exec_result import TerminatedByCondition
19
20
  from uber_compose.helpers.jobs_result import JobResult
20
21
 
21
22
  if TYPE_CHECKING:
@@ -24,6 +25,9 @@ if TYPE_CHECKING:
24
25
 
25
26
  INITIAL_POLL_DELAY_S = 0.05
26
27
  MAX_POLL_DELAY_S = 1.0
28
+ EXIT_FILE_RACE_DELAY_S = 0.1
29
+ TERMINATION_TIMEOUT = TimeOutCheck(attempts=3, delay_s=1)
30
+ KILL_TIMEOUT = TimeOutCheck(attempts=1, delay_s=1)
27
31
 
28
32
 
29
33
  @dataclass(frozen=True)
@@ -149,7 +153,35 @@ class StatusFileExecStrategy(ExecStrategy):
149
153
  if context.life_cycle_policy.kill_after_command_still_running:
150
154
  await self._kill(shell, context, cmd_name)
151
155
  return ExecTimeout(stdout=stdout, cmd=command)
152
- return ExecResult(stdout=stdout, cmd=command, exit_code=exit_code)
156
+
157
+ if exit_code is not None:
158
+ return ExecResult(stdout=stdout, cmd=command, exit_code=exit_code)
159
+
160
+ # The condition is met, but the command has not published its exit code yet:
161
+ # it is either just finishing or still running. Give it a short chance to
162
+ # exit naturally, then stop it if requested.
163
+ exited = await self._wait_for_exit_file(
164
+ shell, context, exit_file,
165
+ TimeOutCheck(attempts=1, delay_s=EXIT_FILE_RACE_DELAY_S),
166
+ )
167
+ if exited:
168
+ stdout, exit_code = await self._read_result(
169
+ shell, context, log_file, exit_file, marker,
170
+ )
171
+ if exit_code is not None:
172
+ return ExecResult(stdout=stdout, cmd=command, exit_code=exit_code)
173
+
174
+ if not context.life_cycle_policy.kill_after_command_still_running:
175
+ return ExecResult(
176
+ stdout=stdout, cmd=command, exit_code=TerminatedByCondition(0),
177
+ )
178
+
179
+ stdout, exit_code = await self._terminate_and_read(
180
+ shell, context, cmd_name, log_file, exit_file, marker, stdout,
181
+ )
182
+ return ExecResult(
183
+ stdout=stdout, cmd=command, exit_code=TerminatedByCondition(exit_code),
184
+ )
153
185
 
154
186
  @staticmethod
155
187
  def _resolve_timeout(timeout: TimeOutCheck | None) -> TimeOutCheck:
@@ -212,6 +244,30 @@ class StatusFileExecStrategy(ExecStrategy):
212
244
  exit_code = None
213
245
  return stdout, exit_code
214
246
 
247
+ async def _terminate_and_read(self, shell: "ComposeShellInterface", context: ExecContext,
248
+ cmd_name: str, log_file: str, exit_file: str, marker: str,
249
+ stdout: bytes) -> tuple[bytes, int]:
250
+ if not cmd_name:
251
+ return stdout, 0
252
+
253
+ await self._kill(shell, context, cmd_name)
254
+ if await self._wait_for_exit_file(shell, context, exit_file, TERMINATION_TIMEOUT):
255
+ stdout, exit_code = await self._read_result(
256
+ shell, context, log_file, exit_file, marker,
257
+ )
258
+ if exit_code is not None:
259
+ return stdout, exit_code
260
+
261
+ await self._kill(shell, context, cmd_name, force=True)
262
+ if await self._wait_for_exit_file(shell, context, exit_file, KILL_TIMEOUT):
263
+ stdout, exit_code = await self._read_result(
264
+ shell, context, log_file, exit_file, marker,
265
+ )
266
+ if exit_code is not None:
267
+ return stdout, exit_code
268
+
269
+ return stdout, 137
270
+
215
271
  @staticmethod
216
272
  async def _run_wait_callable(context: ExecContext, command: str, wait: Callable) -> bool:
217
273
  if asyncio.iscoroutinefunction(wait):
@@ -231,12 +287,14 @@ class StatusFileExecStrategy(ExecStrategy):
231
287
  )
232
288
 
233
289
  @staticmethod
234
- async def _kill(shell: "ComposeShellInterface", context: ExecContext, cmd_name: str) -> None:
290
+ async def _kill(shell: "ComposeShellInterface", context: ExecContext, cmd_name: str,
291
+ force: bool = False) -> None:
235
292
  if not cmd_name:
236
293
  return
294
+ args = f'-9 {shlex.quote(cmd_name)}' if force else shlex.quote(cmd_name)
237
295
  await shell.dc_exec_raw(
238
296
  context.container,
239
- f'killall {shlex.quote(cmd_name)}',
297
+ f'killall {args}',
240
298
  env=context.env,
241
299
  root=context.root,
242
300
  )
@@ -0,0 +1,53 @@
1
+ from typing import NamedTuple
2
+
3
+
4
+ class TerminatedByCondition(int):
5
+ """Exit code marker for a process stopped because a wait condition was met.
6
+
7
+ It behaves like an int exit code but is always truthy: the termination was
8
+ intentional, so even a zero code must not look like an error or a missing
9
+ result.
10
+ """
11
+
12
+ def __new__(cls, exit_code: int = 0):
13
+ return super().__new__(cls, exit_code)
14
+
15
+ def __repr__(self) -> str:
16
+ return f'{type(self).__name__}({int(self)})'
17
+
18
+ def __bool__(self) -> bool:
19
+ return True
20
+
21
+ def __eq__(self, other) -> bool:
22
+ if isinstance(other, int):
23
+ return int(self) == int(other)
24
+ return NotImplemented
25
+
26
+ def __hash__(self) -> int:
27
+ return hash(int(self))
28
+
29
+
30
+ class ExecResult(NamedTuple):
31
+ stdout: bytes
32
+ cmd: str
33
+ exit_code: int | None = None
34
+
35
+ def __str__(self):
36
+ return (f'ExecResult('
37
+ f' cmd={self.cmd}, '
38
+ f' stdout={self.stdout}, '
39
+ f' exit_code={self.exit_code}, '
40
+ f')')
41
+
42
+
43
+ class ExecTimeout(NamedTuple):
44
+ stdout: bytes
45
+ cmd: str
46
+ exit_code: int | None = None
47
+
48
+ def __str__(self):
49
+ return (f'ExecTimeout('
50
+ f' cmd={self.cmd}, '
51
+ f' stdout={self.stdout}, '
52
+ f' exit_code={self.exit_code}, '
53
+ f')')
@@ -15,6 +15,8 @@ from uber_compose.core.docker_compose_shell.interface import TimeOutCheck
15
15
  from uber_compose.core.docker_compose_shell.types import ExecLifeCyclePolicy
16
16
  from uber_compose.core.sequence_run_types import DEFAULT_ENV_ID
17
17
  from uber_compose.helpers.current_env import get_current_env_id
18
+ from uber_compose.helpers.exec_result import ExecTimeout
19
+ from uber_compose.helpers.exec_result import TerminatedByCondition
18
20
  from uber_compose.uber_compose import SystemUberCompose
19
21
  from uber_compose.uber_compose import TheUberCompose
20
22
 
@@ -26,6 +28,7 @@ class CommandResult:
26
28
  cmd: str
27
29
  env: dict[str, str]
28
30
  exit_code: int | None = None
31
+ waiting_done_successfully: bool = True
29
32
 
30
33
  def _format_value(self, key, value, indent_level=1, print_new_line=True):
31
34
  """Formats value considering its type and nesting level."""
@@ -93,12 +96,19 @@ class CommandResult:
93
96
  self._format_value("cmd", self.cmd, print_new_line=True),
94
97
  self._format_value("env", self.env),
95
98
  self._format_value("exit_code", self.exit_code),
99
+ self._format_value("waiting_done_successfully", self.waiting_done_successfully),
96
100
  ]
97
101
 
98
102
  return f"{self.__class__.__name__}(\n" + ",\n".join(fields) + "\n)"
99
103
 
100
104
  def _has_no_errors(self) -> bool:
101
- return self.stderr == [] and self.exit_code == 0
105
+ if self.stderr != []:
106
+ return False
107
+ if not self.waiting_done_successfully:
108
+ return False
109
+ if isinstance(self.exit_code, TerminatedByCondition):
110
+ return True
111
+ return self.exit_code == 0
102
112
 
103
113
  def __bool__(self):
104
114
  has_no_errors = self._has_no_errors()
@@ -230,9 +240,20 @@ class CommonJsonCli(Generic[TCommandResult]):
230
240
  self._life_cycle_policy = life_cycle_policy
231
241
  self._exec = exec
232
242
 
233
- def _make_result(self, cmd: str, env: dict[str, str], logs: bytes, **kwargs) -> TCommandResult:
243
+ def _make_result(self, cmd: str, env: dict[str, str], logs: bytes,
244
+ exit_code: int | None = None,
245
+ waiting_done_successfully: bool = True,
246
+ **kwargs) -> TCommandResult:
234
247
  stdout, stderr = self._parse_json_logs(logs)
235
- return self._result_factory(stdout=stdout, stderr=stderr, cmd=cmd, env=env, **kwargs)
248
+ return self._result_factory(
249
+ stdout=stdout,
250
+ stderr=stderr,
251
+ cmd=cmd,
252
+ env=env,
253
+ exit_code=exit_code,
254
+ waiting_done_successfully=waiting_done_successfully,
255
+ **kwargs,
256
+ )
236
257
 
237
258
  async def exec(self,
238
259
  command: str,
@@ -282,10 +303,17 @@ class CommonJsonCli(Generic[TCommandResult]):
282
303
 
283
304
  result = await self._cli_client.exec(**exec_kwargs)
284
305
 
306
+ result_extra = dict(command_result_extra)
307
+ waiting_done_successfully = result_extra.pop(
308
+ 'waiting_done_successfully',
309
+ not isinstance(result, ExecTimeout),
310
+ )
311
+
285
312
  return self._make_result(
286
313
  cmd=command,
287
314
  env=extra_env or {},
288
315
  logs=result.stdout,
289
316
  exit_code=result.exit_code,
290
- **command_result_extra,
317
+ waiting_done_successfully=waiting_done_successfully,
318
+ **result_extra,
291
319
  )
@@ -0,0 +1 @@
1
+ 3.2.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: uber-compose
3
- Version: 3.1.0
3
+ Version: 3.2.0a1
4
4
  Summary: docker compose testing env orchestrator
5
5
  Home-page: https://github.com/ko10ok/uber-compose
6
6
  Author: Yuriy Sagitov
@@ -1,27 +0,0 @@
1
- from typing import NamedTuple
2
-
3
-
4
- class ExecResult(NamedTuple):
5
- stdout: bytes
6
- cmd: str
7
- exit_code: int | None = None
8
-
9
- def __str__(self):
10
- return (f'ExecResult('
11
- f' cmd={self.cmd}, '
12
- f' stdout={self.stdout}, '
13
- f' exit_code={self.exit_code}, '
14
- f')')
15
-
16
-
17
- class ExecTimeout(NamedTuple):
18
- stdout: bytes
19
- cmd: str
20
- exit_code: int | None = None
21
-
22
- def __str__(self):
23
- return (f'ExecTimeout('
24
- f' cmd={self.cmd}, '
25
- f' stdout={self.stdout}, '
26
- f' exit_code={self.exit_code}, '
27
- f')')
@@ -1 +0,0 @@
1
- 3.1.0
File without changes
File without changes
File without changes
File without changes
File without changes