Skip to content

Commit 84e3f5e

Browse files
committed
Add 'check' command for deno and for python
1 parent 78de827 commit 84e3f5e

File tree

7 files changed

+149
-11
lines changed

7 files changed

+149
-11
lines changed

poetry.lock

Lines changed: 87 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pre-commit = "^3.6.0"
2727
python-ulid = "^2.2.0"
2828
slack-sdk = "^3.26.2"
2929
jupyterlab = "^4.1.5"
30+
nbdime = "^4.0.1"
3031

3132

3233
[tool.poetry.group.dev.dependencies]

runbook/cli/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import click
44

5-
from runbook.cli.commands import create, edit, export, convert, init, plan, review, run, version
5+
from runbook.cli.commands import create, edit, export, convert, check, init, plan, review, run, version
66

77
# TODO: not working, needs a custom underlying class to handle the auto-env
88
CONTEXT_SETTINGS = dict(auto_envvar_prefix="RUNBOOK")
@@ -28,6 +28,7 @@ def cli(ctx, cwd):
2828
cli.add_command(edit)
2929
cli.add_command(create)
3030
cli.add_command(convert)
31+
cli.add_command(check)
3132
cli.add_command(run)
3233
cli.add_command(review)
3334
cli.add_command(version)

runbook/cli/commands/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
from runbook.cli.commands.run import run
77
from runbook.cli.commands.version import version
88
from runbook.cli.commands.convert import convert
9+
from runbook.cli.commands.check import check

runbook/cli/commands/check.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# metadata.kernelspec.name = deno || python3
2+
3+
from os import path
4+
5+
import click
6+
import json
7+
8+
from runbook.cli.completions import EditableNotebook
9+
from runbook.cli.validators import validate_runbook_file_path
10+
11+
@click.command()
12+
@click.argument(
13+
"filename",
14+
type=EditableNotebook(file_okay=True),
15+
callback=validate_runbook_file_path,
16+
)
17+
18+
@click.option(
19+
"-c",
20+
"--command",
21+
default=None,
22+
help="Run a notebook through this custom command, ie 'deno check {}' where the {} is the temporary filename.",
23+
)
24+
@click.pass_context
25+
def check(ctx, filename, command):
26+
"""Check language validity and formatting of a notebook."""
27+
# jupytext --check 'deno check {}' notebook.ipynb
28+
full_path = path.abspath(filename)
29+
content = None
30+
with open(full_path, "r") as f:
31+
txt = f.read()
32+
content = json.loads(txt)
33+
34+
# Default
35+
language_specific_tool = "black --diff {}"
36+
if command:
37+
language_specific_tool = command
38+
else:
39+
kernel_name = content["metadata"]["kernelspec"]["name"]
40+
if kernel_name == "deno":
41+
language_specific_tool = "deno check {}"
42+
43+
argv = ["--check", language_specific_tool, full_path]
44+
# Lazily loaded for performance
45+
from jupytext.cli import jupytext as jupytext_main
46+
47+
jupytext_main(args=argv)

runbooks/binder/_template-deno.ipynb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"source": [
1414
"# TITLE\n",
15+
"\n",
1516
"## DESCRIPTION"
1617
]
1718
},
@@ -45,10 +46,10 @@
4546
"outputs": [],
4647
"source": [
4748
"// Default Params\n",
48-
"let server: string = \"main.xargs.io\"\n",
49-
"let arg: number = 1\n",
50-
"let anArray: string[] = ['a', 'b']\n",
51-
"let __RUNBOOK_METADATA__ = {}"
49+
"let server: string = \"main.xargs.io\";\n",
50+
"let arg: number = 1;\n",
51+
"let anArray: string[] = [\"a\", \"b\"];\n",
52+
"let __RUNBOOK_METADATA__ = {};"
5253
]
5354
},
5455
{
@@ -64,7 +65,7 @@
6465
},
6566
"outputs": [],
6667
"source": [
67-
"import {sh, $} from 'https://raw.githubusercontent.com/zph/runbook/main/ext/deno/runbook/mod.ts'"
68+
"import { $, sh } from \"https://raw.githubusercontent.com/zph/runbook/main/ext/deno/runbook/mod.ts\";"
6869
]
6970
},
7071
{
@@ -80,7 +81,7 @@
8081
},
8182
"outputs": [],
8283
"source": [
83-
"await sh(\"git log\")"
84+
"await sh(\"git log\");"
8485
]
8586
},
8687
{
@@ -124,7 +125,7 @@
124125
},
125126
"outputs": [],
126127
"source": [
127-
"await $`echo '{\"a\": 1}'`.json()"
128+
"await $`echo '{\"a\": 1}'`.json();"
128129
]
129130
},
130131
{
@@ -154,7 +155,7 @@
154155
},
155156
"outputs": [],
156157
"source": [
157-
"await $`git log`.text()"
158+
"await $`git log`.text();"
158159
]
159160
},
160161
{

runbooks/binder/_template-python.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"source": [
1414
"# TITLE\n",
15+
"\n",
1516
"## Description"
1617
]
1718
},
@@ -168,7 +169,7 @@
168169
"id": "f0e9eade",
169170
"metadata": {},
170171
"source": [
171-
"<span style='color: red;'><bold>DANGER</bold></span> <span style='color: red;'><bold>DANGER</bold></span> <span style='color: red;'><bold>DANGER</bold></span> The following code is going to be risky. Be prepared with rollback procedures."
172+
"<span style='color: red;'><bold>DANGER</bold></span> <span style='color: red;'><bold>DANGER</bold></span> <span style='color: red;'><bold>DANGER</bold></span> The following code is going to be risky. Be prepared with rollback procedures."
172173
]
173174
},
174175
{

0 commit comments

Comments
 (0)