Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions unilabos/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,69 @@ def parse_args():
default="",
help="Workflow description, used when publishing the workflow",
)

# package subcommand: 社区设备包 inspect / upload
package_parser = subparsers.add_parser(
"package",
aliases=["pkg"],
help="Community device package tools: inspect / upload / install",
)
package_actions = package_parser.add_subparsers(
title="package actions", dest="package_action"
)
for action_name in ("inspect", "upload"):
action_parser = package_actions.add_parser(
action_name,
help=(
"Scan package dir and generate package_info/archive (local only)"
if action_name == "inspect"
else "Inspect then upload archive + package_info to backend /lab/resource"
),
)
action_parser.add_argument(
"--path",
dest="package_path",
type=str,
required=True,
help="Path to the community device package directory (contains pyproject.toml)",
)
action_parser.add_argument(
"--namespace",
type=str,
default=None,
help="Class namespace, e.g. community.acme; defaults to community.<normalized pyproject name>",
)
action_parser.add_argument(
"--out",
type=str,
default=None,
help="Output dir for archive/package_info.json (default: <package>/../dist)",
)
if action_name == "upload":
action_parser.add_argument(
"--download-url",
dest="download_url",
type=str,
default="",
help="Explicit reachable archive URL (skips OSS upload; handy for local static server)",
)

# install:开发者本地调试入口
install_parser = package_actions.add_parser(
"install",
help="Install a pip spec / git URL locally (uv pip > pip), then scan @device IDs",
)
install_parser.add_argument(
"install_spec",
type=str,
help="pip spec (name==version / name) or git URL (git+https://...)",
)
install_parser.add_argument(
"--no-inspect",
dest="no_inspect",
action="store_true",
help="Skip post-install @device scan / device listing",
)
return parser


Expand Down Expand Up @@ -509,6 +572,25 @@ def main():
print_status("传入了sk参数,优先采用传入参数!", "info")
BasicConfig.working_dir = working_dir

# package 子命令:在配置/鉴权就绪后尽早处理,不进入设备 bootstrap
if args_dict.get("command") in ("package", "pkg"):
from unilabos.app.package_cli import PackageCLIError, cmd_package

package_http_client = None
if args_dict.get("package_action") == "upload":
if not (BasicConfig.ak and BasicConfig.sk):
print_status("package upload 需要 --ak/--sk 鉴权信息", "error")
os._exit(1)
from unilabos.app.web import http_client as _http_client_for_package

package_http_client = _http_client_for_package
try:
cmd_package(args_dict, http_client=package_http_client)
except PackageCLIError as exc:
print_status(str(exc), "error")
os._exit(1)
return

workflow_upload = args_dict.get("command") in ("workflow_upload", "wf")

# 使用远程资源启动
Expand Down
Loading