uber-compose 3.0.0a25__tar.gz → 3.2.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.
Files changed (98) hide show
  1. {uber_compose-3.0.0a25/uber_compose.egg-info → uber_compose-3.2.0}/PKG-INFO +3 -1
  2. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/CLI_USAGE.md +57 -4
  3. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/PARALLELISM.md +33 -0
  4. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/requirements.txt +2 -0
  5. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/__init__.py +6 -1
  6. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/constants.py +8 -0
  7. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/docker_compose_shell/exec_strategies.py +61 -3
  8. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/system_docker_compose.py +5 -1
  9. uber_compose-3.2.0/uber_compose/helpers/exec_result.py +53 -0
  10. uber_compose-3.2.0/uber_compose/helpers/live_env.py +93 -0
  11. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/uber_compose.py +43 -0
  12. uber_compose-3.2.0/uber_compose/utils/search_docker_compose_files.py +25 -0
  13. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/vedro_plugin/__init__.py +1 -3
  14. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/vedro_plugin/base_structures/common_json_cli.py +32 -4
  15. uber_compose-3.2.0/uber_compose/version +1 -0
  16. {uber_compose-3.0.0a25 → uber_compose-3.2.0/uber_compose.egg-info}/PKG-INFO +3 -1
  17. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose.egg-info/SOURCES.txt +1 -0
  18. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose.egg-info/requires.txt +2 -0
  19. uber_compose-3.0.0a25/uber_compose/helpers/exec_result.py +0 -27
  20. uber_compose-3.0.0a25/uber_compose/utils/search_docker_compose_files.py +0 -17
  21. uber_compose-3.0.0a25/uber_compose/version +0 -1
  22. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/LICENSE +0 -0
  23. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/MANIFEST.in +0 -0
  24. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/README.md +0 -0
  25. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/E2E_CONTAINER_SETUP.md +0 -0
  26. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/ENV_LOCKS_FEATURE_REQUEST.md +0 -0
  27. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/EXEC_STRATEGIES.md +0 -0
  28. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/HOOKS.md +0 -0
  29. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/LLM_RULES.md +0 -0
  30. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/PLAN_CONSISTENCY.md +0 -0
  31. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/README.md +0 -0
  32. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/RELEASE_TAGS.md +0 -0
  33. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/UBER_COMPOSE_VEDRO_CONFIG.md +0 -0
  34. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/X_MIGRATION.md +0 -0
  35. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/docs/common.puml +0 -0
  36. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/setup.cfg +0 -0
  37. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/setup.py +0 -0
  38. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/__init__.py +0 -0
  39. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/docker_compose.py +0 -0
  40. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/docker_compose_shell/__init__.py +0 -0
  41. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/docker_compose_shell/interface.py +0 -0
  42. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/docker_compose_shell/types.py +0 -0
  43. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/sequence_run_types.py +0 -0
  44. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/utils/__init__.py +0 -0
  45. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/utils/compose_files.py +0 -0
  46. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/utils/compose_instance_cfg.py +0 -0
  47. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/utils/env_files.py +0 -0
  48. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/utils/process_command_output.py +0 -0
  49. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/utils/shell_process.py +0 -0
  50. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/core/utils/state_waiting.py +0 -0
  51. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/env_description/__init__.py +0 -0
  52. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/env_description/env_tools.py +0 -0
  53. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/env_description/env_types.py +0 -0
  54. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/errors/__init__.py +0 -0
  55. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/errors/migrations.py +0 -0
  56. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/errors/mounted_files.py +0 -0
  57. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/errors/up.py +0 -0
  58. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/__init__.py +0 -0
  59. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/broken_services.py +0 -0
  60. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/bytes_pickle.py +0 -0
  61. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/countdown_counter.py +0 -0
  62. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/current_env.py +0 -0
  63. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/env_id.py +0 -0
  64. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/exec_record.py +0 -0
  65. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/health_policy.py +0 -0
  66. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/hooks.py +0 -0
  67. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/jobs_result.py +0 -0
  68. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/labels.py +0 -0
  69. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/parameterization.py +0 -0
  70. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/singleton.py +0 -0
  71. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/state_keeper.py +0 -0
  72. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/helpers/workers_per_env.py +0 -0
  73. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/output/__init__.py +0 -0
  74. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/output/console.py +0 -0
  75. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/output/styles.py +0 -0
  76. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/parallel_plugin/__init__.py +0 -0
  77. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/parallel_plugin/details.py +0 -0
  78. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/parallel_plugin/grouper.py +0 -0
  79. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/parallel_plugin/grouping.py +0 -0
  80. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/parallel_plugin/planner.py +0 -0
  81. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/parallel_plugin/plugin.py +0 -0
  82. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/parallel_plugin/runner.py +0 -0
  83. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/parallel_plugin/types.py +0 -0
  84. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/parallel_plugin/worker_api.py +0 -0
  85. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/parallel_plugin/worker_filter.py +0 -0
  86. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/utils/__init__.py +0 -0
  87. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/utils/docker_compose_files_path.py +0 -0
  88. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/utils/docker_compose_service_deps.py +0 -0
  89. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/utils/services_construction.py +0 -0
  90. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/vedro_plugin/base_structures/__init__.py +0 -0
  91. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/vedro_plugin/helpers/__init__.py +0 -0
  92. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/vedro_plugin/helpers/scenario_ordering.py +0 -0
  93. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/vedro_plugin/helpers/scenario_tag_processing.py +0 -0
  94. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/vedro_plugin/helpers/test_env_vars_setter.py +0 -0
  95. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/vedro_plugin/plugin.py +0 -0
  96. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose/version.py +0 -0
  97. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/uber_compose.egg-info/dependency_links.txt +0 -0
  98. {uber_compose-3.0.0a25 → uber_compose-3.2.0}/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.0.0a25
