-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrender.py
More file actions
82 lines (65 loc) · 2.05 KB
/
render.py
File metadata and controls
82 lines (65 loc) · 2.05 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import sys
import yaml
import tempfile
import subprocess
from quarto.quarto import find_quarto
def render(input,
output_format = None,
output_file = None,
execute = True,
execute_params = None,
execute_dir = None,
cache = None,
cache_refresh = False,
kernel_keepalive = None,
kernel_restart = False,
debug = False,
quiet = False,
pandoc_args = None):
"""Render a Quarto document."""
# params file to remove after render
params_file = None
# build args
args = ["render", input]
if output_format is not None:
args.extend(["--to", output_format])
if output_file is not None:
args.extend(["--output", output_file])
if execute is not None:
if execute is True:
args.append("--execute")
elif execute is False:
args.append("--no-execute")
if execute_params is not None:
params_file = tempfile.NamedTemporaryFile(mode = 'w',
prefix="quarto-params",
suffix=".yml",
delete=False)
yaml.dump(execute_params, params_file)
params_file.close()
args.extend(["--execute-params", params_file.name])
if execute_dir is not None:
args.extend(["--execute-dir", execute_dir])
if cache is not None:
if cache is True:
args.append("--cache")
elif cache is False:
args.append("--no-cache")
if cache_refresh is True:
args.append("--cache-refresh")
if kernel_keepalive is not None:
args.extend(["--kernel-keepalive", str(kernel_keepalive)])
if kernel_restart is True:
args.append("--kernel-restart")
if debug is True:
args.append("--debug")
if quiet is True:
args.append("--quiet")
# run process
try:
process = subprocess.Popen([find_quarto()] + args)
process.wait()
finally:
if params_file is not None:
os.remove(params_file.name)