fix: 去掉套件级内容,只聚焦脚本本身

This commit is contained in:
2026-07-09 19:20:36 +00:00
parent 8192d1a7d6
commit 9876463f4c
@@ -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 命令行工具