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
3 changes: 2 additions & 1 deletion .github/workflows/tauri-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ jobs:
pdl run ./demos/demo1.pdl | grep 'write a hello'

# 3. `run` subcommand works with UI demos (json source)
# demo4 depends on user input
# demo5,demo6 each depend on an external file, and the interpreter does not currently capture this in the trace
# demo8 currently requires building a model which the interpreter does not directly support
# demo9 takes forever, so... for now skip it
for i in ./src/demos/*.json
do if [[ $(basename $i) != "demo5.json" ]] && [[ $(basename $i) != "demo6.json" ]] && [[ $(basename $i) != "demo8.json" ]] && [[ $(basename $i) != "demo9.json" ]]; then pdl run $i; fi
do if [[ $(basename $i) != "demo4.json" ]] && [[ $(basename $i) != "demo5.json" ]] && [[ $(basename $i) != "demo6.json" ]] && [[ $(basename $i) != "demo8.json" ]] && [[ $(basename $i) != "demo9.json" ]]; then pdl run $i; fi
done

- name: Tear down xvfb
Expand Down
9 changes: 5 additions & 4 deletions src/pdl/pdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def main():
# This case must be before `if args.pdl is None:`
if args.version:
print(f"PDL {version}")
return
return 0

# This case must be before `if args.pdl is None:`
if args.schema:
Expand All @@ -218,11 +218,11 @@ def main():
)
top_level_schema["anyOf"] = list(schema.values())
print(json.dumps(top_level_schema, indent=2))
return
return 0

if args.pdl is None:
parser.print_help()
return
return 0

if args.sandbox:
args = sys.argv[1:]
Expand Down Expand Up @@ -267,12 +267,13 @@ def main():
batch=batch,
cwd=pdl_file.parent,
)
pdl_interpreter.generate(
exit_code = pdl_interpreter.generate(
pdl_file,
InterpreterState(**config),
PdlDict(initial_scope),
trace_file,
)
return exit_code


if __name__ == "__main__":
Expand Down
8 changes: 7 additions & 1 deletion src/pdl/pdl_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,17 @@ def generate(
state: Optional[InterpreterState],
initial_scope: ScopeType,
trace_file: Optional[str | Path],
):
) -> int:
"""Execute the PDL program defined in `pdl_file`.

Args:
pdl_file: Program to execute.
initial_scope: Environment defining the variables in scope to execute the program.
state: Initial state of the interpreter.
trace_file: Indicate if the execution trace must be produced and the file to save it.

Returns:
Returns the exit code: `0` for success, `1` for failure
"""
try:
prog, loc = parse_file(pdl_file)
Expand All @@ -172,6 +175,7 @@ def generate(
write_trace(trace_file, trace)
except PDLParseError as exc:
print("\n".join(exc.message), file=sys.stderr)
return 1
except PDLRuntimeError as exc:
if exc.loc is None:
message = exc.message
Expand All @@ -180,6 +184,8 @@ def generate(
print(message, file=sys.stderr)
if trace_file and exc.pdl__trace is not None:
write_trace(trace_file, exc.pdl__trace)
return 1
return 0


def write_trace(
Expand Down