pg-maker 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. pg_maker/__init__.py +3 -0
  2. pg_maker/__main__.py +3 -0
  3. pg_maker/api.py +594 -0
  4. pg_maker/artifacts/__init__.py +4 -0
  5. pg_maker/artifacts/catalog.py +67 -0
  6. pg_maker/artifacts/manifest.py +301 -0
  7. pg_maker/assets.py +93 -0
  8. pg_maker/builders/__init__.py +4 -0
  9. pg_maker/builders/autotools.py +430 -0
  10. pg_maker/builders/components.py +359 -0
  11. pg_maker/bundled/PROJECT.md +57 -0
  12. pg_maker/bundled/build.yaml +29 -0
  13. pg_maker/bundled/components/pg-stat-kcache.yaml +30 -0
  14. pg_maker/bundled/components/pg-stat-statements.yaml +24 -0
  15. pg_maker/bundled/components/pg-wait-sampling.yaml +30 -0
  16. pg_maker/bundled/config/defaults.yaml +80 -0
  17. pg_maker/bundled/config/documentation.yaml +24 -0
  18. pg_maker/bundled/config/features/my-feature.yaml +17 -0
  19. pg_maker/bundled/config/vendor.yaml +13 -0
  20. pg_maker/bundled/documentation/README.md +20 -0
  21. pg_maker/bundled/documentation/pg-stat-kcache.sgml +99 -0
  22. pg_maker/bundled/documentation/pg-stat-kcache.yaml +15 -0
  23. pg_maker/bundled/documentation/pg-wait-sampling.sgml +122 -0
  24. pg_maker/bundled/documentation/pg-wait-sampling.yaml +15 -0
  25. pg_maker/bundled/patches/unix-socket-directory.patch +5 -0
  26. pg_maker/changes/__init__.py +1 -0
  27. pg_maker/changes/apply.py +298 -0
  28. pg_maker/changes/loader.py +135 -0
  29. pg_maker/changes/workspace.py +221 -0
  30. pg_maker/cli.py +546 -0
  31. pg_maker/components/__init__.py +4 -0
  32. pg_maker/config.py +514 -0
  33. pg_maker/development/__init__.py +1 -0
  34. pg_maker/development/cli.py +104 -0
  35. pg_maker/development/git.py +362 -0
  36. pg_maker/development/session.py +735 -0
  37. pg_maker/documentation/__init__.py +4 -0
  38. pg_maker/documentation/builder.py +467 -0
  39. pg_maker/documentation/cli.py +24 -0
  40. pg_maker/documentation/config.py +127 -0
  41. pg_maker/documentation/install.py +79 -0
  42. pg_maker/documentation/site.py +166 -0
  43. pg_maker/documentation/sphinx_ext.py +150 -0
  44. pg_maker/documentation/theme/_static/pg-maker.css +26 -0
  45. pg_maker/documentation/theme/_static/pg-maker.js +35 -0
  46. pg_maker/documentation/theme/_templates/footer_en.html +5 -0
  47. pg_maker/documentation/theme/_templates/footer_metadata.html +13 -0
  48. pg_maker/documentation/theme/_templates/footer_ru.html +5 -0
  49. pg_maker/documentation/translation.py +341 -0
  50. pg_maker/documentation/validation.py +132 -0
  51. pg_maker/documentation/worker.py +62 -0
  52. pg_maker/documentation/writer.py +324 -0
  53. pg_maker/documentation/xml.py +210 -0
  54. pg_maker/documents.py +118 -0
  55. pg_maker/errors.py +50 -0
  56. pg_maker/execution/__init__.py +1 -0
  57. pg_maker/execution/build.py +502 -0
  58. pg_maker/execution/cache.py +287 -0
  59. pg_maker/execution/cancellation.py +60 -0
  60. pg_maker/execution/checkpoints.py +218 -0
  61. pg_maker/execution/cleanup.py +122 -0
  62. pg_maker/execution/component_cache.py +164 -0
  63. pg_maker/execution/development.py +109 -0
  64. pg_maker/execution/engine.py +171 -0
  65. pg_maker/execution/events.py +65 -0
  66. pg_maker/execution/incremental.py +178 -0
  67. pg_maker/execution/preparation.py +130 -0
  68. pg_maker/execution/process.py +155 -0
  69. pg_maker/execution/resources.py +41 -0
  70. pg_maker/execution/state.py +82 -0
  71. pg_maker/execution/worker.py +45 -0
  72. pg_maker/identity.py +116 -0
  73. pg_maker/integrations/__init__.py +1 -0
  74. pg_maker/integrations/machine.py +163 -0
  75. pg_maker/integrations/runtime.py +387 -0
  76. pg_maker/models.py +245 -0
  77. pg_maker/packaging/__init__.py +4 -0
  78. pg_maker/packaging/deb.py +337 -0
  79. pg_maker/packaging/service.py +165 -0
  80. pg_maker/packaging/spec.py +64 -0
  81. pg_maker/packaging/templates/deb-control.in +8 -0
  82. pg_maker/packaging/tree.py +239 -0
  83. pg_maker/planning/__init__.py +1 -0
  84. pg_maker/planning/documents.py +65 -0
  85. pg_maker/planning/environments.py +318 -0
  86. pg_maker/planning/graph.py +23 -0
  87. pg_maker/planning/plan.py +418 -0
  88. pg_maker/planning/resolve.py +117 -0
  89. pg_maker/planning/reuse.py +80 -0
  90. pg_maker/planning/runtime_repository.py +90 -0
  91. pg_maker/postgresql.py +59 -0
  92. pg_maker/progress.py +64 -0
  93. pg_maker/publishing/__init__.py +4 -0
  94. pg_maker/py.typed +0 -0
  95. pg_maker/recipes/README.md +13 -0
  96. pg_maker/recipes/platforms/debian-13.yaml +125 -0
  97. pg_maker/recipes/postgresql.yaml +114 -0
  98. pg_maker/runners/__init__.py +1 -0
  99. pg_maker/runners/base.py +29 -0
  100. pg_maker/runners/docker.py +312 -0
  101. pg_maker/schemas/build.schema.json +5 -0
  102. pg_maker/schemas/change-set.schema.json +5 -0
  103. pg_maker/schemas/component-envelope.schema.json +69 -0
  104. pg_maker/schemas/component.schema.json +5 -0
  105. pg_maker/schemas/defaults.schema.json +5 -0
  106. pg_maker/schemas/doc-rules.schema.json +5 -0
  107. pg_maker/schemas/documentation.schema.json +5 -0
  108. pg_maker/schemas/environment.schema.json +228 -0
  109. pg_maker/schemas/feature.schema.json +5 -0
  110. pg_maker/schemas/insertions.schema.json +5 -0
  111. pg_maker/schemas/lock.schema.json +3963 -0
  112. pg_maker/schemas/operation-input.schema.json +306 -0
  113. pg_maker/schemas/operation-state.schema.json +127 -0
  114. pg_maker/schemas/plan.schema.json +284 -0
  115. pg_maker/schemas/planning-common.schema.json +8192 -0
  116. pg_maker/schemas/platform.schema.json +5 -0
  117. pg_maker/schemas/postgresql-catalog.schema.json +5 -0
  118. pg_maker/schemas/run-event.schema.json +72 -0
  119. pg_maker/schemas/translations.schema.json +5 -0
  120. pg_maker/schemas/vendor.schema.json +5 -0
  121. pg_maker/security.py +73 -0
  122. pg_maker/sources/__init__.py +1 -0
  123. pg_maker/sources/resolver.py +238 -0
  124. pg_maker/sources/store.py +279 -0
  125. pg_maker/storage.py +127 -0
  126. pg_maker/validation/__init__.py +4 -0
  127. pg_maker/validation/installed.py +667 -0
  128. pg_maker/validation/packages.py +309 -0
  129. pg_maker/validation/systemctl.py +185 -0
  130. pg_maker/yamlio.py +54 -0
  131. pg_maker-0.1.0.data/data/share/doc/pg-maker/CHANGELOG.md +22 -0
  132. pg_maker-0.1.0.data/data/share/doc/pg-maker/CONTRIBUTING.md +63 -0
  133. pg_maker-0.1.0.data/data/share/doc/pg-maker/LICENSE +21 -0
  134. pg_maker-0.1.0.data/data/share/doc/pg-maker/README.md +163 -0
  135. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/architecture.md +55 -0
  136. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/development-storage.md +72 -0
  137. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/development.md +86 -0
  138. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/README.md +32 -0
  139. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/api.md +75 -0
  140. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/build.md +112 -0
  141. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/changes.md +58 -0
  142. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/cleanup.md +17 -0
  143. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/components.md +39 -0
  144. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/configuration.md +83 -0
  145. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/development.md +88 -0
  146. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/documentation.md +241 -0
  147. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/documents.md +42 -0
  148. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/environments.md +40 -0
  149. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/execution.md +49 -0
  150. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/machine.md +31 -0
  151. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/observability.md +28 -0
  152. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/packaging.md +107 -0
  153. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/planning.md +63 -0
  154. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/postgresql.md +79 -0
  155. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/publication.md +20 -0
  156. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/recovery.md +83 -0
  157. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/runtime.md +31 -0
  158. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/sources.md +48 -0
  159. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/state.md +49 -0
  160. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/interfaces/storage.md +24 -0
  161. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/releasing.md +98 -0
  162. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/reuse.md +24 -0
  163. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/roadmap.md +54 -0
  164. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/validation/default-components.md +56 -0
  165. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/validation/development-release.md +49 -0
  166. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/validation/documentation-theme.md +45 -0
  167. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/validation/integration.md +49 -0
  168. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/validation/postgresql-majors.md +107 -0
  169. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/validation/review-fixes.md +68 -0
  170. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/validation/stage4.md +65 -0
  171. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/validation/stage56.md +66 -0
  172. pg_maker-0.1.0.data/data/share/doc/pg-maker/docs/validation/stage7.md +72 -0
  173. pg_maker-0.1.0.data/data/share/doc/pg-maker/tests/fixtures/guc/README.md +11 -0
  174. pg_maker-0.1.0.data/data/share/doc/pg-maker/tests/fixtures/stage4/README.md +31 -0
  175. pg_maker-0.1.0.data/data/share/doc/pg-maker/tests/fixtures/stage7/README.md +16 -0
  176. pg_maker-0.1.0.dist-info/METADATA +200 -0
  177. pg_maker-0.1.0.dist-info/RECORD +181 -0
  178. pg_maker-0.1.0.dist-info/WHEEL +5 -0
  179. pg_maker-0.1.0.dist-info/entry_points.txt +4 -0
  180. pg_maker-0.1.0.dist-info/licenses/LICENSE +21 -0
  181. pg_maker-0.1.0.dist-info/top_level.txt +1 -0