3
+ Version: 3.2.0
4
4
  Summary: docker compose testing env orchestrator
5
5
  Home-page: https://github.com/ko10ok/uber-compose
6
6
  Author: Yuriy Sagitov
@@ -16,6 +16,8 @@ Requires-Python: >=3.10.0
16
16
  Description-Content-Type: text/markdown
17
17
  License-File: LICENSE
18
18
  Requires-Dist: vedro<2.0,>=1.15
19
+ Requires-Dist: cabina<2.0,>=1.1.2
20
+ Requires-Dist: niltype<2.0,>=1.0.2
19
21
  Requires-Dist: PyYAML<6.1,>=6.0.1
20
22
  Requires-Dist: rtry<2.0,>=1.4.0
21
23
  Requires-Dist: rich<16.0,>=11.0
@@ -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
@@ -511,6 +511,39 @@ cassandra:
511
511
  host: "[[cassandra]]"
512
512
  ```
513
513
 
514
+ ## Live config values
515
+
516
+ Config values are resolved once, at import time — before the current env is
517
+ known. `live_env` (based on Cabina's `LazyEnvironment` / `FutureValue`) resolves
518
+ them on every access instead:
519
+
520
+ ```python
521
+ import cabina
522
+
523
+ from uber_compose import live_env
524
+
525
+
526
+ class Config(cabina.Config, cabina.Section):
527
+ class Database(cabina.Section):
528
+ dsn: str = live_env.literal("postgres://db-[[namespace]]:5432/app")
529
+
530
+ class Api(cabina.Section):
531
+ url: str = live_env.raw("API_URL")
532
+ port: int = live_env.int("API_PORT")
533
+ ```
534
+
535
+ Values are read through the sections, e.g. `Config.Api.port`.
536
+
537
+ - `raw` / `str` / `int` and other Cabina accessors read an env var;
538
+ - `literal` substitutes placeholders in an explicit value;
539
+ - placeholders are taken from the current env context (env id, namespace, worker
540
+ id, run id, service names) on every read, without caching.
541
+
542
+ Supported placeholders are the same as for `Service.env`: `[[env_id]]`,
543
+ `[[namespace]]`, `[[worker_id]]`, `[[worker_id_alpha_numeric]]`,
544
+ `[[namespace_alpha_numeric]]`, `[[worker_id_alpha_numeric_6]]`,
545
+ `[[namespace_alpha_numeric_6]]`, `[[test_run_id]]`, and `[[<service>]]`.
546
+
514
547
  ## Reporting details
515
548
 
516
549
  Workers emit JSON events that the parent turns back into regular vedro events,
@@ -1,4 +1,6 @@
1
1
  vedro>=1.15,<2.0
2
+ cabina>=1.1.2,<2.0
3
+ niltype>=1.0.2,<2.0
2
4
  PyYAML>=6.0.1,<6.1
3
5
  rtry>=1.4.0,<2.0
4
6
  rich>=11.0,<16.0
@@ -17,8 +17,12 @@ 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
23
+ from uber_compose.helpers.live_env import LiveEnvironment
24
+ from uber_compose.helpers.live_env import LiveValue
25
+ from uber_compose.helpers.live_env import live_env
22
26
  from uber_compose.output.console import LogEvents
23
27
  from uber_compose.output.console import LogPolicy
24
28
  from uber_compose.output.console import LogPolicySet
@@ -53,7 +57,7 @@ __all__ = (
53
57
  'TheUberCompose', 'SystemUberCompose',
54
58
  'Environment', 'Service', 'Env', 'OverridenService',
55
59
  'CommonJsonCli', 'CommandResult', 'ProcessExit', 'JsonParser', 'json_parser', 'ExecTimeout', 'TimeOutCheck',
56
- 'ExecLifeCyclePolicy', 'ExecResult',
60
+ 'ExecLifeCyclePolicy', 'ExecResult', 'TerminatedByCondition',
57
61
  'ExecStrategy', 'ExecContext', 'PidofExecStrategy', 'StatusFileExecStrategy',
58
62
  'VedroUberCompose', 'UpHealthPolicy', 'DEFAULT_COMPOSE', 'ComposeConfig', 'DEFAULT_ENV_DESCRIPTION',
59
63
  'LogEvents', 'LogPolicy', 'LogPolicySet',
@@ -63,4 +67,5 @@ __all__ = (
63
67
  'get_run_depth', 'is_child_project',
64
68
  'is_parallel_worker', 'is_parallel_worker_process', 'reset_execution_plan', 'set_execution_plan',
65
69
  'VedroUberComposeParallel', 'build_execution_plan', 'build_execution_plan_from_scheduler',
70
+ 'LiveEnvironment', 'LiveValue', 'live_env',
66
71
  )
@@ -30,9 +30,13 @@ def cleanup_log_files(log_file_path: str | Path, limit: int,
30
30
  file.unlink(missing_ok=True)
31
31
 
32
32
 
33
+ DEFAULT_DOCKER_COMPOSE_FILES_AUTO_SCAN_PATTERN = r'(?:.*/)?docker-compose[^/]*\.(yaml|yml)$'
34
+
35
+
33
36
  class Constants:
34
37
  def __init__(self,
35
38
  docker_compose_files_scan_depth: int = 2,
39
+ docker_compose_files_auto_scan_pattern: str = DEFAULT_DOCKER_COMPOSE_FILES_AUTO_SCAN_PATTERN,
36
40
  cli_compose_util_override: str = None,
37
41
  compose_project_name: str = None,
38
42
  tmp_envs_path: str | Path = None,
@@ -103,6 +107,10 @@ class Constants:
103
107
  self.docker_compose_files_scan_depth: int = int(
104
108
  os.environ.get('DOCKER_COMPOSE_FILES_SCAN_DEPTH', docker_compose_files_scan_depth)
105
109
  )
110
+ self.docker_compose_files_auto_scan_pattern: str = os.environ.get(
111
+ 'DOCKER_COMPOSE_FILES_AUTO_SCAN_PATTERN',
112
+ docker_compose_files_auto_scan_pattern,
113
+ )
106
114
 
107
115
  self.ignore_pidof_unexistance: bool = bool(os.environ.get('IGNORE_PIDOF_UNEXISTANCE', 'True') == 'True')
108
116
 
@@ -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
  )
@@ -25,7 +25,11 @@ class SystemDockerCompose:
25
25
 
26
26
  # TODO get path from Constants. Could be used in cases dc yaml not in root directory
27
27
  self.default_compose_files = ':'.join(
28
- scan_for_compose_files(inner_project_root, self.cfg_constants.docker_compose_files_scan_depth)
28
+ scan_for_compose_files(
29
+ inner_project_root,
30
+ self.cfg_constants.docker_compose_files_scan_depth,
31
+ self.cfg_constants.docker_compose_files_auto_scan_pattern,
32
+ )
29
33
  )
30
34
  self.logger.commands(f'All found compose files: {self.default_compose_files}')
31
35
  assert self.default_compose_files, (
@@ -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')')
@@ -0,0 +1,93 @@
1
+ """Cabina-based live environment values resolved for the current uber-compose env."""
2
+
3
+ from typing import Any
4
+ from typing import Callable
5
+
6
+ from cabina import FutureValue
7
+ from cabina import LazyEnvironment
8
+ from cabina.parsers import parse_as_is
9
+ from niltype import Nil
10
+
11
+ from uber_compose.core.sequence_run_types import DEFAULT_ENV_ID
12
+ from uber_compose.env_description.env_types import ServiceMode
13
+ from uber_compose.helpers.current_env import get_current_env_context
14
+ from uber_compose.helpers.parameterization import build_parameterization_placeholders
15
+ from uber_compose.helpers.parameterization import substitute_parameterization_placeholders
16
+
17
+
18
+ def current_environment_placeholders() -> dict[str, str]:
19
+ """Build parameterization placeholders for the environment of the current thread."""
20
+ context = get_current_env_context()
21
+ namespace = context.namespace or context.env_id
22
+
23
+ services_map = {}
24
+ if context.env is not None:
25
+ for service_name, service in context.env.get_services().items():
26
+ if service.mode == ServiceMode.OFF:
27
+ continue
28
+ if service.mode == ServiceMode.SINGLETON or namespace == DEFAULT_ENV_ID:
29
+ services_map[service_name] = service_name
30
+ else:
31
+ services_map[service_name] = f'{service_name}-{namespace}'
32
+
33
+ return build_parameterization_placeholders(
34
+ env_id=context.env_id,
35
+ services_map=services_map,
36
+ run_id=context.run_id,
37
+ worker_id=context.worker_id,
38
+ namespace=namespace,
39
+ )
40
+
41
+
42
+ def resolve_current_placeholders(value: Any) -> Any:
43
+ """Replace ``[[...]]`` placeholders in a value using the current environment context."""
44
+ if not isinstance(value, str):
45
+ return value
46
+ return substitute_parameterization_placeholders(value, current_environment_placeholders())
47
+
48
+
49
+ class LiveValue(FutureValue):
50
+ """A future value that is resolved on every access instead of being cached."""
51
+
52
+ def get(self) -> Any:
53
+ return self._accessor(*self._args, **self._kwargs)
54
+
55
+
56
+ class LiveEnvironment(LazyEnvironment):
57
+ """Environment accessor whose values are re-read and re-substituted on every access."""
58
+
59
+ def get(
60
+ self,
61
+ name: str,
62
+ default: Any = Nil,
63
+ parser: Callable[[str], Any] = parse_as_is,
64
+ ) -> Any:
65
+ raw_name = f'{self._prefix}{name}'
66
+ if raw_name in self._environ:
67
+ value = self._environ[raw_name]
68
+ return parser(resolve_current_placeholders(value))
69
+
70
+ if default is Nil:
71
+ return super().get(name, default, parser)
72
+ return resolve_current_placeholders(default)
73
+
74
+ def raw(
75
+ self,
76
+ name: str,
77
+ default: Any = Nil,
78
+ parser: Callable[[str], Any] = parse_as_is,
79
+ ) -> LiveValue:
80
+ return LiveValue(self.get, name, default=default, parser=parser)
81
+
82
+ def literal(self, value: Any) -> LiveValue:
83
+ """Return a live value with placeholders substituted from the current environment."""
84
+ return LiveValue(resolve_current_placeholders, value)
85
+
86
+
87
+ live_env = LiveEnvironment()
88
+
89
+
90
+ __all__ = (
91
+ 'LiveEnvironment', 'LiveValue', 'current_environment_placeholders', 'live_env',
92
+ 'resolve_current_placeholders',
93
+ )
@@ -19,6 +19,7 @@ from uber_compose.core.docker_compose_shell.types import ExecLifeCyclePolicy
19
19
  from uber_compose.core.docker_compose_shell.types import ServicesComposeState
20
20
  from uber_compose.core.sequence_run_types import DEFAULT_ENV_ID
21
21
  from uber_compose.core.system_docker_compose import SystemDockerCompose
22
+ from uber_compose.core.utils.compose_files import get_compose_services
22
23
  from uber_compose.core.utils.compose_instance_cfg import get_new_env_id
23
24
  from uber_compose.core.utils.compose_instance_cfg import get_stable_env_id
24
25
  from uber_compose.core.utils.state_waiting import is_service_not_running_or_not_healthy
@@ -27,6 +28,7 @@ from uber_compose.env_description.env_types import Environment
27
28
  from uber_compose.env_description.env_types import OverridenService
28
29
  from uber_compose.env_description.env_types import ServiceMode
29
30
  from uber_compose.errors.mounted_files import MountedFileNotFoundError
31
+ from uber_compose.errors.up import ServicesUpError
30
32
  from uber_compose.errors.up import SingletonConfigChangedError
31
33
  from uber_compose.helpers.broken_services import calc_broken_services
32
34
  from uber_compose.helpers.bytes_pickle import base64_pickled
@@ -223,6 +225,17 @@ class SystemUberCompose:
223
225
  config_template = self._resolve_config_template(config_template, compose_files, services_override)
224
226
 
225
227
  requested_env_id = env_id if parallelism_limit > 1 else None
228
+
229
+ if not config_template.get_services():
230
+ self.logger.stage(Text(
231
+ 'Environment has no services. Nothing to start.', style=Style.suspicious
232
+ ))
233
+ return ReadyEnv(
234
+ requested_env_id or DEFAULT_ENV_ID,
235
+ config_template,
236
+ release_id or self.last_release_id or str(uuid4()),
237
+ )
238
+
226
239
  services_state = await self._get_current_state(config_template, compose_files)
227
240
  if requested_env_id is not None:
228
241
  services_state = services_state.get_all_for(
@@ -242,6 +255,8 @@ class SystemUberCompose:
242
255
  await self._hooks.run(UberComposeEvent.AFTER_UP)
243
256
  return reusable_env
244
257
 
258
+ self._validate_env_services_against_compose_files(config_template, compose_files)
259
+
245
260
  self._log_inflight_and_restart_info(services_state, force_restart)
246
261
 
247
262
  _for = f' {config_template.description}' if config_template.description else ''
@@ -380,6 +395,34 @@ class SystemUberCompose:
380
395
 
381
396
  return config_template
382
397
 
398
+ def _validate_env_services_against_compose_files(
399
+ self,
400
+ config_template: Environment,
401
+ compose_files: str,
402
+ ) -> None:
403
+ compose_services = set(get_compose_services(
404
+ get_absolute_compose_files(
405
+ compose_files,
406
+ self.cfg_constants.in_docker_project_root_path,
407
+ )
408
+ ))
409
+ ignored_services = set(config_template.get_overridden_services_names())
410
+ ignored_services |= {
411
+ service_name
412
+ for service_name, service in config_template.get_services().items()
413
+ if service.mode == ServiceMode.OFF
414
+ }
415
+
416
+ missing_services = sorted(
417
+ set(config_template.get_services_names()) - compose_services - ignored_services
418
+ )
419
+ if missing_services:
420
+ raise ServicesUpError(
421
+ f'Environment declares services missing in docker-compose files {compose_files!r}: '
422
+ f'{missing_services}. '
423
+ f'Define them in compose files, override them, or remove them from the environment.'
424
+ )
425
+
383
426
  async def _get_current_state(self, config_template: Environment, compose_files: str) -> ServicesComposeState:
384
427
  self.logger.stage_debug(
385
428
  f'Searching for environment {config_template} with template: {base64_pickled(config_template)}'
@@ -0,0 +1,25 @@
1
+ import os
2
+ from pathlib import Path
3
+ import re
4
+
5
+ from uber_compose.core.constants import DEFAULT_DOCKER_COMPOSE_FILES_AUTO_SCAN_PATTERN
6
+ from uber_compose.core.utils.compose_files import read_dc_file
7
+
8
+
9
+ def scan_for_compose_files(
10
+ path: Path,
11
+ dc_files_scan_depth: int = 1,
12
+ files_pattern: str = DEFAULT_DOCKER_COMPOSE_FILES_AUTO_SCAN_PATTERN,
13
+ ) -> list[str]:
14
+ # TODO exclude paths with ENV
15
+ compose_files = []
16
+ for root, dirs, files in os.walk(path):
17
+ if root.startswith(str(path)) and root.count('/') - str(path).count('/') < dc_files_scan_depth:
18
+ for file in files:
19
+ relative_path = str(Path(root) / file)[len(str(path)) + 1:]
20
+ if not re.fullmatch(files_pattern, relative_path):
21
+ continue
22
+ dc_file = read_dc_file(Path(root) / file)
23
+ if 'services' in dc_file:
24
+ compose_files.append(relative_path)
25
+ return list(sorted(compose_files))
@@ -1,9 +1,7 @@
1
1
  """
2
- This module used for the vedro plugin integration for Maxwell Demon
2
+ Vedro plugin integration for uber-compose.
3
3
 
4
4
  Enabled plugin (in vedro.cfg) catches stage before tests run (StartupEvent) and before each test run (ScenarioRunEvent).
5
5
 
6
6
  On each stage it starts testing environment required by selected tests.
7
-
8
- Plugin communicate with maxwelld service container via http client - maxwelld/client
9
7
  """
@@ -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.0.0a25
3
+ Version: 3.2.0
4
4
  Summary: docker compose testing env orchestrator
5
5
  Home-page: https://github.com/ko10ok/uber-compose
6
6
  Author: Yuriy Sagitov
@@ -16,6 +16,8 @@ Requires-Python: >=3.10.0
16
16
  Description-Content-Type: text/markdown
17
17
  License-File: LICENSE
18
18
  Requires-Dist: vedro<2.0,>=1.15
19
+ Requires-Dist: cabina<2.0,>=1.1.2
20
+ Requires-Dist: niltype<2.0,>=1.0.2
19
21
  Requires-Dist: PyYAML<6.1,>=6.0.1
20
22
  Requires-Dist: rtry<2.0,>=1.4.0
21
23
  Requires-Dist: rich<16.0,>=11.0
@@ -61,6 +61,7 @@ uber_compose/helpers/health_policy.py
61
61
  uber_compose/helpers/hooks.py
62
62
  uber_compose/helpers/jobs_result.py
63
63
  uber_compose/helpers/labels.py
64
+ uber_compose/helpers/live_env.py
64
65
  uber_compose/helpers/parameterization.py
65
66
  uber_compose/helpers/singleton.py
66
67
  uber_compose/helpers/state_keeper.py
@@ -1,4 +1,6 @@
1
1
  vedro<2.0,>=1.15
2
+ cabina<2.0,>=1.1.2
3
+ niltype<2.0,>=1.0.2
2
4
  PyYAML<6.1,>=6.0.1
3
5
  rtry<2.0,>=1.4.0
4
6
  rich<16.0,>=11.0
@@ -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,17 +0,0 @@
1
- import os
2
- from pathlib import Path
3
-
4
- from uber_compose.core.utils.compose_files import read_dc_file
5
-
6
-
7
- def scan_for_compose_files(path: Path, dc_files_scan_depth: int = 1) -> list[str]:
8
- # TODO exclude paths with ENV
9
- compose_files = []
10
- for root, dirs, files in os.walk(path):
11
- if root.startswith(str(path)) and root.count('/') - str(path).count('/') < dc_files_scan_depth:
12
- for file in files:
13
- if file.endswith('.yml') or file.endswith('.yaml'):
14
- dc_file = read_dc_file(Path(root) / file)
15
- if 'services' in dc_file:
16
- compose_files.append(str(Path(root) / file)[len(str(path)) + 1:])
17
- return list(sorted(compose_files))
@@ -1 +0,0 @@
1
- 3.0.0
File without changes
File without changes
File without changes
File without changes