Skip to content

Commit 96f30f2

Browse files
committed
create action
1 parent d7c347f commit 96f30f2

2 files changed

Lines changed: 55 additions & 17 deletions

File tree

‎datatorch/cli/action/create.py‎

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
import yaml
44
import json as jsonlib
55

6+
# What a local action's run.py starts as: the image comes in, a result
7+
# goes out, and the model goes in the middle.
8+
MODEL_SCRIPT = """import datatorch
9+
10+
image_path = datatorch.get_input("imagePath")
11+
12+
# Load your model and run it on image_path here. Anything your model
13+
# needs must be installed in the Python this runner runs with.
14+
result = "ok"
15+
16+
datatorch.set_output("result", result)
17+
"""
18+
619

720
@click.command(
821
help="Creates a basic hello world action in the current folder, or, with "
@@ -62,22 +75,47 @@ def create(name, description, json, local_name, tag):
6275
os.makedirs(target, exist_ok=True)
6376
if name == "Hello World":
6477
name = local_name
65-
config = {
66-
"$schema": "http://datatorch.io/schema/action.v1.json",
67-
"name": name,
68-
"description": description,
69-
"inputs": {
70-
"example": {
71-
"type": "string",
72-
"description": "Input string that will get printed to console.",
73-
"default": "Default Example",
74-
}
75-
},
76-
"outputs": {},
77-
# Inputs reach shell commands as $INPUT_<NAME> environment variables;
78-
# interpolating ${{ input.* }} into a command raises InputInjectionError.
79-
"runs": {"using": "cmd", "command": 'echo "$INPUT_EXAMPLE"'},
80-
}
78+
if local_name is not None:
79+
# A local action is almost always someone's own model: start it
80+
# as one. The runner hands over the image's path; run.py returns
81+
# a result. Mirrors the in-browser editor's scaffold.
82+
config = {
83+
"$schema": "http://datatorch.io/schema/action.v1.json",
84+
"name": name,
85+
"description": (
86+
description
87+
if description != "Action created using CI template."
88+
else "Runs my model on one image."
89+
),
90+
"inputs": {
91+
"imagePath": {
92+
"type": "string",
93+
"required": True,
94+
"description": "Path of the image on disk",
95+
}
96+
},
97+
"outputs": {"result": {"type": "string"}},
98+
"runs": {"using": "python", "main": "run.py"},
99+
}
100+
with open(os.path.join(target, "run.py"), "w") as script:
101+
script.write(MODEL_SCRIPT)
102+
else:
103+
config = {
104+
"$schema": "http://datatorch.io/schema/action.v1.json",
105+
"name": name,
106+
"description": description,
107+
"inputs": {
108+
"example": {
109+
"type": "string",
110+
"description": "Input string that will get printed to console.",
111+
"default": "Default Example",
112+
}
113+
},
114+
"outputs": {},
115+
# Inputs reach shell commands as $INPUT_<NAME> environment variables;
116+
# interpolating ${{ input.* }} into a command raises InputInjectionError.
117+
"runs": {"using": "cmd", "command": 'echo "$INPUT_EXAMPLE"'},
118+
}
81119
if json:
82120
with open(os.path.join(target, "action-datatorch.json"), "w") as outfile:
83121
jsonlib.dump(config, outfile, indent=2, sort_keys=True)

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
setup(
3535
name="datatorch",
36-
version="0.7.5",
36+
version="0.7.7",
3737
description="A CLI and library for interacting with DataTorch.",
3838
author="DataTorch",
3939
author_email="support@datatorch.io",

0 commit comments

Comments
 (0)