Skip to content

Commit 78c4fd7

Browse files
committed
Simplify interface for calling nbconvert
1 parent 6520ad4 commit 78c4fd7

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

runbook/cli/commands/create.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111
"-t",
1212
"--template",
1313
envvar="TEMPLATE",
14-
default="./runbooks/binder/_template-python.ipynb",
14+
default="./runbooks/binder/_template-deno.ipynb",
1515
type=click.Path(exists=True, file_okay=True),
1616
callback=validate_template,
1717
)
18+
19+
# TODO: switch to language and template defaulting to Deno
20+
# based on operational experience at work
1821
@click.option(
1922
"-l",
2023
"--language",
2124
envvar="LANGUAGE",
22-
default="./runbooks/binder/_template-python.ipynb",
25+
default="deno",
2326
callback=validate_create_language,
2427
)
2528
@click.pass_context
@@ -36,9 +39,7 @@ def create(ctx, filename, template, language):
3639
)
3740
# TODO: remove hardcoding of folder outer name and rely on config file
3841
path.join("runbooks", "binder", filename)
39-
# TODO: hide the nbconvert verbose output?
4042
argv = [
41-
"--ClearOutputPreprocessor.enabled=True",
4243
template,
4344
"--to",
4445
"notebook",
@@ -48,7 +49,7 @@ def create(ctx, filename, template, language):
4849
path.join("runbooks", "binder"),
4950
]
5051

51-
nbconvert_launch_instance(argv)
52+
nbconvert_launch_instance(argv, clear_output=True)
5253

5354
click.echo(
5455
click.style(

runbook/cli/commands/plan.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import papermill as pm
1313

1414

15-
# TODO: standardize ids in output files through custom processor
16-
# use something like ulid, we don't need full UUIDs
1715
@click.command()
1816
@click.argument(
1917
"input", type=click.Path(file_okay=True), callback=validate_runbook_file_path
@@ -57,7 +55,7 @@ def plan(ctx, input, embed, identifier="", params={}):
5755
# we make the simplifying assumption to show user and then treat inputs as potentially json
5856
for key, value in inferred_params.items():
5957
if key != RUNBOOK_METADATA:
60-
default = value["default"].strip(";")
58+
default = value["default"].rstrip(";")
6159
typing = value["inferred_type_name"]
6260
type_hint = ""
6361
help_hint = ""
@@ -89,16 +87,13 @@ def plan(ctx, input, embed, identifier="", params={}):
8987
)
9088

9189
argv = [
92-
"--ClearOutputPreprocessor.enabled=True",
9390
"--inplace",
9491
full_output,
9592
]
9693

9794
# TODO: join the unified logic of create and plan
9895

99-
# TODO: hide the nbconvert verbose output?
100-
101-
nbconvert_launch_instance(argv)
96+
nbconvert_launch_instance(argv, clear_output=True)
10297

10398
for f in embed:
10499
shutil.copyfile(src=f, dst=f"{output_folder}/{path.basename(f)}")

runbook/cli/lib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ def ts_id(length=10):
2020

2121

2222
# Suppresses nbconvert output
23-
def nbconvert_launch_instance(argv):
24-
# Temporarily redirect stdout/stderr to suppress nbconvert output
23+
def nbconvert_launch_instance(argv, clear_output=True):
24+
if clear_output:
25+
argv.insert(0, "--ClearOutputPreprocessor.enabled=True")
2526
stdout = sys.stdout
2627
stderr = sys.stderr
2728
sys.stdout = StringIO()

runbook/cli/validators.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from pathlib import Path
55

66
import click
7+
8+
# TODO: use click prompt lib instead of questionary to avoid dependency
79
import questionary
810

911

@@ -26,8 +28,10 @@ def validate_template(ctx, param, value):
2628
def validate_create_language(ctx, param, value):
2729
if value == "./runbooks/binder/_template-python.ipynb":
2830
return value
31+
if value == "./runbooks/binder/_template-deno.ipynb":
32+
return value
2933
if value in ["python", "deno"]:
30-
return f"./runbooks/binder/_template-{value}"
34+
return f"./runbooks/binder/_template-{value}.ipynb"
3135
else:
3236
raise click.BadOptionUsage("--language", "options are python or deno")
3337

0 commit comments

Comments
 (0)