aether-mobile 0.8.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.
- aether/__init__.py +16 -0
- aether/__main__.py +3 -0
- aether/android_compatibility.json +107 -0
- aether/android_profile.py +44 -0
- aether/bundle.py +260 -0
- aether/cli.py +246 -0
- aether/compatibility.py +467 -0
- aether/models.py +472 -0
- aether/native_ops.py +1367 -0
- aether/pipeline.py +441 -0
- aether/preview.py +388 -0
- aether/scaffold.py +255 -0
- aether/schema.py +261 -0
- aether/targets.py +137 -0
- aether_mobile-0.8.0.dist-info/METADATA +309 -0
- aether_mobile-0.8.0.dist-info/RECORD +20 -0
- aether_mobile-0.8.0.dist-info/WHEEL +5 -0
- aether_mobile-0.8.0.dist-info/entry_points.txt +2 -0
- aether_mobile-0.8.0.dist-info/licenses/LICENSE +190 -0
- aether_mobile-0.8.0.dist-info/top_level.txt +1 -0
aether/cli.py
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"""Command-line tools for local pipeline work."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from contextlib import contextmanager, redirect_stdout
|
|
5
|
+
import importlib.util
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
import sys
|
|
10
|
+
from tempfile import TemporaryDirectory
|
|
11
|
+
|
|
12
|
+
from .bundle import read_manifest
|
|
13
|
+
from .compatibility import TARGET, finding, load_contract
|
|
14
|
+
from .pipeline import Pipeline
|
|
15
|
+
from .schema import PipelineError, check_key
|
|
16
|
+
from .targets import check_bundle, check_pipeline, definition_error, failure_report, preflight
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _load_pipeline(definition):
|
|
20
|
+
path = Path(definition).resolve()
|
|
21
|
+
if path.suffix != ".py" or not path.is_file():
|
|
22
|
+
raise PipelineError("Supply a Python file that defines a variable named pipeline.")
|
|
23
|
+
check_key(path.stem)
|
|
24
|
+
if path.stem in sys.modules:
|
|
25
|
+
raise PipelineError("Choose a definition filename that does not shadow an imported module.")
|
|
26
|
+
cwd = str(Path.cwd())
|
|
27
|
+
if cwd not in sys.path:
|
|
28
|
+
sys.path.insert(0, cwd)
|
|
29
|
+
parent = str(path.parent)
|
|
30
|
+
if parent not in sys.path:
|
|
31
|
+
sys.path.insert(0, parent)
|
|
32
|
+
spec = importlib.util.spec_from_file_location(path.stem, path)
|
|
33
|
+
module = importlib.util.module_from_spec(spec)
|
|
34
|
+
sys.modules[path.stem] = module
|
|
35
|
+
spec.loader.exec_module(module)
|
|
36
|
+
pipeline = getattr(module, "pipeline", None)
|
|
37
|
+
if not isinstance(pipeline, Pipeline):
|
|
38
|
+
raise PipelineError("Define a Pipeline instance named pipeline.")
|
|
39
|
+
return pipeline
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@contextmanager
|
|
43
|
+
def _project_bundle(path, target):
|
|
44
|
+
if path.suffix.lower() == ".aether":
|
|
45
|
+
yield path
|
|
46
|
+
elif path.suffix.lower() == ".py":
|
|
47
|
+
with TemporaryDirectory() as directory:
|
|
48
|
+
yield _load_pipeline(path).package(Path(directory) / "project.aether", target=target)
|
|
49
|
+
else:
|
|
50
|
+
raise PipelineError("Supply a .py pipeline definition or a .aether bundle.")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _check(args):
|
|
54
|
+
if (args.device_api is None) != (not args.device_abi):
|
|
55
|
+
return failure_report(args.target, "device.incomplete", "device", "Supply both Android API and ABI.",
|
|
56
|
+
"Use --device-api and --device-abi together, or omit both for an app-only check.")
|
|
57
|
+
device = {"api": args.device_api, "abis": args.device_abi} if args.device_api is not None else None
|
|
58
|
+
if args.project.suffix.lower() == ".aether":
|
|
59
|
+
return check_bundle(args.project, args.target, device=device)[1]
|
|
60
|
+
try:
|
|
61
|
+
pipeline = _load_pipeline(args.project)
|
|
62
|
+
except Exception as error:
|
|
63
|
+
return definition_error(args.target, error)
|
|
64
|
+
report = check_pipeline(pipeline, args.target, device=device)
|
|
65
|
+
if args.static_only or not report["compatible"] or not any(example.expected is not None for example in pipeline.examples):
|
|
66
|
+
return report
|
|
67
|
+
try:
|
|
68
|
+
examples = pipeline.check()
|
|
69
|
+
report["examples"] = [{"index": index, "passed": result["passed"], "elapsed_ms": result["elapsed_ms"]}
|
|
70
|
+
for index, result in enumerate(examples, start=1)]
|
|
71
|
+
passed = all(result["passed"] for result in examples)
|
|
72
|
+
except (PipelineError, OSError, ImportError, ValueError):
|
|
73
|
+
passed = False
|
|
74
|
+
if not passed:
|
|
75
|
+
report["compatible"] = False
|
|
76
|
+
report["findings"].append(finding("example.desktop_failed", "unsupported", "examples",
|
|
77
|
+
"A desktop reference example failed.", "Run the example locally and correct the expected result or model."))
|
|
78
|
+
return report
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _print_check(report, as_json):
|
|
82
|
+
if as_json:
|
|
83
|
+
print(json.dumps(report, indent=2))
|
|
84
|
+
return
|
|
85
|
+
print(f"Android compatibility {report['target'] or 'unknown target'}")
|
|
86
|
+
if report["runtime"]:
|
|
87
|
+
runtime = report["runtime"]
|
|
88
|
+
print(f"Runtime {runtime['id']} {runtime['version']}. {runtime['reason']}")
|
|
89
|
+
for item in report["findings"]:
|
|
90
|
+
print(f"[{item['status']}] {item['component']} ({item['code']}). {item['message']}")
|
|
91
|
+
if item["required"] not in (None, "") or item["available"] is not None:
|
|
92
|
+
print(f" Required {item['required'] or 'any installed version'}. Available {item['available']}.")
|
|
93
|
+
if item["suggestion"]:
|
|
94
|
+
print(f" {item['suggestion']}")
|
|
95
|
+
if "examples" in report:
|
|
96
|
+
print(f"Desktop reference examples passed {sum(item['passed'] for item in report['examples'])}/{len(report['examples'])}.")
|
|
97
|
+
print("Compatibility result is " + ("supported." if report["compatible"] else "unsupported."))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def main(argv=None):
|
|
101
|
+
parser = argparse.ArgumentParser(prog="aether", description=__doc__)
|
|
102
|
+
subcommands = parser.add_subparsers(dest="command", required=True)
|
|
103
|
+
package = subcommands.add_parser("package", help="Build a .aether file from a pipeline.")
|
|
104
|
+
package.add_argument("definition", type=Path)
|
|
105
|
+
package.add_argument("-o", "--output", type=Path)
|
|
106
|
+
package.add_argument("--target", default=TARGET, help=f"App target. Use desktop for an explicit legacy archive. Defaults to {TARGET}.")
|
|
107
|
+
run = subcommands.add_parser("run", help="Run a pipeline on this computer.")
|
|
108
|
+
run.add_argument("definition", type=Path)
|
|
109
|
+
run.add_argument("--input", type=Path, required=True, help="JSON file with input values.")
|
|
110
|
+
check = subcommands.add_parser("check", help="Check Android compatibility and desktop reference examples.",
|
|
111
|
+
description="Checks declared requirements. Import inspection cannot prove dynamic Python or native code will run on a phone.")
|
|
112
|
+
check.add_argument("project", type=Path)
|
|
113
|
+
check.add_argument("--target", default=TARGET)
|
|
114
|
+
check.add_argument("--json", action="store_true", help="Print a versioned compatibility report.")
|
|
115
|
+
check.add_argument("--static-only", action="store_true",
|
|
116
|
+
help="Skip desktop examples. Loading a .py definition executes its top-level Python. "
|
|
117
|
+
"Use a .aether bundle to inspect a project as data.")
|
|
118
|
+
check.add_argument("--device-api", type=int, choices=range(1, 1000), metavar="LEVEL")
|
|
119
|
+
check.add_argument("--device-abi", action="append")
|
|
120
|
+
subcommands.add_parser("capabilities", help="Print the current Android compatibility registry as JSON.")
|
|
121
|
+
inspect = subcommands.add_parser("inspect", help="Verify a bundle and show its manifest.")
|
|
122
|
+
inspect.add_argument("bundle", type=Path)
|
|
123
|
+
target_check = subcommands.add_parser("preflight", help="Check a project against an Android app release.")
|
|
124
|
+
target_check.add_argument("project", type=Path)
|
|
125
|
+
target_check.add_argument("--target", default=TARGET, help=f"Installed app target. Defaults to {TARGET}.")
|
|
126
|
+
preview = subcommands.add_parser("preview", help="Package or serve an Android-compatible project by QR.")
|
|
127
|
+
preview.add_argument("project", type=Path)
|
|
128
|
+
preview.add_argument("--target", default=TARGET, help=f"Installed app target. Defaults to {TARGET}.")
|
|
129
|
+
preview.add_argument("--host", help="Laptop IPv4 address. Defaults to the active private interface.")
|
|
130
|
+
preview.add_argument("--port", type=int, default=8765)
|
|
131
|
+
preview.add_argument("--qr-dir", type=Path, default=Path("."))
|
|
132
|
+
preview.add_argument("--seconds", type=int, default=300)
|
|
133
|
+
preview.add_argument("--install-url", help="HTTPS app installation page for the separate install QR.")
|
|
134
|
+
preview.add_argument("--app-url", help="Optional HTTPS handoff page URL for first-time app download before opening AetherML.")
|
|
135
|
+
preview.add_argument("--terminal-qr", action="store_true", help="Render the QR code in the terminal as well.")
|
|
136
|
+
serve_cmd = subcommands.add_parser("serve", help="Check, package, serve, and print the QR in the terminal.")
|
|
137
|
+
serve_cmd.add_argument("project", type=Path)
|
|
138
|
+
serve_cmd.add_argument("--target", default=TARGET, help=f"Installed app target. Defaults to {TARGET}.")
|
|
139
|
+
serve_cmd.add_argument("--host", help="Laptop IPv4 address. Defaults to the active private interface.")
|
|
140
|
+
serve_cmd.add_argument("--port", type=int, default=8765)
|
|
141
|
+
serve_cmd.add_argument("--seconds", type=int, default=300)
|
|
142
|
+
serve_cmd.add_argument("--qr-dir", type=Path, default=None, help="Optional directory to save PNG QR files.")
|
|
143
|
+
serve_cmd.add_argument(
|
|
144
|
+
"--app-url",
|
|
145
|
+
default=os.environ.get("AETHER_APP_URL") or None,
|
|
146
|
+
help="Optional HTTPS landing/handoff URL (or set AETHER_APP_URL).",
|
|
147
|
+
)
|
|
148
|
+
serve_cmd.add_argument("--install-url", help="Optional HTTPS app installation page when --qr-dir is set.")
|
|
149
|
+
serve_cmd.add_argument("--no-terminal-qr", action="store_true", help="Do not print the QR code to stdout.")
|
|
150
|
+
serve_cmd.add_argument("--watch", action="store_true", help="Rebuild and reprint the QR when files change.")
|
|
151
|
+
init_cmd = subcommands.add_parser("init", help="Create a starter train.py and app.py project template.")
|
|
152
|
+
init_cmd.add_argument("directory", nargs="?", type=Path, default=Path("."), help="Target folder (defaults to current directory).")
|
|
153
|
+
init_cmd.add_argument("--runtime", choices=("onnx", "litert"), default="onnx", help="Target mobile runtime.")
|
|
154
|
+
init_cmd.add_argument("--kind", choices=("tabular", "image"), default="tabular", help="Starter pipeline template kind.")
|
|
155
|
+
init_cmd.add_argument("--force", action="store_true", help="Overwrite existing template files.")
|
|
156
|
+
args = parser.parse_args(argv)
|
|
157
|
+
try:
|
|
158
|
+
if args.command == "capabilities":
|
|
159
|
+
print(json.dumps(load_contract(), indent=2))
|
|
160
|
+
return 0
|
|
161
|
+
if args.command == "init":
|
|
162
|
+
from .scaffold import init_project
|
|
163
|
+
|
|
164
|
+
created = init_project(args.directory, runtime=args.runtime, kind=args.kind, force=args.force)
|
|
165
|
+
for path in created:
|
|
166
|
+
print(path)
|
|
167
|
+
return 0
|
|
168
|
+
if args.command == "check":
|
|
169
|
+
if args.json:
|
|
170
|
+
with redirect_stdout(sys.stderr):
|
|
171
|
+
report = _check(args)
|
|
172
|
+
else:
|
|
173
|
+
report = _check(args)
|
|
174
|
+
_print_check(report, args.json)
|
|
175
|
+
return int(not report["compatible"])
|
|
176
|
+
if args.command == "inspect":
|
|
177
|
+
print(json.dumps(read_manifest(args.bundle), indent=2))
|
|
178
|
+
return 0
|
|
179
|
+
if args.command == "serve" and args.watch:
|
|
180
|
+
from .preview import serve_watch
|
|
181
|
+
|
|
182
|
+
serve_watch(
|
|
183
|
+
args.project,
|
|
184
|
+
_load_pipeline,
|
|
185
|
+
args.host,
|
|
186
|
+
args.port,
|
|
187
|
+
args.qr_dir,
|
|
188
|
+
args.seconds,
|
|
189
|
+
args.install_url,
|
|
190
|
+
args.target,
|
|
191
|
+
terminal_qr=not args.no_terminal_qr,
|
|
192
|
+
app_url=args.app_url,
|
|
193
|
+
)
|
|
194
|
+
return 0
|
|
195
|
+
if args.command in ("preflight", "preview", "serve"):
|
|
196
|
+
with _project_bundle(args.project, args.target) as bundle:
|
|
197
|
+
if args.command == "preflight":
|
|
198
|
+
_, report = preflight(bundle, args.target)
|
|
199
|
+
print(json.dumps(report, indent=2))
|
|
200
|
+
elif args.command == "preview":
|
|
201
|
+
from .preview import serve
|
|
202
|
+
|
|
203
|
+
serve(
|
|
204
|
+
bundle,
|
|
205
|
+
args.host,
|
|
206
|
+
args.port,
|
|
207
|
+
args.qr_dir,
|
|
208
|
+
args.seconds,
|
|
209
|
+
args.install_url,
|
|
210
|
+
args.target,
|
|
211
|
+
terminal_qr=args.terminal_qr,
|
|
212
|
+
app_url=args.app_url,
|
|
213
|
+
)
|
|
214
|
+
else:
|
|
215
|
+
from .preview import serve
|
|
216
|
+
|
|
217
|
+
serve(
|
|
218
|
+
bundle,
|
|
219
|
+
args.host,
|
|
220
|
+
args.port,
|
|
221
|
+
args.qr_dir,
|
|
222
|
+
args.seconds,
|
|
223
|
+
args.install_url,
|
|
224
|
+
args.target,
|
|
225
|
+
terminal_qr=not args.no_terminal_qr,
|
|
226
|
+
app_url=args.app_url,
|
|
227
|
+
)
|
|
228
|
+
return 0
|
|
229
|
+
pipeline = _load_pipeline(args.definition)
|
|
230
|
+
if args.command == "package":
|
|
231
|
+
destination = args.output or args.definition.with_suffix(".aether")
|
|
232
|
+
print(pipeline.package(destination, target=None if args.target == "desktop" else args.target))
|
|
233
|
+
else:
|
|
234
|
+
inputs = json.loads(args.input.read_text(encoding="utf-8-sig"))
|
|
235
|
+
print(json.dumps(pipeline.run(inputs), indent=2))
|
|
236
|
+
except (PipelineError, OSError, ImportError, json.JSONDecodeError, SyntaxError) as error:
|
|
237
|
+
response = {"error": str(error)}
|
|
238
|
+
if isinstance(error, PipelineError) and error.events:
|
|
239
|
+
response["events"] = error.events
|
|
240
|
+
if isinstance(error, PipelineError) and error.report:
|
|
241
|
+
response["compatibility"] = error.report
|
|
242
|
+
print(json.dumps(response), file=sys.stderr)
|
|
243
|
+
return 1
|
|
244
|
+
except KeyboardInterrupt:
|
|
245
|
+
return 130
|
|
246
|
+
return 0
|