margo-tooling 0.5.1__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.
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.5
2
+ Name: margo-tooling
3
+ Version: 0.5.1
4
+ Summary: Developer CLI for building and publishing Margo application packages
5
+ License-File: LICENSE
6
+ Requires-Python: >=3.12
7
+ Requires-Dist: dynaconf>=3.2.10
8
+ Requires-Dist: jinja2>=3.1
9
+ Requires-Dist: oras>=0.2.28
10
+ Requires-Dist: pyyaml>=6.0.3
11
+ Requires-Dist: rich>=14.0.0
12
+ Requires-Dist: semver>=3.0.4
13
+ Requires-Dist: typer>=0.15.4
@@ -0,0 +1,34 @@
1
+ margot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ margot/config.py,sha256=cc_jRQN-T-UyfHjGJYC_buMqq2DLfRlw0A5r--4r3wY,2283
3
+ margot/console.py,sha256=27TpwxURRKOBtQaWiBAXyfPVEfRGu9QwFO8N8BW82vg,4662
4
+ margot/main.py,sha256=OVaLVVieWVcnlGOTAzmYCt4Pp5MmfxHhdW2DntRiWDo,835
5
+ margot/commands/__init__.py,sha256=US6hzhLZfbYC00Po2aaVIgGs5rg1L71MbpFDKd9KMk8,40
6
+ margot/commands/auth.py,sha256=fmsVbmrR2IQHYpZhng92doOg4qcclgXmQhiYzj57SFw,3982
7
+ margot/commands/build.py,sha256=Toe8XDgoX1sXq3tnrLTm6h31P-L1at5kgFMSg_M9Xxw,3012
8
+ margot/commands/fetch.py,sha256=_i8X-p5tylIsJ7p5AXISkrDag4S3fG7KhVNJyuvyUSA,652
9
+ margot/commands/global_options.py,sha256=punmdJAxmRZNZIMPONIgQ5LvSg1rCwJhVwwCHmKbz8A,1001
10
+ margot/commands/pull.py,sha256=-GOyEr4gC_UrD9MWUnP49oNI0urTN0FuDYQ2eNGDU5o,2032
11
+ margot/commands/push.py,sha256=KUIN4n6acxobsamkNhkeeethXw8jjAp4W6o7EY_ymwM,3156
12
+ margot/commands/version.py,sha256=aFI7B8xZ0QaGYNpMKkitTBxk7xBdEpw4CopxKX3ad0g,321
13
+ margot/domain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ margot/domain/auth.py,sha256=OqNIj2sT7eSldi-y03VlcQvKTE45ufocQn2izzJx2W0,2575
15
+ margot/domain/layers.py,sha256=9UNBjJx7srV0YC-c3RNO7cromGL1JWSdBEXpzh6HIdk,3392
16
+ margot/domain/metadata.py,sha256=s-FYX8W2ArgwqC53odMaBDb6RvoLGJ71hly4WIlqo4c,8476
17
+ margot/domain/models.py,sha256=lqeOTMjsePoCGRWiVgkf1iRgH_MBs9CsaMXLmv1xh58,1563
18
+ margot/domain/tags.py,sha256=P37QKV7qsK6X-8KD-2L7WmrNXU5owrAavoiJJbZUjy4,1742
19
+ margot/domain/uri.py,sha256=lMsAlErSq48fgQ94oLcEyW1KU4Z2Fr7X9gAHYpDxiUM,2214
20
+ margot/infra/__init__.py,sha256=SWwiLcKZaATuZs2Lz1Xi2Cu9hJ1ErxgKt1q8z2q3P6o,33
21
+ margot/infra/credentials.py,sha256=T1YJCU_vdl97jHlR45EJo01ONgNYa2VUEqxLimFayAM,6754
22
+ margot/infra/filesystem.py,sha256=8Ji7YqS0p8qepeI0nJoQzNUfqWnnVUAgJGNgWCiCwTU,4010
23
+ margot/infra/oci.py,sha256=TCQQ4M9NV9Vgwcnygn38D70fuEhQqZ2Oxoe0S10pWlQ,13071
24
+ margot/services/__init__.py,sha256=LP0milclAyzZZ-rCaOvHbjf98gAxTnaKLU4C-pJ7f6s,52
25
+ margot/services/auth.py,sha256=RHdKnO_6z7AH3NdXNPQPIdw_Ynf2nKVl0jslNB0tEuQ,3361
26
+ margot/services/build.py,sha256=1SUxdBSTf_QmVsuZSRk7X2h46Q7icH5-I3MgmFrprHU,10578
27
+ margot/services/fetch.py,sha256=aRkvQ9K4f5b_iN2UZPrkcZBe405mMWyffCdDzmSS_Yk,976
28
+ margot/services/pull.py,sha256=4lmc53-Tttl5iIpBxFm0grU_G8Xmql8IvHAizZDfRjs,6546
29
+ margot/services/push.py,sha256=JtqioOvzsb79Hwcm4cT4ZV47S4YV_pHkbSe-kL6EBXg,13084
30
+ margo_tooling-0.5.1.dist-info/METADATA,sha256=_Lq-410NYg_KDOTcUMReWR-uNSvkaerP9WGby2aPtgA,383
31
+ margo_tooling-0.5.1.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
32
+ margo_tooling-0.5.1.dist-info/entry_points.txt,sha256=w7pbJv6-Ho6RfPeDqjkKmbrdpVvO8NPA88Bt6laCMq8,43
33
+ margo_tooling-0.5.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
34
+ margo_tooling-0.5.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ margot = margot.main:app
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
margot/__init__.py ADDED
File without changes
@@ -0,0 +1 @@
1
+ """Commands layer: CLI entry points."""
@@ -0,0 +1,117 @@
1
+ """Auth commands: manage OCI registry credentials."""
2
+
3
+ from datetime import UTC, datetime
4
+ import sys
5
+ from typing import Annotated
6
+
7
+ from rich.table import Table
8
+ from typer import Argument, Option, Typer
9
+
10
+ from margot import console
11
+ from margot.services import auth as auth_service
12
+
13
+ app = Typer(name="auth", help="Manage OCI registry credentials.", no_args_is_help=True)
14
+
15
+
16
+ def _format_expiry(expires_at: datetime) -> str:
17
+ """Format time remaining until expiry as a human-readable string."""
18
+ remaining = expires_at - datetime.now(tz=UTC)
19
+ total_seconds = int(remaining.total_seconds())
20
+ if total_seconds <= 0:
21
+ return f"already expired ({expires_at.strftime('%Y-%m-%dT%H:%M:%SZ')})"
22
+ hours, remainder = divmod(total_seconds, 3600)
23
+ minutes = remainder // 60
24
+ return f"{hours}h {minutes:02d}m (expires {expires_at.strftime('%Y-%m-%dT%H:%M:%SZ')})"
25
+
26
+
27
+ _STATUS_COLORS = {"VALID": "green", "EXPIRING": "yellow", "EXPIRED": "red"}
28
+
29
+
30
+ def _format_remaining(remaining_seconds: int) -> str:
31
+ """Format a remaining-time duration (in seconds) as a human-readable string."""
32
+ if remaining_seconds <= 0:
33
+ return "expired"
34
+ hours, remainder = divmod(remaining_seconds, 3600)
35
+ minutes = remainder // 60
36
+ return f"{hours}h {minutes:02d}m"
37
+
38
+
39
+ @app.command()
40
+ def login(
41
+ registry: Annotated[str, Argument(help="Registry hostname (e.g. public.ecr.aws).")],
42
+ username: Annotated[str | None, Option("--username", "-u", help="Username for authentication.")] = None,
43
+ password_stdin: Annotated[bool, Option("--password-stdin", help="Read password from stdin.")] = False,
44
+ expiry_hours: Annotated[
45
+ int | None,
46
+ Option(
47
+ "--expiry-hours",
48
+ help="Save credential expiry to credentials file. Provide the number of hours until expiry (e.g. 12 for ECR).",
49
+ ),
50
+ ] = None,
51
+ ) -> None:
52
+ """Login to an OCI registry."""
53
+ if not username:
54
+ console.fatal("Username required. Use --username.")
55
+
56
+ if not password_stdin:
57
+ console.fatal("Password required. Use --password-stdin.")
58
+
59
+ password = sys.stdin.read().strip()
60
+ if not password:
61
+ console.fatal("Empty password received from stdin.")
62
+
63
+ try:
64
+ expires_at = auth_service.login(
65
+ registry=registry,
66
+ username=username,
67
+ password=password,
68
+ expiry_hours=expiry_hours,
69
+ )
70
+ console.success(f"Logged in to {registry}.")
71
+ if expires_at is not None:
72
+ console.success(f"Token expires in {_format_expiry(expires_at)}")
73
+ except Exception as e: # noqa: BLE001
74
+ console.fatal(f"Login failed: {e}")
75
+
76
+
77
+ @app.command()
78
+ def logout(
79
+ registry: Annotated[str, Argument(help="Registry hostname (e.g. public.ecr.aws).")],
80
+ ) -> None:
81
+ """Logout from an OCI registry."""
82
+ try:
83
+ auth_service.logout(registry=registry)
84
+ console.success(f"Logged out from {registry}.")
85
+ except Exception as e: # noqa: BLE001
86
+ console.fatal(f"Logout failed: {e}")
87
+
88
+
89
+ @app.command()
90
+ def status() -> None:
91
+ """Show credential status for all tracked OCI registries."""
92
+ result = auth_service.auth_status()
93
+
94
+ if not result.tracked and not result.oras_only:
95
+ console.success("No credentials tracked.")
96
+ return
97
+
98
+ table = Table(title="Registry Credential Status")
99
+ table.add_column("Registry")
100
+ table.add_column("Expires At")
101
+ table.add_column("Remaining")
102
+ table.add_column("Status")
103
+
104
+ for entry in result.tracked:
105
+ color = _STATUS_COLORS.get(entry.status, "white")
106
+ remaining = _format_remaining(int(entry.remaining.total_seconds()))
107
+ table.add_row(
108
+ entry.hostname,
109
+ entry.expires_at.strftime("%Y-%m-%dT%H:%M:%SZ"),
110
+ remaining,
111
+ f"[{color}]{entry.status}[/{color}]",
112
+ )
113
+
114
+ for hostname in result.oras_only:
115
+ table.add_row(hostname, "-", "present but expiry unknown", "[cyan]UNKNOWN[/cyan]")
116
+
117
+ console.print_table(table)
@@ -0,0 +1,88 @@
1
+ """Build command: compile Margo application components locally."""
2
+
3
+ from typing import Annotated
4
+
5
+ from typer import Option
6
+
7
+ from margot import console
8
+ from margot.domain.models import BuildTarget, PackageType
9
+ from margot.services import build as build_service
10
+
11
+
12
+ def _resolve_types(types: list[str] | None) -> tuple[list[str], bool]:
13
+ """Validate and expand --type values. Returns (resolved_types, expanded_from_all)."""
14
+ if not types:
15
+ return ["margo", "compose", "quadlet"], True
16
+
17
+ valid_types = ("margo", "compose", "quadlet", "all")
18
+ for t in types:
19
+ if t not in valid_types:
20
+ console.fatal(f"invalid --type '{t}'. Must be one of: margo, compose, quadlet, all")
21
+
22
+ if "all" in types:
23
+ return ["margo", "compose", "quadlet"], True
24
+
25
+ # Deduplicate preserving order
26
+ seen: set[str] = set()
27
+ resolved: list[str] = []
28
+ for t in types:
29
+ if t not in seen:
30
+ resolved.append(t)
31
+ seen.add(t)
32
+ return resolved, False
33
+
34
+
35
+ def _invoke_build(
36
+ t: str,
37
+ expanded_from_all: bool,
38
+ build_dir: str,
39
+ version: str | None,
40
+ variant: str | None,
41
+ ) -> list[BuildTarget]:
42
+ """Call build service for one type. Returns targets or [] if component is missing and expanded_from_all."""
43
+ package_type = PackageType(t)
44
+ try:
45
+ return build_service.build(
46
+ package_type,
47
+ project_dir=".",
48
+ build_dir=build_dir,
49
+ version_override=version,
50
+ variant=variant,
51
+ )
52
+ except ValueError as e:
53
+ if expanded_from_all and "not defined in margo.yaml" in str(e):
54
+ console.info(f"Skipping {t}: not defined in margo.yaml")
55
+ return []
56
+ raise
57
+
58
+
59
+ def build_cmd(
60
+ types: Annotated[
61
+ list[str] | None,
62
+ Option("--type", "-t", help="Package type(s) to build (margo|compose|quadlet|all). Repeatable."),
63
+ ] = None,
64
+ version: str | None = Option(None, "--version", "-v", help="Override version for all components."),
65
+ build_dir: str = Option(".dist", "--build-dir", help="Output directory for built artifacts."),
66
+ variant: str | None = Option(None, "--variant", help="Build a specific variant (compose/quadlet only)."),
67
+ ) -> None:
68
+ """Build Margo application package types locally."""
69
+ resolved, expanded_from_all = _resolve_types(types)
70
+
71
+ all_targets: list[BuildTarget] = []
72
+ try:
73
+ for t in resolved:
74
+ all_targets.extend(_invoke_build(t, expanded_from_all, build_dir, version, variant))
75
+
76
+ if all_targets:
77
+ for target in all_targets:
78
+ if target.variant_name:
79
+ console.success(f"Built ({target.variant_name}): {target.artifact_path}")
80
+ else:
81
+ console.success(f"Built: {target.artifact_path}")
82
+ else:
83
+ console.warning("Nothing was built.")
84
+
85
+ except ValueError as e:
86
+ console.fatal(str(e))
87
+ except Exception as e: # noqa: BLE001
88
+ console.fatal(f"Build failed: {e}")
@@ -0,0 +1,22 @@
1
+ """Fetch command: retrieve and display OCI artifact manifest."""
2
+
3
+ from typing import Any
4
+
5
+ from margot import console
6
+ from margot.services import fetch as fetch_service
7
+
8
+
9
+ def fetch(uri: str) -> None:
10
+ """
11
+ Fetch and display the manifest of an OCI artifact.
12
+
13
+ Args:
14
+ uri: Full OCI reference (e.g. public.ecr.aws/g2n4p2m7/margo:1.0.0)
15
+ """
16
+ try:
17
+ manifest: dict[str, Any] = fetch_service.fetch_manifest(uri)
18
+ console.print_json(manifest)
19
+ except ValueError as e:
20
+ console.fatal(f"Error fetching manifest: {e}")
21
+ except Exception as e: # noqa: BLE001
22
+ console.fatal(f"Error fetching manifest: {e}")
@@ -0,0 +1,29 @@
1
+ """Global CLI options: version, verbose, and debug flags."""
2
+
3
+ from typer import Exit, Option, echo
4
+
5
+ from margot.commands.version import get_version
6
+ from margot.console import set_debug, set_verbose
7
+
8
+
9
+ def global_options(
10
+ version_flag: bool = Option(False, "--version", "-V", help="Print version and exit.", is_eager=True),
11
+ verbose: bool = Option(False, "--verbose", "-v", help="Enable verbose output (step-level info)."),
12
+ debug: bool = Option(False, "--debug", "-d", help="Enable debug output (infra-level detail, implies --verbose)."),
13
+ ) -> None:
14
+ """Register global CLI options.
15
+
16
+ Handles version output and sets verbosity flags for the application.
17
+ Called once at startup via app.callback().
18
+ """
19
+ if debug:
20
+ set_debug(True)
21
+ elif verbose:
22
+ set_verbose(True)
23
+ else:
24
+ set_debug(False)
25
+ set_verbose(False)
26
+
27
+ if version_flag:
28
+ echo(f"margot {get_version()}")
29
+ raise Exit() # noqa: RSE102 - Exit class must be instantiated
@@ -0,0 +1,56 @@
1
+ """Pull command: retrieve OCI artifact layers to a local directory."""
2
+
3
+ from typing import Annotated
4
+
5
+ from typer import Argument, Option
6
+
7
+ from margot import console
8
+ from margot.domain.models import PackageType
9
+ from margot.services import pull as pull_service
10
+
11
+ _VALID_FORCE_TYPES = ("margo", "compose", "quadlet")
12
+
13
+
14
+ def pull(
15
+ uri: str = Argument(..., help="Full OCI reference (e.g. public.ecr.aws/g2n4p2m7/margo:1.0.0)"),
16
+ output: str = Option(".", "--output", "-o", help="Output directory (default: current directory)."),
17
+ force: bool = Option(
18
+ False, "--force", "-f", help="Bypass SemVer gate, malicious annotation checks, and allow non-standard artifact types."
19
+ ),
20
+ force_type: Annotated[
21
+ str | None, Option("--force-type", help="Force artifact type interpretation (margo|compose|quadlet).")
22
+ ] = None,
23
+ ) -> None:
24
+ """
25
+ Pull OCI artifact layers to a local directory.
26
+
27
+ URI is the full OCI reference: registry/repository:tag
28
+ """
29
+ resolved_force_type: PackageType | None = None
30
+
31
+ if force_type is not None:
32
+ if force_type not in _VALID_FORCE_TYPES:
33
+ console.fatal(f"invalid --force-type '{force_type}'. Must be one of: {', '.join(_VALID_FORCE_TYPES)}")
34
+ resolved_force_type = PackageType(force_type)
35
+
36
+ if resolved_force_type is not None and not force:
37
+ force = True
38
+ console.warning("--force-type implies --force. Safety checks bypassed.")
39
+ elif force and resolved_force_type is None:
40
+ console.warning("--force is active. Safety checks bypassed.")
41
+
42
+ try:
43
+ paths = pull_service.pull_artifact(
44
+ uri,
45
+ outdir=output,
46
+ force=force,
47
+ force_type=resolved_force_type,
48
+ )
49
+ for path in paths:
50
+ console.success(f"Pulled: {path}")
51
+ if not paths:
52
+ console.warning("No layers pulled.")
53
+ except ValueError as e:
54
+ console.fatal(str(e))
55
+ except Exception as e: # noqa: BLE001
56
+ console.fatal(f"Error pulling artifact: {e}")
@@ -0,0 +1,91 @@
1
+ """Push command: push built Margo artifacts to OCI registries."""
2
+
3
+ from typing import Annotated
4
+
5
+ from typer import Option
6
+
7
+ from margot import console
8
+ from margot.domain.models import BuildTarget, PackageType
9
+ from margot.services import push as push_service
10
+
11
+
12
+ def _resolve_types(types: list[str] | None) -> tuple[list[str], bool]:
13
+ """Validate and expand --type values. Returns (resolved_types, expanded_from_all)."""
14
+ if not types:
15
+ return ["margo", "compose", "quadlet"], True
16
+
17
+ valid_types = ("margo", "compose", "quadlet", "all")
18
+ for t in types:
19
+ if t not in valid_types:
20
+ console.fatal(f"invalid --type '{t}'. Must be one of: margo, compose, quadlet, all")
21
+
22
+ if "all" in types:
23
+ return ["margo", "compose", "quadlet"], True
24
+
25
+ # Deduplicate preserving order
26
+ seen: set[str] = set()
27
+ resolved: list[str] = []
28
+ for t in types:
29
+ if t not in seen:
30
+ resolved.append(t)
31
+ seen.add(t)
32
+ return resolved, False
33
+
34
+
35
+ def _invoke_push( # noqa: PLR0913
36
+ t: str,
37
+ expanded_from_all: bool,
38
+ build_dir: str,
39
+ registry: str | None,
40
+ repository: str | None,
41
+ variant: str | None,
42
+ ) -> list[BuildTarget]:
43
+ """Call push service for one type. Returns targets or [] if component is missing and expanded_from_all."""
44
+ package_type = PackageType(t)
45
+ try:
46
+ return push_service.push(
47
+ package_type,
48
+ project_dir=".",
49
+ build_dir=build_dir,
50
+ registry=registry,
51
+ repository=repository,
52
+ variant=variant,
53
+ )
54
+ except ValueError as e:
55
+ if expanded_from_all and "not defined in margo.yaml" in str(e):
56
+ console.info(f"Skipping {t}: not defined in margo.yaml")
57
+ return []
58
+ raise
59
+
60
+
61
+ def push_cmd(
62
+ types: Annotated[
63
+ list[str] | None,
64
+ Option("--type", "-t", help="Package type(s) to push (margo|compose|quadlet|all). Repeatable."),
65
+ ] = None,
66
+ registry: str | None = Option(None, "--registry", help="OCI registry base URL."),
67
+ repository: str | None = Option(None, "--repository", help="Repository path."),
68
+ build_dir: str = Option(".dist", "--build-dir", help="Directory containing built artifacts."),
69
+ variant: str | None = Option(None, "--variant", help="Push a specific variant (compose/quadlet only)."),
70
+ ) -> None:
71
+ """Push built Margo application artifacts to an OCI registry."""
72
+ resolved, expanded_from_all = _resolve_types(types)
73
+
74
+ all_targets: list[BuildTarget] = []
75
+ try:
76
+ for t in resolved:
77
+ all_targets.extend(_invoke_push(t, expanded_from_all, build_dir, registry, repository, variant))
78
+
79
+ if all_targets:
80
+ for target in all_targets:
81
+ if target.variant_name:
82
+ console.success(f"Pushed ({target.variant_name}): {target.version}")
83
+ else:
84
+ console.success(f"Pushed: {target.version}")
85
+ else:
86
+ console.warning("Nothing was pushed.")
87
+
88
+ except ValueError as e:
89
+ console.fatal(str(e))
90
+ except Exception as e: # noqa: BLE001
91
+ console.fatal(f"Push failed: {e}")