@delta-infra/cli 1.1.17 → 1.1.18
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.
- package/README.md +513 -506
- package/checksums.txt +5 -5
- package/package.json +1 -1
- package/scripts/install-wizard.js +701 -701
- package/scripts/install.js +442 -442
- package/scripts/run.js +65 -65
- package/skills/delta-sandbox/SKILL.md +388 -388
- package/skills/delta-sandbox/agents/openai.yaml +4 -4
- package/skills/delta-sandbox/references/commands.md +58 -58
- package/skills/delta-sandbox/references/lifecycle.md +100 -100
- package/skills/delta-sandbox/references/recipes.md +138 -138
- package/skills/delta-science/AGENTS.md +47 -47
- package/skills/delta-science/SKILL.md +227 -185
- package/skills/delta-science/agents/openai.yaml +4 -4
- package/skills/delta-science/references/antbo.md +105 -100
- package/skills/delta-science/references/delta-bo.md +92 -89
- package/skills/delta-science/references/gsasii.md +118 -116
- package/skills/delta-science/references/lammps.md +68 -66
- package/skills/delta-science/references/ldm-bo.md +132 -129
- package/skills/delta-science/references/materials-design.md +130 -118
- package/skills/delta-science/references/pubchem.md +128 -126
- package/skills/delta-science/references/pymatgen.md +69 -68
- package/skills/delta-science/references/qe.md +134 -125
- package/skills/delta-science/references/rdkit.md +141 -138
- package/skills/delta-science/references/strbo.md +95 -87
- package/skills/delta-science/references/synbo.md +201 -198
- package/skills/delta-science/references/xrd.md +197 -186
- package/skills/delta-science/scripts/catalog.py +92 -92
- package/skills/delta-science/scripts/generated_catalog.py +69 -69
- package/skills/delta-science/scripts/invoke.py +346 -346
- package/skills/delta-shared/SKILL.md +113 -111
- package/skills/delta-shared/agents/openai.yaml +4 -4
- package/skills/manifest.json +19 -19
|
@@ -1,186 +1,197 @@
|
|
|
1
|
-
# XRD Cloud Compute
|
|
2
|
-
|
|
3
|
-
`xrd`
|
|
4
|
-
`delta-cli
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
| `
|
|
24
|
-
| `xmatcher-
|
|
25
|
-
| `xmatcher-
|
|
26
|
-
| `
|
|
27
|
-
| `xmatcher-
|
|
28
|
-
| `
|
|
29
|
-
| `
|
|
30
|
-
| `refinement-
|
|
31
|
-
| `
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
--
|
|
43
|
-
--
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
--
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
`
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
-
|
|
178
|
-
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
1
|
+
# XRD Cloud Compute reference
|
|
2
|
+
|
|
3
|
+
`xrd` is a real tool for accessing XRD cloud compute through the Science tool proxy. Route every
|
|
4
|
+
call through `delta-cli`; do not bypass the CLI with broker URLs, `curl`, `requests`, `httpx`, a
|
|
5
|
+
browser or local XRD libraries. This is a tool reference for `delta-science`, not a second HTTP
|
|
6
|
+
client.
|
|
7
|
+
|
|
8
|
+
## Tool and endpoints
|
|
9
|
+
|
|
10
|
+
Before execution, use the live catalogue to confirm the canonical names and enabled status in the
|
|
11
|
+
current environment:
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
delta-cli science list
|
|
15
|
+
delta-cli science endpoints list xrd
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Copy `xrd` endpoint names exactly from the output of the second command. This reference covers
|
|
19
|
+
the following stable contracts:
|
|
20
|
+
|
|
21
|
+
| endpoint | Method/purpose | Request type |
|
|
22
|
+
| --- | --- | --- |
|
|
23
|
+
| `healthz`, `readyz`, `capabilities`, `xmatcher-status` | Readiness, capabilities and database status | Read-only JSON |
|
|
24
|
+
| `xmatcher-artifacts` | Upload an observed pattern, model input, CIF or instrument parameters | `invoke --file` |
|
|
25
|
+
| `xmatcher-artifact`, `xmatcher-artifact-content` | Query/read an artifact | `invoke --path-params` |
|
|
26
|
+
| `xqueryer-predictions` | XQueryer single-phase candidate prediction | JSON |
|
|
27
|
+
| `xmatcher-detect-peaks`, `xmatcher-match` | Peak detection and single-phase matching | JSON |
|
|
28
|
+
| `xmatcher-multiphase-match`, `xdecomposer-predictions` | Multiphase matching and phase decomposition | JSON |
|
|
29
|
+
| `xmatcher-cif-xrd`, `xmatcher-pdf-peaks-xlsx` | CIF simulation and PDF peak-table export | JSON/binary |
|
|
30
|
+
| `xmatcher-refinement-patterns` | Generate refinement inputs and a provenance manifest | JSON |
|
|
31
|
+
| `refinement-fullprof`, `refinement-gsasii`, `refinement-wpem` | Submit a refinement job to the corresponding backend | JSON + header |
|
|
32
|
+
| `refinement-job`, `refinement-job-events`, `refinement-job-artifacts` | Query a refinement job | `invoke --path-params` |
|
|
33
|
+
| `refinement-job-cancel` | Request refinement-job cancellation | `invoke --path-params` |
|
|
34
|
+
| `mp500-cif-exports` | Export an MP500 structure as CIF | JSON |
|
|
35
|
+
|
|
36
|
+
The live catalogue is authoritative. If an endpoint is absent from it, stop and report a
|
|
37
|
+
configuration issue; do not retry under a different name.
|
|
38
|
+
|
|
39
|
+
## CLI argument mapping
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
--data Upstream JSON body
|
|
43
|
+
--params Upstream URL query parameters
|
|
44
|
+
--path-params Replace {artifact_id}/{job_id} in the endpoint path
|
|
45
|
+
--headers Additional upstream headers, such as Idempotency-Key
|
|
46
|
+
--file Send a local file to the tool proxy via file_base64
|
|
47
|
+
--content-type The file's original MIME type
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`--params` cannot replace `--path-params`. Do not put local paths, base64, path parameters or
|
|
51
|
+
idempotency keys in ordinary business `--data`. `science file` is a separate file interface for
|
|
52
|
+
tools such as QE and Materials Design. XRD's `xmatcher-artifacts` is a tool-proxy endpoint; use
|
|
53
|
+
`science invoke --file` for it.
|
|
54
|
+
|
|
55
|
+
## Call sequence
|
|
56
|
+
|
|
57
|
+
1. When the user explicitly asks for a diagnosis or execution, read `healthz` first; read
|
|
58
|
+
`capabilities` only when you need to select a backend.
|
|
59
|
+
2. Upload real files through `xmatcher-artifacts` and save the returned `artifact_id` and `sha256`.
|
|
60
|
+
3. Use `xmatcher-match`, `xmatcher-multiphase-match` or `xdecomposer-predictions` for observed
|
|
61
|
+
data; XQueryer uses `model_input_pattern`.
|
|
62
|
+
4. Use `xmatcher-cif-xrd` for CIF simulation. For refinement, call
|
|
63
|
+
`xmatcher-refinement-patterns` first, then choose a refinement endpoint matching
|
|
64
|
+
`data.backends`.
|
|
65
|
+
5. After submitting a refinement job, read its status and artifacts with `refinement-job`,
|
|
66
|
+
`refinement-job-events` and `refinement-job-artifacts`.
|
|
67
|
+
|
|
68
|
+
Do not present a returned `queued` state, scheduler completion or backend success as a scientific
|
|
69
|
+
conclusion. For refinement, report the transport/job final state, backend execution state and
|
|
70
|
+
scientific acceptance state separately.
|
|
71
|
+
|
|
72
|
+
## Readiness checks
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
delta-cli science invoke --tool xrd --endpoint healthz
|
|
76
|
+
delta-cli science invoke --tool xrd --endpoint capabilities
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Call readiness/status additionally only when diagnosis requires it or the user explicitly asks.
|
|
80
|
+
Every required component in the capabilities result must have `available` status. For production
|
|
81
|
+
jobs, also check `asset_release_approved`, checksum fields and warnings. `auto` does not prove GPU
|
|
82
|
+
use; report GPU use only when the result explicitly returns a GPU backend.
|
|
83
|
+
|
|
84
|
+
## Artifact upload and identity
|
|
85
|
+
|
|
86
|
+
Upload an observed pattern:
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
delta-cli science invoke --tool xrd --endpoint xmatcher-artifacts `
|
|
90
|
+
--file observed.csv `
|
|
91
|
+
--params '{"filename":"observed.csv","kind":"observed_pattern","media_type":"text/csv"}' `
|
|
92
|
+
--content-type application/octet-stream
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Allowed `kind` values are `observed_pattern`, `model_input_pattern`, `cif` and
|
|
96
|
+
`instrument_parameters`. Save the successful response's `artifact_id` and `sha256` together and
|
|
97
|
+
pass them to downstream calls unchanged. Pattern files are normalised by the server, so the
|
|
98
|
+
returned digest identifies the normalised artifact and may differ from the digest of the local
|
|
99
|
+
upload bytes.
|
|
100
|
+
|
|
101
|
+
Use path parameters to query an artifact:
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
delta-cli science invoke --tool xrd --endpoint xmatcher-artifact `
|
|
105
|
+
--path-params '{"artifact_id":"art_<returned-id>"}'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Binary-content responses may return `data._binary=true`, `content_base64`, `media_type` and
|
|
109
|
+
`content_length`. Decode only when the user asks to save the content or the workflow requires it,
|
|
110
|
+
and verify it against the SHA-256 returned by the service. Do not infer the format from the filename.
|
|
111
|
+
|
|
112
|
+
## Phase identification and matching
|
|
113
|
+
|
|
114
|
+
XQueryer's `model_input_pattern` must contain exactly 3,500 samples over 10 to 90 degrees 2theta,
|
|
115
|
+
with intensities within the service's capability limits:
|
|
116
|
+
|
|
117
|
+
```text
|
|
118
|
+
delta-cli science invoke --tool xrd --endpoint xqueryer-predictions `
|
|
119
|
+
--data '{"schema_version":1,"pattern":{"artifact_id":"art_<model>","sha256":"<sha>"},"top_k":10,"radiation_profile":"CuKa"}'
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
XMatcher observed pattern:
|
|
123
|
+
|
|
124
|
+
```text
|
|
125
|
+
delta-cli science invoke --tool xrd --endpoint xmatcher-match `
|
|
126
|
+
--data '{"schema_version":1,"pattern":{"artifact_id":"art_<observed>","sha256":"<sha>"},"top_n":10,"element_filter_mode":"contains"}'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Multiphase matching:
|
|
130
|
+
|
|
131
|
+
```text
|
|
132
|
+
delta-cli science invoke --tool xrd --endpoint xmatcher-multiphase-match `
|
|
133
|
+
--data '{"schema_version":1,"pattern":{"artifact_id":"art_<observed>","sha256":"<sha>"},"max_phases":3,"candidate_pool":8}'
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The `score` from `xqueryer-predictions` is a softmax probability; the XMatcher `score` is
|
|
137
|
+
`raw_score / 100`. Do not average them directly or treat them as the same calibrated probability.
|
|
138
|
+
|
|
139
|
+
## CIF simulation and peak tables
|
|
140
|
+
|
|
141
|
+
Each artifact in `cifs` must provide both `artifact_id` and `sha256`:
|
|
142
|
+
|
|
143
|
+
```text
|
|
144
|
+
delta-cli science invoke --tool xrd --endpoint xmatcher-cif-xrd `
|
|
145
|
+
--data '{"schema_version":1,"cifs":[{"artifact":{"artifact_id":"art_<cif>","sha256":"<sha>"},"name":"phase"}],"two_theta_range":[5.0,90.0],"wavelength":"CuKa"}'
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`xmatcher-pdf-peaks-xlsx` returns a binary XLSX file; read and save it only when the user asks for an export.
|
|
149
|
+
|
|
150
|
+
## Refinement jobs
|
|
151
|
+
|
|
152
|
+
First generate the corrected pattern and provenance manifest:
|
|
153
|
+
|
|
154
|
+
```text
|
|
155
|
+
delta-cli science invoke --tool xrd --endpoint xmatcher-refinement-patterns `
|
|
156
|
+
--data '{"schema_version":1,"source_pattern":{"artifact_id":"art_<observed>","sha256":"<sha>"}}'
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Then use the endpoint matching `data.backends`. The example below shows the structure; every
|
|
160
|
+
artifact identity must come from the current call chain:
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
delta-cli science invoke --tool xrd --endpoint refinement-gsasii `
|
|
164
|
+
--data '{"schema_version":1,"radiation_profile":"CuKa","refinement_pattern":{"observed_pattern":{"artifact_id":"art_<obs>","sha256":"<sha>"},"corrected_pattern":{"artifact_id":"art_<corrected>","sha256":"<sha>"},"provenance_manifest":{"artifact_id":"art_<manifest>","sha256":"<sha>"}},"phases":[{"phase_index":0,"name":"phase","cif":{"artifact_id":"art_<cif>","sha256":"<sha>"}}],"wavelengths_angstrom":[1.540593,1.544414],"backends":["gsasii"]}' `
|
|
165
|
+
--headers '{"Idempotency-Key":"<stable-unique-key>"}'
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`refinement-fullprof`, `refinement-gsasii` and `refinement-wpem` select the billing/backend
|
|
169
|
+
entry point. Do not interchange endpoint names or `backends` merely because they map to the same
|
|
170
|
+
path. Submission, cancellation, retry and review are remote mutations and require the user's
|
|
171
|
+
explicit authorisation. After a timeout or disconnection, do not retry blindly; first check
|
|
172
|
+
whether a job has already been created.
|
|
173
|
+
|
|
174
|
+
To query a job:
|
|
175
|
+
|
|
176
|
+
```text
|
|
177
|
+
delta-cli science invoke --tool xrd --endpoint refinement-job `
|
|
178
|
+
--path-params '{"job_id":"refjob_<returned-id>"}'
|
|
179
|
+
|
|
180
|
+
delta-cli science invoke --tool xrd --endpoint refinement-job-events `
|
|
181
|
+
--path-params '{"job_id":"refjob_<returned-id>"}'
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Results and errors
|
|
185
|
+
|
|
186
|
+
- A call succeeds only when the CLI exits with code 0 and the top-level JSON `ok` is `true`.
|
|
187
|
+
- Preserve the returned `data`, warnings, error detail and stable error codes exactly as returned.
|
|
188
|
+
- `202`, `queued` and `running` describe job acceptance/execution state only; they do not mean the solver converged or the result was scientifically accepted.
|
|
189
|
+
- `TIER_CONCURRENCY_EXCEEDED`, `Endpoint is disabled`, `ARTIFACT_MISSING`,
|
|
190
|
+
`MP500_IDENTITY_MISMATCH` and similar errors should stop the current call chain; report the
|
|
191
|
+
original detail and do not switch endpoints, rename them, guess parameters or substitute a
|
|
192
|
+
local algorithm.
|
|
193
|
+
- Use the live catalogue as the authority for paid endpoint prices and availability; before execution, confirm that the user actually requested the business call.
|
|
194
|
+
|
|
195
|
+
Evidence boundary: business results in the current Delta CLI `data` only.
|
|
196
|
+
Call chain: `delta-cli`.
|
|
197
|
+
Do not add information absent from the response: yes.
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Read the authoritative Delta Science catalog through delta-cli."""
|
|
3
|
-
|
|
4
|
-
from __future__ import annotations
|
|
5
|
-
|
|
6
|
-
import argparse
|
|
7
|
-
import json
|
|
8
|
-
import os
|
|
9
|
-
import subprocess
|
|
10
|
-
import sys
|
|
11
|
-
import time
|
|
12
|
-
|
|
13
|
-
from invoke import _parse_cli_error, _resolve_cli, _runtime_config
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def _parser() -> argparse.ArgumentParser:
|
|
17
|
-
parser = argparse.ArgumentParser(description=__doc__)
|
|
18
|
-
action = parser.add_mutually_exclusive_group(required=True)
|
|
19
|
-
action.add_argument("--tools", action="store_true")
|
|
20
|
-
action.add_argument("--endpoints", metavar="TOOL")
|
|
21
|
-
parser.add_argument("--cli")
|
|
22
|
-
parser.add_argument("--science-base-url")
|
|
23
|
-
parser.add_argument("--timeout", type=float, default=30.0)
|
|
24
|
-
return parser
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def main() -> int:
|
|
28
|
-
args = _parser().parse_args()
|
|
29
|
-
started = time.perf_counter()
|
|
30
|
-
kind = "tools" if args.tools else "endpoints"
|
|
31
|
-
try:
|
|
32
|
-
runtime = _runtime_config()
|
|
33
|
-
cli = _resolve_cli(args.cli, runtime)
|
|
34
|
-
env = os.environ.copy()
|
|
35
|
-
base_url = args.science_base_url or runtime.get("science_base_url")
|
|
36
|
-
if base_url:
|
|
37
|
-
env["DELTA_INFRA_SCIENCE_BASE_URL"] = str(base_url)
|
|
38
|
-
|
|
39
|
-
command = [cli, "science", "list"]
|
|
40
|
-
if args.endpoints:
|
|
41
|
-
command = [cli, "science", "endpoints", "list", args.endpoints]
|
|
42
|
-
completed = subprocess.run(
|
|
43
|
-
command,
|
|
44
|
-
capture_output=True,
|
|
45
|
-
text=True,
|
|
46
|
-
encoding="utf-8",
|
|
47
|
-
errors="replace",
|
|
48
|
-
env=env,
|
|
49
|
-
timeout=args.timeout,
|
|
50
|
-
check=False,
|
|
51
|
-
)
|
|
52
|
-
if completed.returncode != 0:
|
|
53
|
-
error_type, detail = _parse_cli_error(completed)
|
|
54
|
-
raise RuntimeError(f"{error_type}: {detail}")
|
|
55
|
-
root = json.loads(completed.stdout)
|
|
56
|
-
if not isinstance(root, dict) or root.get("ok") is not True:
|
|
57
|
-
raise RuntimeError(json.dumps(root, ensure_ascii=False))
|
|
58
|
-
if "data" not in root:
|
|
59
|
-
raise RuntimeError("CLI success envelope is missing data")
|
|
60
|
-
print(json.dumps({
|
|
61
|
-
"ok": True,
|
|
62
|
-
"transport": "delta-cli",
|
|
63
|
-
"catalog": kind,
|
|
64
|
-
"tool": args.endpoints,
|
|
65
|
-
"elapsed_seconds": round(time.perf_counter() - started, 3),
|
|
66
|
-
"native": root["data"],
|
|
67
|
-
}, ensure_ascii=False))
|
|
68
|
-
return 0
|
|
69
|
-
except subprocess.TimeoutExpired:
|
|
70
|
-
error_type = "timeout"
|
|
71
|
-
error = f"timeout after {args.timeout}s"
|
|
72
|
-
except (OSError, ValueError, json.JSONDecodeError) as exc:
|
|
73
|
-
error_type = "catalog"
|
|
74
|
-
error = str(exc)
|
|
75
|
-
except RuntimeError as exc:
|
|
76
|
-
error_type = "cli"
|
|
77
|
-
error = str(exc)
|
|
78
|
-
|
|
79
|
-
print(json.dumps({
|
|
80
|
-
"ok": False,
|
|
81
|
-
"transport": "delta-cli",
|
|
82
|
-
"catalog": kind,
|
|
83
|
-
"tool": args.endpoints,
|
|
84
|
-
"error_type": error_type,
|
|
85
|
-
"elapsed_seconds": round(time.perf_counter() - started, 3),
|
|
86
|
-
"error": error[:2000],
|
|
87
|
-
}, ensure_ascii=False))
|
|
88
|
-
return 1
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if __name__ == "__main__":
|
|
92
|
-
sys.exit(main())
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Read the authoritative Delta Science catalog through delta-cli."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
import time
|
|
12
|
+
|
|
13
|
+
from invoke import _parse_cli_error, _resolve_cli, _runtime_config
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _parser() -> argparse.ArgumentParser:
|
|
17
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
18
|
+
action = parser.add_mutually_exclusive_group(required=True)
|
|
19
|
+
action.add_argument("--tools", action="store_true")
|
|
20
|
+
action.add_argument("--endpoints", metavar="TOOL")
|
|
21
|
+
parser.add_argument("--cli")
|
|
22
|
+
parser.add_argument("--science-base-url")
|
|
23
|
+
parser.add_argument("--timeout", type=float, default=30.0)
|
|
24
|
+
return parser
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def main() -> int:
|
|
28
|
+
args = _parser().parse_args()
|
|
29
|
+
started = time.perf_counter()
|
|
30
|
+
kind = "tools" if args.tools else "endpoints"
|
|
31
|
+
try:
|
|
32
|
+
runtime = _runtime_config()
|
|
33
|
+
cli = _resolve_cli(args.cli, runtime)
|
|
34
|
+
env = os.environ.copy()
|
|
35
|
+
base_url = args.science_base_url or runtime.get("science_base_url")
|
|
36
|
+
if base_url:
|
|
37
|
+
env["DELTA_INFRA_SCIENCE_BASE_URL"] = str(base_url)
|
|
38
|
+
|
|
39
|
+
command = [cli, "science", "list"]
|
|
40
|
+
if args.endpoints:
|
|
41
|
+
command = [cli, "science", "endpoints", "list", args.endpoints]
|
|
42
|
+
completed = subprocess.run(
|
|
43
|
+
command,
|
|
44
|
+
capture_output=True,
|
|
45
|
+
text=True,
|
|
46
|
+
encoding="utf-8",
|
|
47
|
+
errors="replace",
|
|
48
|
+
env=env,
|
|
49
|
+
timeout=args.timeout,
|
|
50
|
+
check=False,
|
|
51
|
+
)
|
|
52
|
+
if completed.returncode != 0:
|
|
53
|
+
error_type, detail = _parse_cli_error(completed)
|
|
54
|
+
raise RuntimeError(f"{error_type}: {detail}")
|
|
55
|
+
root = json.loads(completed.stdout)
|
|
56
|
+
if not isinstance(root, dict) or root.get("ok") is not True:
|
|
57
|
+
raise RuntimeError(json.dumps(root, ensure_ascii=False))
|
|
58
|
+
if "data" not in root:
|
|
59
|
+
raise RuntimeError("CLI success envelope is missing data")
|
|
60
|
+
print(json.dumps({
|
|
61
|
+
"ok": True,
|
|
62
|
+
"transport": "delta-cli",
|
|
63
|
+
"catalog": kind,
|
|
64
|
+
"tool": args.endpoints,
|
|
65
|
+
"elapsed_seconds": round(time.perf_counter() - started, 3),
|
|
66
|
+
"native": root["data"],
|
|
67
|
+
}, ensure_ascii=False))
|
|
68
|
+
return 0
|
|
69
|
+
except subprocess.TimeoutExpired:
|
|
70
|
+
error_type = "timeout"
|
|
71
|
+
error = f"timeout after {args.timeout}s"
|
|
72
|
+
except (OSError, ValueError, json.JSONDecodeError) as exc:
|
|
73
|
+
error_type = "catalog"
|
|
74
|
+
error = str(exc)
|
|
75
|
+
except RuntimeError as exc:
|
|
76
|
+
error_type = "cli"
|
|
77
|
+
error = str(exc)
|
|
78
|
+
|
|
79
|
+
print(json.dumps({
|
|
80
|
+
"ok": False,
|
|
81
|
+
"transport": "delta-cli",
|
|
82
|
+
"catalog": kind,
|
|
83
|
+
"tool": args.endpoints,
|
|
84
|
+
"error_type": error_type,
|
|
85
|
+
"elapsed_seconds": round(time.perf_counter() - started, 3),
|
|
86
|
+
"error": error[:2000],
|
|
87
|
+
}, ensure_ascii=False))
|
|
88
|
+
return 1
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == "__main__":
|
|
92
|
+
sys.exit(main())
|