-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathscript.template.py
More file actions
executable file
·35 lines (30 loc) · 873 Bytes
/
script.template.py
File metadata and controls
executable file
·35 lines (30 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import atexit;
import fire
import json
import os;
import sys
from pathlib import Path
@atexit.register
def cleanup():
if os.path.exists(__file__):
os.remove(__file__);
# end if
# end cleanup()
def snippet_runner(items: list, env_vars: dict) -> list:
# ...code snippet
# should return items
# <%- codeSnippet %>
pass
def main(json_path: str, env_vars: dict = {}) -> None:
with open(Path(json_path), 'r') as json_file:
items: list = json.load(json_file)
new_items = snippet_runner(items, env_vars)
assert type(new_items) is list or isinstance(new_items, list), "code snippet should return a list"
# print('```', json.dumps(new_items), '```')
# sys.stdout.write(json.dumps(new_items))
sys.stderr.write(json.dumps(new_items))
exit(0)
if __name__ == "__main__":
fire.Fire(main)