From 9876463f4cd1266631862aa2aa6adfbdda4bedcb Mon Sep 17 00:00:00 2001 From: Huawei Date: Thu, 9 Jul 2026 19:20:36 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=BB=E6=8E=89=E5=A5=97=E4=BB=B6?= =?UTF-8?q?=E7=BA=A7=E5=86=85=E5=AE=B9=EF=BC=8C=E5=8F=AA=E8=81=9A=E7=84=A6?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E6=9C=AC=E8=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- suites-help/开发者指南/脚本开发指南.md | 37 +++++++++++--------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/suites-help/开发者指南/脚本开发指南.md b/suites-help/开发者指南/脚本开发指南.md index bb11a7b..16bdf92 100644 --- a/suites-help/开发者指南/脚本开发指南.md +++ b/suites-help/开发者指南/脚本开发指南.md @@ -1,17 +1,8 @@ # 脚本开发指南 -## 脚本结构 - -``` -my-suite/ -├── workflow.yaml -└── scripts/ - └── run.py # 主执行文件 -``` - ## 脚本约定 -脚本通过 `PARAMS_FILE` 环境变量获取参数,通过 stdout 输出 JSON 结果。 +`scripts/run.py` 通过环境变量获取参数,通过 stdout 输出 JSON 结果。 ### 接收参数 @@ -21,6 +12,9 @@ import json, os params_file = os.environ.get("PARAMS_FILE", "/tmp/params.json") with open(params_file) as f: params = json.load(f) + +expression = params.get("expression", "1+1") +precision = int(params.get("precision", 2)) ``` ### 输出结果 @@ -30,33 +24,32 @@ result = {"status": "ok", "result": 42, "output_path": "/tmp/output/result.geojs print(json.dumps(result)) ``` -stdout 的 JSON 会被执行器捕获并作为步骤结果写入调度中心。 +stdout 的 JSON 会被执行器捕获并作为步骤结果。 ### 文件输出 -- 输出文件写入 `/tmp/output/`(步骤间共享的目录) -- 执行结束后脚本目录会被自动清理 +- 输出文件写入 `/tmp/output/`(步骤间共享) +- 执行结束后脚本目录自动清理 ## 执行环境 - **基础镜像**:`registry.mercator.cn/agentgis/gis-base:latest` - **包含**:Python 3.11, GDAL, Shapely, GeoPandas, Fiona, PyProj, Rasterio, numpy -- **脚本目录**:挂载到 `/tmp/scripts`(只读) -- **工作目录**:挂载到 `/tmp/output`(读写,步骤间共享) -- **参数文件**:`/tmp/params.json`(只读) +- **脚本路径**:`/tmp/scripts/run.py`(只读) +- **工作目录**:`/tmp/output`(读写,步骤间共享) +- **参数文件**:`/tmp/params.json` ## 错误处理 -脚本退出码非 0 表示执行失败。失败时在 stdout 输出错误信息: +退出码非 0 表示失败: ```python -print(json.dumps({"status": "error", "message": "文件不存在: /data/input.shp"})) +print(json.dumps({"status": "error", "message": "文件不存在"})) sys.exit(1) ``` ## 开发建议 -1. **先测试**:用 `agc run` 验证后再发布 -2. **输出明确**:结果 JSON 包含关键信息 -3. **错误友好**:失败信息写清楚原因 -4. **使用 GDAL**:GIS 文件处理优先使用 GDAL 命令行工具 +1. **输出明确**:结果 JSON 包含关键信息 +2. **错误友好**:失败信息写清楚原因 +3. **使用 GDAL**:GIS 文件处理优先使用 GDAL 命令行工具