Skip to content

Commit 20195b2

Browse files
committed
complete render implementation
1 parent efef855 commit 20195b2

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

quarto/quarto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def path():
1010
return shutil.which("quarto")
1111
else:
1212
return path_env
13-
13+
1414

1515
def find_quarto():
1616
quarto = path()

quarto/render.py

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,82 @@
11

2+
import os
23
import sys
4+
import yaml
5+
import tempfile
36
import subprocess
47

58
from quarto.quarto import find_quarto
69

7-
def render(input):
10+
def render(input,
11+
output_format = None,
12+
output_file = None,
13+
execute = True,
14+
execute_params = None,
15+
execute_dir = None,
16+
cache = None,
17+
cache_refresh = False,
18+
kernel_keepalive = None,
19+
kernel_restart = False,
20+
debug = False,
21+
quiet = False,
22+
pandoc_args = None):
23+
24+
# params file to remove after render
25+
params_file = None
26+
27+
# build args
828
args = ["render", input]
9-
process = subprocess.Popen([find_quarto()] + args)
10-
process.wait()
29+
30+
if output_format is not None:
31+
args.extend(["--to", output_format])
32+
33+
if output_file is not None:
34+
args.extend(["--output", output_file])
35+
36+
if execute is not None:
37+
if execute is True:
38+
args.append("--execute")
39+
elif execute is False:
40+
args.append("--no-execute")
41+
42+
if execute_params is not None:
43+
params_file = tempfile.NamedTemporaryFile(mode = 'w',
44+
prefix="quarto-params",
45+
suffix=".yml",
46+
delete=False)
47+
yaml.dump(execute_params, params_file)
48+
params_file.close()
49+
args.extend(["--execute-params", params_file.name])
50+
51+
if execute_dir is not None:
52+
args.extend(["--execute-dir", execute_dir])
53+
54+
if cache is not None:
55+
if cache is True:
56+
args.append("--cache")
57+
elif cache is False:
58+
args.append("--no-cache")
59+
60+
if cache_refresh is True:
61+
args.append("--cache-refresh")
62+
63+
if kernel_keepalive is not None:
64+
args.extend(["--kernel-keepalive", str(kernel_keepalive)])
65+
66+
if kernel_restart is True:
67+
args.append("--kernel-restart")
1168

69+
if debug is True:
70+
args.append("--debug")
71+
72+
if quiet is True:
73+
args.append("--quiet")
74+
75+
# run process
76+
try:
77+
process = subprocess.Popen([find_quarto()] + args)
78+
process.wait()
79+
finally:
80+
if params_file is not None:
81+
os.remove(params_file.name)
1282

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
long_description_content_type="text/markdown",
1414
url="https://github.com/quarto-dev/quarto-python",
1515
packages=setuptools.find_packages(),
16-
install_requires=["jupyter"],
16+
install_requires=["pyyaml", "jupyter"],
1717
classifiers=[
1818
"Programming Language :: Python :: 3",
1919
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",

0 commit comments

Comments
 (0)