Skip to content

Commit d8e4c12

Browse files
committed
Don't require or assume that the executed script file is in the app catalog
1 parent 39d658e commit d8e4c12

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pyttman/tools/pyttmancli/intents.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def respond(self, message: Message) -> Reply | ReplyStream:
7272
print(f"- Attempt [{i + 1}/{num_retries}]:", end=" ")
7373
try:
7474
terraformer.terraform()
75+
except FileExistsError as e:
76+
return Reply(str(e))
77+
7578
except requests.exceptions.ConnectionError as e:
7679
print("failed.",
7780
"Cannot connect to the server, "
@@ -179,26 +182,22 @@ class RunFile(Intent, PyttmanCliComplainerMixin):
179182

180183
def respond(self, message: Message) -> Reply | ReplyStream:
181184
app_name = message.entities["app_name"]
182-
script_file = message.entities["script_file_name"]
183-
184-
if complaint := self.complain_app_not_found(app_name):
185-
return Reply(complaint)
186-
if script_file is None:
185+
if (script_path := message.entities["script_file_name"]) is None:
187186
return Reply("Filename must be entered, as a '.py' file. "
188187
f"Example: {self.example}")
188+
if complaint := self.complain_app_not_found(app_name):
189+
return Reply(complaint)
189190

190-
script_file = Path(script_file)
191191
app = bootstrap_app(devmode=True, module=app_name)
192192
app.hooks.trigger(LifeCycleHookType.before_start)
193193
global_variables = globals().copy()
194194
global_variables.update(locals())
195195
shell = code.InteractiveConsole(global_variables)
196-
script_path = Path.cwd() / script_file
197196

198197
with open(script_path.as_posix(), "r") as f:
199198
# Set variable to indicate for the running script that it's main
200199
source = f.read()
201-
code_obj = compile(source, script_file.as_posix(), "exec")
200+
code_obj = compile(source, script_path.as_posix(), "exec")
202201
global_variables["__name__"] = "__main__"
203202
exec(code_obj, global_variables)
204203
return Reply(f"Script file executed successfully.")

0 commit comments

Comments
 (0)