pg_maker/cli.py ADDED
@@ -0,0 +1,546 @@
1
+ """Thin argparse adapter. Machine stdout contains exactly one JSON document."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import io
7
+ import json
8
+ import sys
9
+ from contextlib import redirect_stdout
10
+ from pathlib import Path
11
+
12
+ from pg_maker import __version__
13
+ from pg_maker.api import MakerService
14
+ from pg_maker.assets import initialize_project
15
+ from pg_maker.errors import MakerError, ValidationError
16
+ from pg_maker.integrations.machine import EXIT_CODES, capabilities, envelope
17
+ from pg_maker.models import CommandSpec, EnvironmentSpec, OperationRequest
18
+ from pg_maker.runners.docker import current_user
19
+ from pg_maker.security import redact
20
+ from pg_maker.storage import canonical_json, read_json, write_json
21
+
22
+
23
+ class Parser(argparse.ArgumentParser):
24
+ def error(self, message: str) -> None:
25
+ raise ValidationError(message)
26
+
27
+
28
+ def parser() -> Parser:
29
+ root = Parser(prog="pg-maker", description="PostgreSQL distribution configuration and planning")
30
+ root.add_argument("--version", action="version", version=f"pg-maker {__version__}")
31
+ sub = root.add_subparsers(dest="command", required=True)
32
+ from pg_maker.development.cli import add_commands
33
+
34
+ add_commands(sub)
35
+ init = sub.add_parser("init", help="create editable YAML configuration and document schemas")
36
+ init.add_argument("directory", type=Path)
37
+ init_docs = init.add_mutually_exclusive_group()
38
+ init_docs.add_argument("--with-doc", dest="with_doc", action="store_true", default=None)
39
+ init_docs.add_argument("--without-doc", dest="with_doc", action="store_false")
40
+ init.add_argument("--doc-language", action="append", dest="doc_languages")
41
+ init.add_argument("--feature", action="append", dest="features")
42
+ init.add_argument("--build-mode", choices=["release", "debug"])
43
+ sub.add_parser("doctor", help="check the current Docker daemon")
44
+ runner = sub.add_parser("runner", help="container executor checks")
45
+ checks = runner.add_subparsers(dest="runner_command", required=True)
46
+ check = checks.add_parser("check", help="run uname/id in an isolated pinned image")
47
+ check.add_argument("--image", required=True, help="local sha256 image ID or repository@sha256")
48
+ check.add_argument("--out", type=Path, default=Path("operations"))
49
+ check.add_argument("--operation-id")
50
+ check.add_argument("--detach", action="store_true")
51
+
52
+ def config_args(command):
53
+ command.add_argument("manifest", type=Path)
54
+ command.add_argument("--config-dir", type=Path)
55
+ command.add_argument("--feature", action="append", dest="features")
56
+ command.add_argument("--build-mode", choices=["release", "debug"])
57
+ docs = command.add_mutually_exclusive_group()
58
+ docs.add_argument("--with-doc", dest="with_doc", action="store_true", default=None)
59
+ docs.add_argument("--without-doc", dest="with_doc", action="store_false")
60
+ command.add_argument("--doc-language", action="append", dest="doc_languages")
61
+
62
+ config = sub.add_parser("config").add_subparsers(dest="config_command", required=True)
63
+ show = config.add_parser("show")
64
+ config_args(show)
65
+ show.add_argument(
66
+ "--resolved", action="store_true", help="show effective values and provenance"
67
+ )
68
+ config_args(sub.add_parser("validate"))
69
+ config_args(sub.add_parser("features"))
70
+ names = sub.add_parser("package").add_subparsers(dest="package_command", required=True)
71
+ config_args(names.add_parser("names"))
72
+ sub.add_parser("platforms", help="list installed platform recipes")
73
+ env = sub.add_parser("env").add_subparsers(dest="env_command", required=True)
74
+ for command in (env.add_parser("prepare"), sub.add_parser("resolve")):
75
+ config_args(command)
76
+ command.add_argument("--out", required=True, type=Path)
77
+ command.add_argument("--operations", type=Path, default=Path("operations"))
78
+ command.add_argument("--input-store", type=Path, default=Path("inputs"))
79
+ command.add_argument("--operation-id")
80
+ command.add_argument("--detach", action="store_true")
81
+ command.add_argument("--offline", action="store_true")
82
+ if command.prog.endswith("resolve"):
83
+ command.add_argument("--environments", type=Path, required=True)
84
+ plan = sub.add_parser("plan", help="produce a read-only build DAG from fixed inputs")
85
+ plan.add_argument("lock", type=Path)
86
+ plan.add_argument("--out", type=Path)
87
+ plan.add_argument("--input-store", type=Path)
88
+ plan.add_argument(
89
+ "--goal",
90
+ choices=[
91
+ "source",
92
+ "build",
93
+ "package",
94
+ "docs",
95
+ "translations",
96
+ "doc-source",
97
+ "translated-docs",
98
+ "verified",
99
+ ],
100
+ default="build",
101
+ )
102
+ build = sub.add_parser("build", help="execute a locked source or build graph")
103
+ build.add_argument("lock", type=Path)
104
+ build.add_argument(
105
+ "--goal",
106
+ choices=[
107
+ "source",
108
+ "build",
109
+ "package",
110
+ "docs",
111
+ "translations",
112
+ "doc-source",
113
+ "translated-docs",
114
+ "verified",
115
+ ],
116
+ default=None,
117
+ )
118
+ build.add_argument("--plan", type=Path)
119
+ build.add_argument("--plan-hash")
120
+ build.add_argument("--input-store", type=Path)
121
+ build.add_argument("--operations", type=Path, default=Path("operations"))
122
+ build.add_argument("--operation-id")
123
+ build.add_argument("--detach", action="store_true")
124
+ build.add_argument("--cache-store", type=Path)
125
+ build.add_argument("--no-cache", action="store_true")
126
+ build_docs = build.add_mutually_exclusive_group()
127
+ build_docs.add_argument("--with-doc", dest="with_doc", action="store_true", default=None)
128
+ build_docs.add_argument("--without-doc", dest="with_doc", action="store_false")
129
+ build.add_argument("--doc-language", action="append", dest="doc_languages")
130
+ build.add_argument("--feature", action="append", dest="features")
131
+ build.add_argument("--build-mode", choices=["release", "debug"])
132
+ docs = sub.add_parser("docs", help="containerized documentation tools")
133
+ docs_commands = docs.add_subparsers(dest="docs_command", required=True)
134
+ for name, goal in (
135
+ ("build", "docs"),
136
+ ("write", "doc-source"),
137
+ ("prepare-translations", "translations"),
138
+ ("apply-translations", "translated-docs"),
139
+ ):
140
+ command = docs_commands.add_parser(name)
141
+ command.set_defaults(goal=goal, run_db_tests=False, cache_store=None, no_cache=True)
142
+ command.add_argument("lock", type=Path)
143
+ command.add_argument("--plan", type=Path)
144
+ command.add_argument("--plan-hash")
145
+ command.add_argument("--input-store", type=Path)
146
+ command.add_argument("--operations", type=Path, default=Path("operations"))
147
+ command.add_argument("--operation-id")
148
+ command.add_argument("--detach", action="store_true")
149
+ resume = sub.add_parser("resume", help="resume a failed operation with verified checkpoints")
150
+ resume.add_argument("directory", type=Path)
151
+ resume.add_argument("--plan-hash")
152
+ resume.add_argument("--input-hash")
153
+ resume.add_argument("--detach", action="store_true")
154
+ export = sub.add_parser("export", help="copy portable artifacts, reports and logs")
155
+ export.add_argument("directory", type=Path)
156
+ export.add_argument("--out", required=True, type=Path)
157
+ export.add_argument("--include-inputs", action="store_true")
158
+ cleanup = sub.add_parser(
159
+ "cleanup", help="Preview or apply private scratch removal after export"
160
+ )
161
+ cleanup.add_argument("directory", type=Path)
162
+ cleanup.add_argument("--export", dest="exported", type=Path)
163
+ cleanup.add_argument("--apply", type=Path)
164
+ cleanup.add_argument("--out", type=Path)
165
+ changes = sub.add_parser(
166
+ "changes", help="Create private agent workspaces and export ChangeSets"
167
+ )
168
+ changes_commands = changes.add_subparsers(dest="changes_command", required=True)
169
+ change_workspace = changes_commands.add_parser("workspace")
170
+ change_workspace.add_argument("directory", type=Path)
171
+ change_workspace.add_argument("--input-store", type=Path, required=True)
172
+ change_workspace.add_argument("--source-hash", required=True)
173
+ change_workspace.add_argument("--lock", type=Path)
174
+ change_workspace.add_argument("--feature")
175
+ change_workspace.add_argument("--until")
176
+ change_export = changes_commands.add_parser("export")
177
+ change_export.add_argument("directory", type=Path)
178
+ change_export.add_argument("--out", type=Path, required=True)
179
+ change_export.add_argument("--id", required=True)
180
+ change_export.add_argument("--postgresql", required=True)
181
+ changes_commands.add_parser("validate").add_argument("file", type=Path)
182
+ runtime = sub.add_parser("runtime", help="Create a pg_stand image from locked DEBs")
183
+ runtime_commands = runtime.add_subparsers(dest="runtime_command", required=True)
184
+ runtime_plan = runtime_commands.add_parser("plan")
185
+ runtime_plan.add_argument("directory", type=Path)
186
+ runtime_plan.add_argument("--profile", type=Path, required=True)
187
+ runtime_plan.add_argument("--out", type=Path)
188
+ runtime_build = runtime_commands.add_parser("build")
189
+ runtime_build.add_argument("plan", type=Path)
190
+ runtime_build.add_argument("--plan-hash", required=True)
191
+ runtime_build.add_argument("--out", type=Path, required=True)
192
+ runtime_build.add_argument("--operations", type=Path, default=Path("operations"))
193
+ runtime_build.add_argument("--operation-id")
194
+ runtime_build.add_argument("--detach", action="store_true")
195
+ cache = sub.add_parser("cache").add_subparsers(dest="cache_command", required=True)
196
+ prune = cache.add_parser("prune", help="preview or apply a checked cache cleanup plan")
197
+ prune.add_argument("directory", type=Path)
198
+ prune.add_argument("--out", type=Path)
199
+ prune.add_argument("--apply", type=Path)
200
+ for command in (plan, build):
201
+ tests = command.add_mutually_exclusive_group()
202
+ tests.add_argument(
203
+ "--run-db-tests",
204
+ dest="run_db_tests",
205
+ action="store_true",
206
+ default=None,
207
+ help="run PostgreSQL, component and acceptance tests (build default: disabled)",
208
+ )
209
+ tests.add_argument(
210
+ "--skip-db-tests",
211
+ dest="run_db_tests",
212
+ action="store_false",
213
+ help="skip DB tests and baseline; produce an unverified development build",
214
+ )
215
+ for name in ("status", "events", "cancel", "wait", "artifacts"):
216
+ command = sub.add_parser(name)
217
+ command.add_argument("directory", type=Path)
218
+ if name == "events":
219
+ command.add_argument("--after-sequence", type=int, default=0)
220
+ command.add_argument("--limit", type=int, default=100)
221
+ if name == "wait":
222
+ command.add_argument("--timeout", type=int)
223
+ # Document global flags; a small pre-parser accepts them before or after the command.
224
+ root.add_argument("--machine", action="store_true", help="one component JSON response")
225
+ root.add_argument("--request-id")
226
+ root.add_argument("--component-capabilities", action="store_true")
227
+ return root
228
+
229
+
230
+ def main(argv: list[str] | None = None) -> int:
231
+ values = list(sys.argv[1:] if argv is None else argv)
232
+ machine = "--machine" in values
233
+ request_id, command, result, error, code, status = None, "arguments", None, None, 0, "succeeded"
234
+ try:
235
+ common = Parser(add_help=False, allow_abbrev=False)
236
+ common.add_argument("--machine", action="store_true")
237
+ common.add_argument("--request-id")
238
+ common.add_argument("--component-capabilities", action="store_true")
239
+ flags, rest = common.parse_known_args(values)
240
+ machine, request_id = flags.machine, flags.request_id
241
+ if flags.component_capabilities:
242
+ document = capabilities()
243
+ if machine:
244
+ document = envelope("capabilities", request_id, result=document)
245
+ print(canonical_json(document))
246
+ return 0
247
+ if machine:
248
+ output = io.StringIO()
249
+ try:
250
+ with redirect_stdout(output):
251
+ args = parser().parse_args(rest)
252
+ except SystemExit as exc:
253
+ if exc.code != 0:
254
+ raise
255
+ command = "version" if "--version" in rest else "help"
256
+ print(
257
+ canonical_json(
258
+ envelope(command, request_id, result={command: output.getvalue()})
259
+ )
260
+ )
261
+ return 0
262
+ else:
263
+ args = parser().parse_args(rest)
264
+ subcommand = {
265
+ "runner": "check",
266
+ "config": "show",
267
+ "package": "names",
268
+ "env": "prepare",
269
+ "cache": "prune",
270
+ }
271
+ command = args.command + (
272
+ " " + subcommand[args.command] if args.command in subcommand else ""
273
+ )
274
+ if args.command == "docs":
275
+ command += " " + args.docs_command
276
+ if args.command == "runtime":
277
+ command += " " + args.runtime_command
278
+ if args.command == "changes":
279
+ command += " " + args.changes_command
280
+ if args.command == "dev":
281
+ command += " " + args.dev_command
282
+ if args.command == "init":
283
+ result = initialize_project(
284
+ args.directory.expanduser().absolute(),
285
+ with_doc=args.with_doc,
286
+ doc_languages=args.doc_languages,
287
+ features=args.features,
288
+ build_mode=args.build_mode,
289
+ )
290
+ else:
291
+ out = (
292
+ args.out
293
+ if args.command == "runner"
294
+ else getattr(args, "operations", Path("operations"))
295
+ )
296
+ service = MakerService(out.expanduser().absolute())
297
+ options = {
298
+ key: getattr(args, key)
299
+ for key in ("config_dir", "features", "build_mode", "with_doc", "doc_languages")
300
+ if hasattr(args, key)
301
+ }
302
+ if args.command == "dev":
303
+ from pg_maker.development.cli import dispatch
304
+
305
+ result = dispatch(service, args)
306
+ elif args.command == "changes":
307
+ from pg_maker.changes.workspace import export_changes, validate_changes, workspace
308
+
309
+ if args.changes_command == "workspace":
310
+ result = workspace(
311
+ args.input_store.absolute(),
312
+ args.source_hash,
313
+ args.directory.absolute(),
314
+ lock=args.lock,
315
+ feature=args.feature,
316
+ until=args.until,
317
+ )
318
+ elif args.changes_command == "export":
319
+ result = export_changes(
320
+ args.directory.absolute(), args.out.absolute(), args.id, args.postgresql
321
+ )
322
+ else:
323
+ result = validate_changes(args.file.absolute())
324
+ elif args.command == "runtime":
325
+ from pg_maker.integrations.runtime import plan_runtime, verify_runtime_plan
326
+ from pg_maker.models import RuntimeRequest
327
+
328
+ if args.runtime_command == "plan":
329
+ result = plan_runtime(args.directory, read_json(args.profile))
330
+ if args.out:
331
+ write_json(args.out.absolute(), result)
332
+ else:
333
+ document = read_json(args.plan)
334
+ verify_runtime_plan(document, args.plan_hash)
335
+ result = service.start_operation(
336
+ RuntimeRequest(document, str(args.out.absolute())),
337
+ operation_id=args.operation_id,
338
+ request_id=request_id,
339
+ )
340
+ if not args.detach:
341
+ result = service.wait(service.directory / result["operation_id"])
342
+ status = result["status"]
343
+ if status in {"failed", "cancelled", "partial", "interrupted"}:
344
+ error = result.get("error")
345
+ code = EXIT_CODES.get((error or {}).get("code"), 6)
346
+ elif args.command in {"config", "features", "package", "validate", "env", "resolve"}:
347
+ if args.command == "validate":
348
+ result = service.validate(args.manifest, **options)
349
+ elif args.command in {"env", "resolve"}:
350
+ prepare = (
351
+ service.resolve
352
+ if args.command == "resolve"
353
+ else service.prepare_environments
354
+ )
355
+ env_option = (
356
+ {"environments": args.environments} if args.command == "resolve" else {}
357
+ )
358
+ result = prepare(
359
+ args.manifest,
360
+ output=args.out,
361
+ input_store=args.input_store,
362
+ offline=args.offline,
363
+ request_id=request_id,
364
+ operation_id=args.operation_id,
365
+ **env_option,
366
+ **options,
367
+ )
368
+ directory = service.directory / result["operation_id"]
369
+ if not args.detach:
370
+ if not machine:
371
+ print(
372
+ f"Operation {result['operation_id']}; logs: {directory}",
373
+ file=sys.stderr,
374
+ )
375
+ result = service.wait(directory)
376
+ else:
377
+ result = service.config_show(args.manifest, **options)
378
+ if args.command == "features":
379
+ result = {"features": result["data"]["features"]}
380
+ elif args.command == "package":
381
+ result = {
382
+ "variants": [
383
+ {"id": v["id"], **v["identity"]} for v in result["data"]["variants"]
384
+ ]
385
+ }
386
+ elif args.command == "platforms":
387
+ from pg_maker.config import resource_path
388
+ from pg_maker.yamlio import load_yaml
389
+
390
+ result = {
391
+ "platforms": [
392
+ load_yaml(path, "platform")
393
+ for path in sorted(resource_path("recipes", "platforms").glob("*.yaml"))
394
+ ]
395
+ }
396
+ elif args.command == "plan":
397
+ result = service.plan(
398
+ args.lock,
399
+ goal=args.goal,
400
+ input_store=args.input_store,
401
+ run_db_tests=args.run_db_tests,
402
+ )
403
+ if args.out:
404
+ write_json(args.out.absolute(), result)
405
+ elif args.command in {"build", "docs"}:
406
+ result = service.build(
407
+ args.lock,
408
+ goal=args.goal,
409
+ plan=args.plan,
410
+ plan_hash=args.plan_hash,
411
+ run_db_tests=args.run_db_tests,
412
+ input_store=args.input_store,
413
+ cache_store=args.cache_store,
414
+ use_cache=not args.no_cache,
415
+ operation_id=args.operation_id,
416
+ request_id=request_id,
417
+ **{
418
+ key: getattr(args, key)
419
+ for key in ("with_doc", "doc_languages", "features", "build_mode")
420
+ if hasattr(args, key)
421
+ },
422
+ )
423
+ directory = service.directory / result["operation_id"]
424
+ if not args.detach:
425
+ if not machine:
426
+ print(
427
+ f"Operation {result['operation_id']}; logs: {directory}",
428
+ file=sys.stderr,
429
+ )
430
+ result = service.wait(directory)
431
+ elif args.command == "resume":
432
+ directory = args.directory.expanduser().absolute()
433
+ result = service.resume(
434
+ directory, plan_hash=args.plan_hash, input_hash=args.input_hash
435
+ )
436
+ if not args.detach:
437
+ result = service.wait(directory)
438
+ elif args.command == "export":
439
+ result = service.export(
440
+ args.directory.expanduser().absolute(),
441
+ args.out,
442
+ include_inputs=args.include_inputs,
443
+ )
444
+ elif args.command == "cleanup":
445
+ from pg_maker.execution.cleanup import apply_cleanup, cleanup_plan
446
+
447
+ if args.apply:
448
+ document = read_json(args.apply)
449
+ if document.get("operation") != str(args.directory.absolute()):
450
+ raise ValidationError("cleanup plan belongs to another operation")
451
+ result = apply_cleanup(service, document)
452
+ elif args.exported:
453
+ result = cleanup_plan(
454
+ service, args.directory.absolute(), args.exported.absolute()
455
+ )
456
+ else:
457
+ raise ValidationError("cleanup requires --export for preview or --apply")
458
+ if args.out:
459
+ write_json(args.out.absolute(), result)
460
+ elif args.command == "cache":
461
+ from pg_maker.execution.cache import SnapshotStore
462
+
463
+ cache_store = SnapshotStore(args.directory.expanduser().absolute())
464
+ result = (
465
+ cache_store.prune(read_json(args.apply))
466
+ if args.apply
467
+ else cache_store.prune_plan()
468
+ )
469
+ if args.out:
470
+ write_json(args.out.absolute(), result)
471
+ elif args.command == "doctor":
472
+ result = service.doctor()
473
+ elif args.command == "runner":
474
+ request = OperationRequest(
475
+ EnvironmentSpec(args.image, current_user()),
476
+ (
477
+ CommandSpec("kernel", ("uname", "-s"), timeout_seconds=30),
478
+ CommandSpec("user", ("id", "-u"), timeout_seconds=30),
479
+ ),
480
+ )
481
+ result = service.start_operation(
482
+ request, operation_id=args.operation_id, request_id=request_id
483
+ )
484
+ directory = service.directory / result["operation_id"]
485
+ if not args.detach:
486
+ if not machine:
487
+ print(
488
+ f"Operation {result['operation_id']}; logs: {directory}",
489
+ file=sys.stderr,
490
+ )
491
+ result = service.wait(directory)
492
+ else:
493
+ directory = args.directory.expanduser().absolute()
494
+ if args.command == "artifacts":
495
+ from pg_maker.artifacts.catalog import operation_artifacts
496
+
497
+ result = operation_artifacts(directory, service.status(directory))
498
+ elif args.command == "events":
499
+ result = service.events(
500
+ directory, after_sequence=args.after_sequence, limit=args.limit
501
+ )
502
+ elif args.command == "wait":
503
+ result = service.wait(directory, timeout_seconds=args.timeout)
504
+ else:
505
+ result = getattr(service, args.command)(directory)
506
+ if args.command == "dev" and args.dev_command in {"build", "exec"}:
507
+ status = result["status"]
508
+ if not args.detach:
509
+ error = result.get("error")
510
+ code = (
511
+ 0 if status == "succeeded" else EXIT_CODES.get((error or {}).get("code"), 6)
512
+ )
513
+ elif args.command == "wait" or (
514
+ args.command in {"runner", "env", "resolve", "build", "docs", "resume"}
515
+ and not args.detach
516
+ ):
517
+ status = result["status"]
518
+ error = result["error"]
519
+ code = (
520
+ 0
521
+ if status == "succeeded"
522
+ else 5
523
+ if status == "partial"
524
+ else EXIT_CODES.get((error or {}).get("code"), 6)
525
+ )
526
+ elif args.command in {"runner", "env", "resolve", "build", "docs", "resume"}:
527
+ status = result["status"]
528
+ except MakerError as exc:
529
+ code, error, status = exc.exit_code, exc.as_dict(), "failed"
530
+ except KeyboardInterrupt:
531
+ code, error, status = (
532
+ 130,
533
+ {"code": "wait_interrupted", "message": "worker was not cancelled"},
534
+ "failed",
535
+ )
536
+ except (OSError, ValueError) as exc:
537
+ code, error, status = 6, MakerError(f"{type(exc).__name__}: {exc}").as_dict(), "failed"
538
+ if machine:
539
+ print(
540
+ canonical_json(envelope(command, request_id, result=result, error=error, status=status))
541
+ )
542
+ elif error:
543
+ print(f"{error['code']}: {error['message']}", file=sys.stderr)
544
+ else:
545
+ print(json.dumps(redact(result), ensure_ascii=False, indent=2))
546
+ return code
@@ -0,0 +1,4 @@
1
+ """Reserved project boundary; planned contract: docs/interfaces/build.md.
2
+
3
+ Concrete adapters are introduced with their implementation stage.
4
+ """