simulo 0.13.2__tar.gz → 0.15.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simulo-0.13.2/src/simulo.egg-info → simulo-0.15.0}/PKG-INFO +3 -3
- {simulo-0.13.2 → simulo-0.15.0}/PYPI.md +1 -1
- {simulo-0.13.2 → simulo-0.15.0}/pyproject.toml +2 -2
- simulo-0.15.0/src/simulo/_client/_entrypoint.py +313 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/app.py +312 -60
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/bundle.py +40 -3
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/cli.py +311 -30
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/manifest.py +8 -2
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/packaging.py +3 -0
- simulo-0.15.0/src/simulo/_client/runtime.py +185 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/templates/inference/app.py.tmpl +6 -70
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/templates/scenario/app.py.tmpl +8 -33
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/templates/training/app.py.tmpl +8 -34
- {simulo-0.13.2 → simulo-0.15.0/src/simulo.egg-info}/PKG-INFO +3 -3
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo.egg-info/requires.txt +1 -1
- simulo-0.13.2/src/simulo/_client/_entrypoint.py +0 -104
- simulo-0.13.2/src/simulo/_client/runtime.py +0 -90
- {simulo-0.13.2 → simulo-0.15.0}/MANIFEST.in +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/setup.cfg +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/__init__.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/__init__.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/_mounts.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/_runner.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/asset.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/asset_api.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/asset_package.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/asset_pins.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/builtin_aliases.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/cancel_api.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/config.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/credentials.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/discovery.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/http.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/jobs_api.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/learning.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/login.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/mode.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/registry.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/runtime_display.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/seed_ref.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/stub.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/submit_api.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/templates/__init__.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/templates/inference/simuloignore.tmpl +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/templates/scenario/simuloignore.tmpl +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/templates/training/simuloignore.tmpl +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/view_session_api.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/_client/volume.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/callbacks.py +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo/py.typed +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo.egg-info/SOURCES.txt +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo.egg-info/dependency_links.txt +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo.egg-info/entry_points.txt +0 -0
- {simulo-0.13.2 → simulo-0.15.0}/src/simulo.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simulo
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.15.0
|
|
4
4
|
Summary: Simulo SDK and CLI — define robotics simulation and training apps in Python and run them on the Simulo cloud.
|
|
5
5
|
Author-email: Simulo Team <team@simulo.ai>
|
|
6
6
|
License: BSD-3-Clause
|
|
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
15
15
|
Classifier: Typing :: Typed
|
|
16
16
|
Requires-Python: >=3.11
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
|
-
Requires-Dist: simulo-interfaces<0.
|
|
18
|
+
Requires-Dist: simulo-interfaces<0.8,>=0.7
|
|
19
19
|
Requires-Dist: mcap<2,>=1.3
|
|
20
20
|
Requires-Dist: defusedxml>=0.7.1
|
|
21
21
|
Requires-Dist: usd-core<27,>=25.5
|
|
@@ -83,7 +83,7 @@ def hello(name: str = "world", repeat: int = 3) -> dict:
|
|
|
83
83
|
return {"greeting": f"hello, {name}", "repeat": repeat}
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
@app.
|
|
86
|
+
@app.entrypoint
|
|
87
87
|
def main(name: str = "world", repeat: int = 3) -> None:
|
|
88
88
|
handle = hello.spawn(name=name, repeat=repeat)
|
|
89
89
|
print(f"Submitted job: {handle.job_name}")
|
|
@@ -47,7 +47,7 @@ def hello(name: str = "world", repeat: int = 3) -> dict:
|
|
|
47
47
|
return {"greeting": f"hello, {name}", "repeat": repeat}
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
@app.
|
|
50
|
+
@app.entrypoint
|
|
51
51
|
def main(name: str = "world", repeat: int = 3) -> None:
|
|
52
52
|
handle = hello.spawn(name=name, repeat=repeat)
|
|
53
53
|
print(f"Submitted job: {handle.job_name}")
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "simulo"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.15.0"
|
|
8
8
|
description = "Simulo SDK and CLI — define robotics simulation and training apps in Python and run them on the Simulo cloud."
|
|
9
9
|
readme = "PYPI.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -26,7 +26,7 @@ classifiers = [
|
|
|
26
26
|
# mcap: used by `simulo recordings` to read back a downloaded recording and
|
|
27
27
|
# verify it (message count) — MIT-licensed, deps only lz4+zstandard.
|
|
28
28
|
dependencies = [
|
|
29
|
-
"simulo-interfaces>=0.
|
|
29
|
+
"simulo-interfaces>=0.7,<0.8",
|
|
30
30
|
"mcap>=1.3,<2",
|
|
31
31
|
# Hardened XML parsing for URDF ingestion (USD Asset Catalogs, PR-12 fix
|
|
32
32
|
# loop 2, security NIT): stdlib xml.etree.ElementTree relies on
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"""Map ``simulo run`` command-line arguments onto a function's signature.
|
|
2
|
+
|
|
3
|
+
Two submit paths share this module's introspection, pointed at different
|
|
4
|
+
targets:
|
|
5
|
+
|
|
6
|
+
* **The entrypoint path** — ``simulo run app.py`` maps ``--flag value``
|
|
7
|
+
arguments onto the registered ``@app.entrypoint``'s parameters and
|
|
8
|
+
invokes it; the entrypoint's own ``spawn()`` calls end at exactly one
|
|
9
|
+
submit (:func:`run_entrypoint` / :func:`parse_args`). (A direct ``python
|
|
10
|
+
app.py`` never reaches this module: :meth:`App.entrypoint` prints the
|
|
11
|
+
exact equivalent ``simulo run`` command to stderr and exits 2.)
|
|
12
|
+
* **The no-entrypoint path** — with no ``@app.entrypoint`` declared, the
|
|
13
|
+
CLI maps the same ``--flag value`` arguments directly onto the chosen
|
|
14
|
+
``@app.job``'s own signature (:func:`parse_explicit_args`) and spawns it.
|
|
15
|
+
Only EXPLICITLY-passed flags are returned there: a defaulted-but-unpassed
|
|
16
|
+
parameter must stay out of the submitted ``args`` so an upgraded client
|
|
17
|
+
submits the byte-identical package (same ``canonical_args`` → same
|
|
18
|
+
``package_id``) for the no-flags case it always produced ``args={}`` for.
|
|
19
|
+
|
|
20
|
+
An argument parser is built from the target's signature: each parameter
|
|
21
|
+
``foo_bar`` becomes ``--foo-bar`` (dash for underscore), coerced from the
|
|
22
|
+
parameter's default type, then its annotation. A parameter without a default is
|
|
23
|
+
required. This keeps authoring frictionless — ``def main(num_envs: int = 4096)``
|
|
24
|
+
just works as ``--num-envs 4096`` — with no argparse boilerplate in the app file.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import argparse
|
|
30
|
+
import inspect
|
|
31
|
+
import types
|
|
32
|
+
import typing
|
|
33
|
+
from typing import Any, Callable, Collection, Mapping, Optional, Sequence
|
|
34
|
+
|
|
35
|
+
_STR_TO_TYPE: Mapping[str, type] = {"int": int, "float": float, "bool": bool, "str": str}
|
|
36
|
+
|
|
37
|
+
_SKIP_KINDS = (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD)
|
|
38
|
+
|
|
39
|
+
#: The only types a ``--flag value`` string can be conclusively coerced to.
|
|
40
|
+
_SCALAR_TYPES: tuple[type, ...] = (int, float, bool, str)
|
|
41
|
+
|
|
42
|
+
#: Sentinel default for :func:`parse_explicit_args`'s parser: a parameter whose
|
|
43
|
+
#: parsed value is still this object was never passed on the command line, so it
|
|
44
|
+
#: is omitted from the returned kwargs (the job body applies its own default at
|
|
45
|
+
#: execution). ``None`` cannot play this role — it is a legitimate flag value.
|
|
46
|
+
_UNSET: Any = object()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _param_type(param: inspect.Parameter) -> type:
|
|
50
|
+
"""Best-effort scalar type for a parameter: default's type, then annotation.
|
|
51
|
+
|
|
52
|
+
A concrete (non-``None``) default is the most reliable signal — ``= 4096``
|
|
53
|
+
means ``int``. Otherwise fall back to the annotation (a real type, or a PEP
|
|
54
|
+
563 string like ``"int"``). Defaults to ``str`` when nothing is conclusive.
|
|
55
|
+
"""
|
|
56
|
+
default = param.default
|
|
57
|
+
if default is not inspect.Parameter.empty and default is not None:
|
|
58
|
+
return type(default)
|
|
59
|
+
ann = param.annotation
|
|
60
|
+
if isinstance(ann, type):
|
|
61
|
+
return ann
|
|
62
|
+
if isinstance(ann, str):
|
|
63
|
+
return _STR_TO_TYPE.get(ann, str)
|
|
64
|
+
return str
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _str_to_bool(raw: str) -> bool:
|
|
68
|
+
"""Parse a CLI ``--flag value`` boolean (``true``/``1``/``yes`` → ``True``)."""
|
|
69
|
+
lowered = raw.strip().lower()
|
|
70
|
+
if lowered in ("true", "1", "yes", "y", "on"):
|
|
71
|
+
return True
|
|
72
|
+
if lowered in ("false", "0", "no", "n", "off"):
|
|
73
|
+
return False
|
|
74
|
+
raise argparse.ArgumentTypeError(f"expected a boolean (true/false), got {raw!r}")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def flag_for_param(name: str) -> str:
|
|
78
|
+
"""The ``--flag`` a signature parameter ``name`` maps to (dash for underscore)."""
|
|
79
|
+
return "--" + name.replace("_", "-")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def mappable_params(fn: Callable[..., object]) -> list[tuple[str, inspect.Parameter]]:
|
|
83
|
+
"""The parameters :func:`build_parser` maps to ``--flags``.
|
|
84
|
+
|
|
85
|
+
``VAR_POSITIONAL`` (``*args``) and ``VAR_KEYWORD`` (``**kwargs``) are
|
|
86
|
+
skipped, exactly as ``build_parser`` skips them — signature guards must use
|
|
87
|
+
the same filter, or a harmless ``def train(**job)`` would be rejected for a
|
|
88
|
+
flag it never gets.
|
|
89
|
+
"""
|
|
90
|
+
return [(name, param) for name, param in inspect.signature(fn).parameters.items() if param.kind not in _SKIP_KINDS]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _strip_optional_annotation(ann: Any) -> Any:
|
|
94
|
+
"""Unwrap ``Optional[X]`` / ``X | None`` / ``Union[X, None]`` to ``X``.
|
|
95
|
+
|
|
96
|
+
Handles both representations of each spelling: under ``from __future__
|
|
97
|
+
import annotations`` (which every shipped scaffold enables) an annotation
|
|
98
|
+
is a STRING like ``"int | None"``, ``"Optional[int]"``, or
|
|
99
|
+
``"Union[int, None]"``; without it, a typing object (whose ``Optional``
|
|
100
|
+
and ``Union`` spellings are the same object, handled by ``get_origin``).
|
|
101
|
+
All are common, deliberate ways to declare "this scalar, or unset" — the
|
|
102
|
+
wrapper must not hide the scalar, and no SPELLING may work in one
|
|
103
|
+
representation and fail in the other. Anything that is not exactly "one
|
|
104
|
+
type or None" is returned unchanged.
|
|
105
|
+
"""
|
|
106
|
+
if isinstance(ann, str):
|
|
107
|
+
text = ann.strip()
|
|
108
|
+
if text.startswith("typing."):
|
|
109
|
+
text = text[len("typing.") :]
|
|
110
|
+
if text.startswith("Optional[") and text.endswith("]"):
|
|
111
|
+
return text[len("Optional[") : -1].strip()
|
|
112
|
+
if text.startswith("Union[") and text.endswith("]"):
|
|
113
|
+
# Naive comma split is safe here: a nested generic like
|
|
114
|
+
# "Union[dict[str, int], None]" yields 3 parts and falls through
|
|
115
|
+
# unchanged — its inner type is not a scalar anyway.
|
|
116
|
+
parts = [part.strip() for part in text[len("Union[") : -1].split(",")]
|
|
117
|
+
non_none = [part for part in parts if part != "None"]
|
|
118
|
+
if len(parts) == 2 and len(non_none) == 1:
|
|
119
|
+
return non_none[0]
|
|
120
|
+
return ann
|
|
121
|
+
if "|" in text:
|
|
122
|
+
parts = [part.strip() for part in text.split("|")]
|
|
123
|
+
non_none = [part for part in parts if part != "None"]
|
|
124
|
+
if len(parts) == 2 and len(non_none) == 1:
|
|
125
|
+
return non_none[0]
|
|
126
|
+
return ann
|
|
127
|
+
origin = typing.get_origin(ann)
|
|
128
|
+
if origin is typing.Union or origin is types.UnionType:
|
|
129
|
+
args = [arg for arg in typing.get_args(ann) if arg is not type(None)]
|
|
130
|
+
if len(args) == 1:
|
|
131
|
+
return args[0]
|
|
132
|
+
return ann
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def conclusive_param_type(param: inspect.Parameter) -> Optional[type]:
|
|
136
|
+
"""The scalar type a ``--flag`` value is conclusively coerced to, or ``None``.
|
|
137
|
+
|
|
138
|
+
Unlike :func:`_param_type` — whose ``str`` FALLBACK is fine for an
|
|
139
|
+
entrypoint (the entrypoint body runs client-side and can fix things up) —
|
|
140
|
+
the no-entrypoint job path submits the coerced value straight into the
|
|
141
|
+
job's ``args``, so a guess is a silent wrong submission: ``tags: list = []``
|
|
142
|
+
would coerce ``--tags release`` through ``list("release")`` into
|
|
143
|
+
``["r", "e", "l", ...]``, and a ``Path``/``set``/enum value would crash
|
|
144
|
+
``json.dumps`` at manifest time. ``None`` here means "reject at submit".
|
|
145
|
+
|
|
146
|
+
Conclusive: a non-``None`` scalar default (its type), or an ``int`` /
|
|
147
|
+
``float`` / ``bool`` / ``str`` annotation — real type, PEP 563 string, or
|
|
148
|
+
either wrapped in ``Optional[...]`` / ``| None``. An unannotated parameter
|
|
149
|
+
stays ``str`` (the documented text fallback, unchanged from the entrypoint
|
|
150
|
+
convention).
|
|
151
|
+
"""
|
|
152
|
+
default = param.default
|
|
153
|
+
if default is not inspect.Parameter.empty and default is not None:
|
|
154
|
+
return type(default) if type(default) in _SCALAR_TYPES else None
|
|
155
|
+
ann = param.annotation
|
|
156
|
+
if ann is inspect.Parameter.empty:
|
|
157
|
+
return str
|
|
158
|
+
ann = _strip_optional_annotation(ann)
|
|
159
|
+
if isinstance(ann, type) and ann in _SCALAR_TYPES:
|
|
160
|
+
return ann
|
|
161
|
+
if isinstance(ann, str) and ann in _STR_TO_TYPE:
|
|
162
|
+
return _STR_TO_TYPE[ann]
|
|
163
|
+
return None
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def unmappable_params(fn: Callable[..., object]) -> list[tuple[str, str, str, bool]]:
|
|
167
|
+
"""``(name, kind, why, has_default)`` for parameters the CLI cannot map.
|
|
168
|
+
|
|
169
|
+
``kind`` is ``"positional-only"`` (the worker executes ``fn(**args)``, so a
|
|
170
|
+
keyword can never reach it) or ``"type"`` (no conclusive scalar coercion —
|
|
171
|
+
see :func:`conclusive_param_type`).
|
|
172
|
+
|
|
173
|
+
``has_default`` is the caller's rejection policy input: without a default
|
|
174
|
+
the parameter is required-but-unmappable — the submit can never succeed, so
|
|
175
|
+
it is rejected always. WITH a default the defaults-only submit works today
|
|
176
|
+
(``fn(**{})`` never touches the parameter), so callers reject only when a
|
|
177
|
+
flag actually targets it — a blanket rejection would break submits that
|
|
178
|
+
work on shipped 0.14.x clients.
|
|
179
|
+
"""
|
|
180
|
+
result: list[tuple[str, str, str, bool]] = []
|
|
181
|
+
for name, param in mappable_params(fn):
|
|
182
|
+
has_default = param.default is not inspect.Parameter.empty
|
|
183
|
+
if param.kind is inspect.Parameter.POSITIONAL_ONLY:
|
|
184
|
+
result.append((name, "positional-only", "declared positional-only (before a '/')", has_default))
|
|
185
|
+
continue
|
|
186
|
+
if conclusive_param_type(param) is not None:
|
|
187
|
+
continue
|
|
188
|
+
if param.default is not inspect.Parameter.empty and param.default is not None:
|
|
189
|
+
why = f"default {param.default!r} of non-scalar type {type(param.default).__name__}"
|
|
190
|
+
elif param.annotation is not inspect.Parameter.empty:
|
|
191
|
+
why = f"annotation {param.annotation!r} is not a scalar type"
|
|
192
|
+
else: # pragma: no cover - unreachable: no annotation + no default resolves to str
|
|
193
|
+
why = "no usable type"
|
|
194
|
+
result.append((name, "type", why, has_default))
|
|
195
|
+
return result
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def build_parser(
|
|
199
|
+
fn: Callable[..., object],
|
|
200
|
+
*,
|
|
201
|
+
sentinel_defaults: bool = False,
|
|
202
|
+
prog: Optional[str] = None,
|
|
203
|
+
exclude: Collection[str] = (),
|
|
204
|
+
) -> argparse.ArgumentParser:
|
|
205
|
+
"""Build an ``argparse`` parser from a function's signature.
|
|
206
|
+
|
|
207
|
+
With ``sentinel_defaults=False`` (the entrypoint path — behavior unchanged),
|
|
208
|
+
a defaulted parameter's parser default is the signature's own default, so
|
|
209
|
+
``parse_args`` yields EVERY parameter, and values coerce via
|
|
210
|
+
:func:`_param_type` (``str`` fallback included). With
|
|
211
|
+
``sentinel_defaults=True`` (the no-entrypoint job path), defaulted
|
|
212
|
+
parameters default to the private ``_UNSET`` sentinel instead — so
|
|
213
|
+
:func:`parse_explicit_args` can tell an explicitly-passed flag from an
|
|
214
|
+
untouched default — and values coerce via :func:`conclusive_param_type`
|
|
215
|
+
(callers must have rejected inconclusive signatures first). ``prog`` names
|
|
216
|
+
the parser in ``-h`` output (e.g. ``"simulo run app.py"``); default is the
|
|
217
|
+
function's own name, as before.
|
|
218
|
+
|
|
219
|
+
``exclude`` drops the named parameters from the parser entirely — the
|
|
220
|
+
no-entrypoint path passes its DEFERRED unmappable-but-defaulted parameters
|
|
221
|
+
here (see :func:`unmappable_params`), so a flag targeting one — even via
|
|
222
|
+
an argparse abbreviation the caller's exact-token scan cannot see — fails
|
|
223
|
+
at submit as an unrecognized argument rather than being mis-parsed.
|
|
224
|
+
"""
|
|
225
|
+
sig = inspect.signature(fn)
|
|
226
|
+
doc = (inspect.getdoc(fn) or "").strip().splitlines()
|
|
227
|
+
parser = argparse.ArgumentParser(
|
|
228
|
+
prog=prog if prog is not None else getattr(fn, "__name__", "entrypoint"),
|
|
229
|
+
description=doc[0] if doc else None,
|
|
230
|
+
)
|
|
231
|
+
for name, param in sig.parameters.items():
|
|
232
|
+
if param.kind in _SKIP_KINDS or name in exclude:
|
|
233
|
+
continue
|
|
234
|
+
flag = flag_for_param(name)
|
|
235
|
+
required = param.default is inspect.Parameter.empty
|
|
236
|
+
if required:
|
|
237
|
+
default = None
|
|
238
|
+
elif sentinel_defaults:
|
|
239
|
+
default = _UNSET
|
|
240
|
+
else:
|
|
241
|
+
default = param.default
|
|
242
|
+
if sentinel_defaults:
|
|
243
|
+
resolved = conclusive_param_type(param)
|
|
244
|
+
typ = resolved if resolved is not None else _param_type(param)
|
|
245
|
+
else:
|
|
246
|
+
typ = _param_type(param)
|
|
247
|
+
if typ is bool:
|
|
248
|
+
parser.add_argument(
|
|
249
|
+
flag,
|
|
250
|
+
dest=name,
|
|
251
|
+
type=_str_to_bool,
|
|
252
|
+
required=required,
|
|
253
|
+
default=default,
|
|
254
|
+
metavar="BOOL",
|
|
255
|
+
)
|
|
256
|
+
else:
|
|
257
|
+
parser.add_argument(
|
|
258
|
+
flag,
|
|
259
|
+
dest=name,
|
|
260
|
+
type=typ,
|
|
261
|
+
required=required,
|
|
262
|
+
default=default,
|
|
263
|
+
)
|
|
264
|
+
return parser
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def parse_args(fn: Callable[..., object], argv: Sequence[str]) -> dict[str, Any]:
|
|
268
|
+
"""Parse ``argv`` against ``fn``'s signature into a keyword-argument dict."""
|
|
269
|
+
parser = build_parser(fn)
|
|
270
|
+
namespace = parser.parse_args(list(argv))
|
|
271
|
+
sig = inspect.signature(fn)
|
|
272
|
+
kwargs: dict[str, Any] = {}
|
|
273
|
+
for name, param in sig.parameters.items():
|
|
274
|
+
if param.kind in _SKIP_KINDS:
|
|
275
|
+
continue
|
|
276
|
+
kwargs[name] = getattr(namespace, name)
|
|
277
|
+
return kwargs
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def parse_explicit_args(
|
|
281
|
+
fn: Callable[..., object],
|
|
282
|
+
argv: Sequence[str],
|
|
283
|
+
*,
|
|
284
|
+
prog: Optional[str] = None,
|
|
285
|
+
exclude: Collection[str] = (),
|
|
286
|
+
) -> dict[str, Any]:
|
|
287
|
+
"""Parse ``argv`` against ``fn``'s signature; return ONLY explicitly-passed kwargs.
|
|
288
|
+
|
|
289
|
+
The no-entrypoint submit path maps CLI flags onto a ``@app.job``'s own
|
|
290
|
+
signature with this: a parameter the user did not pass stays OUT of the
|
|
291
|
+
returned dict (the job body applies its own default on the worker), so the
|
|
292
|
+
no-flags case still submits ``args={}`` — exactly what pre-mapping clients
|
|
293
|
+
always submitted — and ``package_id`` is unchanged across the upgrade.
|
|
294
|
+
A parameter without a default is required, exactly as on the entrypoint
|
|
295
|
+
path. ``exclude`` names parameters left out of the parser and the result
|
|
296
|
+
(the deferred unmappable-but-defaulted ones — see :func:`build_parser`).
|
|
297
|
+
"""
|
|
298
|
+
parser = build_parser(fn, sentinel_defaults=True, prog=prog, exclude=exclude)
|
|
299
|
+
namespace = parser.parse_args(list(argv))
|
|
300
|
+
sig = inspect.signature(fn)
|
|
301
|
+
kwargs: dict[str, Any] = {}
|
|
302
|
+
for name, param in sig.parameters.items():
|
|
303
|
+
if param.kind in _SKIP_KINDS or name in exclude:
|
|
304
|
+
continue
|
|
305
|
+
value = getattr(namespace, name)
|
|
306
|
+
if value is not _UNSET:
|
|
307
|
+
kwargs[name] = value
|
|
308
|
+
return kwargs
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def run_entrypoint(fn: Callable[..., object], argv: Sequence[str]) -> object:
|
|
312
|
+
"""Parse ``argv`` for ``fn`` and invoke it (the single submit happens inside)."""
|
|
313
|
+
return fn(**parse_args(fn, argv))
|