calkit-python 0.0.4__tar.gz → 0.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {calkit_python-0.0.4 → calkit_python-0.0.5}/PKG-INFO +1 -1
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/__init__.py +1 -1
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/cli.py +117 -5
- {calkit_python-0.0.4 → calkit_python-0.0.5}/.github/FUNDING.yml +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/.github/workflows/publish-test.yml +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/.github/workflows/publish.yml +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/.gitignore +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/LICENSE +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/README.md +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/cloud.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/config.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/core.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/data.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/dvc.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/git.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/gui.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/jupyter.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/models.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/server.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/tests/__init__.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/tests/test_core.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/calkit/tests/test_jupyter.py +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/examples/cfd-study/README.md +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/examples/cfd-study/calkit.yaml +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/examples/cfd-study/config/simulations/runs.csv +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/examples/cfd-study/notebook.ipynb +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/examples/ms-office/.gitignore +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/examples/ms-office/README.md +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/examples/ms-office/calkit.yaml +0 -0
- {calkit_python-0.0.4 → calkit_python-0.0.5}/pyproject.toml +0 -0
|
@@ -11,16 +11,37 @@ import git
|
|
|
11
11
|
import typer
|
|
12
12
|
from typing_extensions import Annotated, Optional
|
|
13
13
|
|
|
14
|
+
import calkit
|
|
14
15
|
from calkit.core import ryaml
|
|
15
16
|
|
|
16
17
|
from . import config
|
|
17
18
|
from .dvc import configure_remote, set_remote_auth
|
|
18
19
|
|
|
19
|
-
app = typer.Typer(
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
app = typer.Typer(
|
|
21
|
+
invoke_without_command=True,
|
|
22
|
+
no_args_is_help=True,
|
|
23
|
+
context_settings=dict(help_option_names=["-h", "--help"]),
|
|
24
|
+
)
|
|
25
|
+
config_app = typer.Typer(no_args_is_help=True)
|
|
26
|
+
new_app = typer.Typer(no_args_is_help=True)
|
|
27
|
+
notebooks_app = typer.Typer(no_args_is_help=True)
|
|
22
28
|
app.add_typer(config_app, name="config", help="Configure Calkit.")
|
|
23
|
-
app.add_typer(
|
|
29
|
+
app.add_typer(
|
|
30
|
+
new_app, name="new", help="Add new Calkit object (to calkit.yaml)."
|
|
31
|
+
)
|
|
32
|
+
app.add_typer(notebooks_app, name="nb", help="Work with Jupyter notebooks.")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@app.callback()
|
|
36
|
+
def main(
|
|
37
|
+
version: Annotated[
|
|
38
|
+
bool,
|
|
39
|
+
typer.Option("--version", help="Show version and exit."),
|
|
40
|
+
] = False,
|
|
41
|
+
):
|
|
42
|
+
if version:
|
|
43
|
+
typer.echo(calkit.__version__)
|
|
44
|
+
raise typer.Exit()
|
|
24
45
|
|
|
25
46
|
|
|
26
47
|
@config_app.command(name="set")
|
|
@@ -135,7 +156,7 @@ def new_figure(
|
|
|
135
156
|
description: Annotated[str, typer.Option("--desc")] = None,
|
|
136
157
|
commit: Annotated[bool, typer.Option("--commit")] = False,
|
|
137
158
|
):
|
|
138
|
-
"""Add a new figure
|
|
159
|
+
"""Add a new figure."""
|
|
139
160
|
if os.path.isfile("calkit.yaml"):
|
|
140
161
|
with open("calkit.yaml") as f:
|
|
141
162
|
ck_info = ryaml.load(f)
|
|
@@ -163,6 +184,7 @@ def new_question(
|
|
|
163
184
|
question: str,
|
|
164
185
|
commit: Annotated[bool, typer.Option("--commit")] = False,
|
|
165
186
|
):
|
|
187
|
+
"""Add a new question."""
|
|
166
188
|
if os.path.isfile("calkit.yaml"):
|
|
167
189
|
with open("calkit.yaml") as f:
|
|
168
190
|
ck_info = ryaml.load(f)
|
|
@@ -183,6 +205,96 @@ def new_question(
|
|
|
183
205
|
repo.git.commit(["-m", "Add question"])
|
|
184
206
|
|
|
185
207
|
|
|
208
|
+
@new_app.command("notebook")
|
|
209
|
+
def new_notebook(
|
|
210
|
+
path: Annotated[str, typer.Argument(help="Notebook path (relative)")],
|
|
211
|
+
title: Annotated[str, typer.Option("--title")],
|
|
212
|
+
description: Annotated[str, typer.Option("--desc")] = None,
|
|
213
|
+
commit: Annotated[bool, typer.Option("--commit")] = False,
|
|
214
|
+
):
|
|
215
|
+
"""Add a new notebook."""
|
|
216
|
+
if os.path.isabs(path):
|
|
217
|
+
raise ValueError("Path must be relative")
|
|
218
|
+
if not os.path.isfile(path):
|
|
219
|
+
raise ValueError("Path is not a file")
|
|
220
|
+
if not path.endswith(".ipynb"):
|
|
221
|
+
raise ValueError("Path does not have .ipynb extension")
|
|
222
|
+
# TODO: Add option to create stages that run `calkit nb clean` and
|
|
223
|
+
# `calkit nb execute`
|
|
224
|
+
if os.path.isfile("calkit.yaml"):
|
|
225
|
+
with open("calkit.yaml") as f:
|
|
226
|
+
ck_info = ryaml.load(f)
|
|
227
|
+
else:
|
|
228
|
+
ck_info = {}
|
|
229
|
+
notebooks = ck_info.get("notebooks", [])
|
|
230
|
+
paths = [f.get("path") for f in notebooks]
|
|
231
|
+
if path in paths:
|
|
232
|
+
raise ValueError(f"Notebook at path {path} already exists")
|
|
233
|
+
obj = dict(path=path, title=title)
|
|
234
|
+
if description is not None:
|
|
235
|
+
obj["description"] = description
|
|
236
|
+
notebooks.append(obj)
|
|
237
|
+
ck_info["notebooks"] = notebooks
|
|
238
|
+
with open("calkit.yaml", "w") as f:
|
|
239
|
+
ryaml.dump(ck_info, f)
|
|
240
|
+
if commit:
|
|
241
|
+
repo = git.Repo()
|
|
242
|
+
repo.git.add("calkit.yaml")
|
|
243
|
+
repo.git.commit(["-m", f"Add notebook {path}"])
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
@notebooks_app.command("clean")
|
|
247
|
+
def clean_notebook_outputs(path: str):
|
|
248
|
+
"""Clean notebook and place a copy in the cleaned notebooks directory.
|
|
249
|
+
|
|
250
|
+
This can be useful to use as a preprocessing DVC stage to use a clean
|
|
251
|
+
notebook as a dependency for a stage that caches and executed notebook.
|
|
252
|
+
"""
|
|
253
|
+
if os.path.isabs(path):
|
|
254
|
+
raise ValueError("Path must be relative")
|
|
255
|
+
fpath_out = os.path.join(".calkit", "notebooks", "cleaned", path)
|
|
256
|
+
folder = os.path.dirname(fpath_out)
|
|
257
|
+
os.makedirs(folder, exist_ok=True)
|
|
258
|
+
subprocess.call(
|
|
259
|
+
[
|
|
260
|
+
"jupyter",
|
|
261
|
+
"nbconvert",
|
|
262
|
+
path,
|
|
263
|
+
"--clear-output",
|
|
264
|
+
"--to",
|
|
265
|
+
"notebook",
|
|
266
|
+
"--output",
|
|
267
|
+
fpath_out,
|
|
268
|
+
]
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
@notebooks_app.command("execute")
|
|
273
|
+
def execute_notebook(path: str):
|
|
274
|
+
"""Execute notebook and place a copy in the executed notebooks directory.
|
|
275
|
+
|
|
276
|
+
This can be useful to use as a preprocessing DVC stage to use a clean
|
|
277
|
+
notebook as a dependency for a stage that caches and executed notebook.
|
|
278
|
+
"""
|
|
279
|
+
if os.path.isabs(path):
|
|
280
|
+
raise ValueError("Path must be relative")
|
|
281
|
+
fpath_out = os.path.join(".calkit", "notebooks", "executed", path)
|
|
282
|
+
folder = os.path.dirname(fpath_out)
|
|
283
|
+
os.makedirs(folder, exist_ok=True)
|
|
284
|
+
subprocess.call(
|
|
285
|
+
[
|
|
286
|
+
"jupyter",
|
|
287
|
+
"nbconvert",
|
|
288
|
+
path,
|
|
289
|
+
"--execute",
|
|
290
|
+
"--to",
|
|
291
|
+
"notebook",
|
|
292
|
+
"--output",
|
|
293
|
+
fpath_out,
|
|
294
|
+
]
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
|
|
186
298
|
@app.command(name="server", help="Run the local server.")
|
|
187
299
|
def run_server():
|
|
188
300
|
import uvicorn
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|