calkit-python 0.0.8__py3-none-any.whl → 0.0.10__py3-none-any.whl
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/__init__.py +1 -1
- calkit/cli/list.py +70 -0
- calkit/cli/main.py +47 -5
- calkit/cli/new.py +4 -15
- calkit/core.py +7 -0
- {calkit_python-0.0.8.dist-info → calkit_python-0.0.10.dist-info}/METADATA +1 -1
- {calkit_python-0.0.8.dist-info → calkit_python-0.0.10.dist-info}/RECORD +10 -9
- {calkit_python-0.0.8.dist-info → calkit_python-0.0.10.dist-info}/WHEEL +0 -0
- {calkit_python-0.0.8.dist-info → calkit_python-0.0.10.dist-info}/entry_points.txt +0 -0
- {calkit_python-0.0.8.dist-info → calkit_python-0.0.10.dist-info}/licenses/LICENSE +0 -0
calkit/__init__.py
CHANGED
calkit/cli/list.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""CLI for listing objects."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
import calkit
|
|
10
|
+
|
|
11
|
+
list_app = typer.Typer(no_args_is_help=True)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _list_objects(
|
|
15
|
+
kind: Literal[
|
|
16
|
+
"notebooks", "datasets", "figures", "references", "publications"
|
|
17
|
+
]
|
|
18
|
+
):
|
|
19
|
+
"""List objects.
|
|
20
|
+
|
|
21
|
+
TODO: This should probably just use some library to dump YAML to string.
|
|
22
|
+
"""
|
|
23
|
+
ck_info = calkit.load_calkit_info()
|
|
24
|
+
objects = ck_info.get(kind, [])
|
|
25
|
+
for obj in objects:
|
|
26
|
+
path = obj.pop("path")
|
|
27
|
+
typer.echo(f"- path: {path}")
|
|
28
|
+
for k, v in obj.items():
|
|
29
|
+
if isinstance(v, dict):
|
|
30
|
+
typer.echo(f" {k}:")
|
|
31
|
+
for k1, v1 in v.items():
|
|
32
|
+
typer.echo(f" {k1}: {v1}")
|
|
33
|
+
elif isinstance(v, list):
|
|
34
|
+
typer.echo(f" {k}:")
|
|
35
|
+
for item in v:
|
|
36
|
+
if isinstance(item, dict):
|
|
37
|
+
for n, (k1, v1) in enumerate(item.items()):
|
|
38
|
+
if n == 0:
|
|
39
|
+
typer.echo(f" - {k1}: {v1}")
|
|
40
|
+
else:
|
|
41
|
+
typer.echo(f" {k1}: {v1}")
|
|
42
|
+
else:
|
|
43
|
+
typer.echo(f" - {item}")
|
|
44
|
+
else:
|
|
45
|
+
typer.echo(f" {k}: {v}")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@list_app.command(name="notebooks")
|
|
49
|
+
def list_notebooks():
|
|
50
|
+
_list_objects("notebooks")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@list_app.command(name="figures")
|
|
54
|
+
def list_figures():
|
|
55
|
+
_list_objects("figures")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@list_app.command(name="datasets")
|
|
59
|
+
def list_datasets():
|
|
60
|
+
_list_objects("datasets")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@list_app.command(name="publications")
|
|
64
|
+
def list_publications():
|
|
65
|
+
_list_objects("publications")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@list_app.command(name="references")
|
|
69
|
+
def list_references():
|
|
70
|
+
_list_objects("references")
|
calkit/cli/main.py
CHANGED
|
@@ -11,6 +11,7 @@ from typing_extensions import Annotated, Optional
|
|
|
11
11
|
import calkit
|
|
12
12
|
from calkit.cli import print_sep, run_cmd
|
|
13
13
|
from calkit.cli.config import config_app
|
|
14
|
+
from calkit.cli.list import list_app
|
|
14
15
|
from calkit.cli.new import new_app
|
|
15
16
|
from calkit.cli.notebooks import notebooks_app
|
|
16
17
|
|
|
@@ -25,6 +26,7 @@ app.add_typer(
|
|
|
25
26
|
new_app, name="new", help="Add new Calkit object (to calkit.yaml)."
|
|
26
27
|
)
|
|
27
28
|
app.add_typer(notebooks_app, name="nb", help="Work with Jupyter notebooks.")
|
|
29
|
+
app.add_typer(list_app, name="list", help="List Calkit objects.")
|
|
28
30
|
|
|
29
31
|
|
|
30
32
|
@app.callback()
|
|
@@ -166,6 +168,50 @@ def commit(
|
|
|
166
168
|
push()
|
|
167
169
|
|
|
168
170
|
|
|
171
|
+
@app.command(name="save")
|
|
172
|
+
def save(
|
|
173
|
+
paths: Annotated[
|
|
174
|
+
Optional[list[str]],
|
|
175
|
+
typer.Argument(
|
|
176
|
+
help=(
|
|
177
|
+
"Paths to add and commit. If not provided, will default to "
|
|
178
|
+
"any changed files that have been added previously."
|
|
179
|
+
),
|
|
180
|
+
),
|
|
181
|
+
] = None,
|
|
182
|
+
all: Annotated[
|
|
183
|
+
Optional[bool],
|
|
184
|
+
typer.Option(
|
|
185
|
+
"--all", "-a", help="Automatically stage all changed files."
|
|
186
|
+
),
|
|
187
|
+
] = False,
|
|
188
|
+
message: Annotated[
|
|
189
|
+
Optional[str], typer.Option("--message", "-m", help="Commit message.")
|
|
190
|
+
] = None,
|
|
191
|
+
to: Annotated[
|
|
192
|
+
str,
|
|
193
|
+
typer.Option(
|
|
194
|
+
"--to", "-t", help="System with which to add (git or dvc)."
|
|
195
|
+
),
|
|
196
|
+
] = None,
|
|
197
|
+
no_push: Annotated[
|
|
198
|
+
bool,
|
|
199
|
+
typer.Option(
|
|
200
|
+
"--no-push", help="Do not push to Git and DVC after committing."
|
|
201
|
+
),
|
|
202
|
+
] = False,
|
|
203
|
+
):
|
|
204
|
+
"""Save paths by committing and pushing.
|
|
205
|
+
|
|
206
|
+
This is essentially git/dvc add, commit, and push in one step.
|
|
207
|
+
"""
|
|
208
|
+
if paths is not None:
|
|
209
|
+
add(paths, to=to)
|
|
210
|
+
commit(all=True if paths is None else False, message=message)
|
|
211
|
+
if not no_push:
|
|
212
|
+
push()
|
|
213
|
+
|
|
214
|
+
|
|
169
215
|
@app.command(name="pull", help="Pull with both Git and DVC.")
|
|
170
216
|
def pull():
|
|
171
217
|
typer.echo("Git pulling")
|
|
@@ -293,11 +339,7 @@ def run_dvc_repro(
|
|
|
293
339
|
)
|
|
294
340
|
# Now that we've extracted Calkit objects from stage metadata, we can put
|
|
295
341
|
# them into the calkit.yaml file, overwriting objects with the same path
|
|
296
|
-
|
|
297
|
-
with open("calkit.yaml") as f:
|
|
298
|
-
ck_info = calkit.ryaml.load(f)
|
|
299
|
-
else:
|
|
300
|
-
ck_info = {}
|
|
342
|
+
ck_info = calkit.load_calkit_info()
|
|
301
343
|
for obj in objects:
|
|
302
344
|
cktype = obj.pop("type")
|
|
303
345
|
cktype_plural = cktype + "s"
|
calkit/cli/new.py
CHANGED
|
@@ -8,6 +8,7 @@ import git
|
|
|
8
8
|
import typer
|
|
9
9
|
from typing_extensions import Annotated
|
|
10
10
|
|
|
11
|
+
import calkit
|
|
11
12
|
from calkit.core import ryaml
|
|
12
13
|
|
|
13
14
|
new_app = typer.Typer(no_args_is_help=True)
|
|
@@ -21,11 +22,7 @@ def new_figure(
|
|
|
21
22
|
commit: Annotated[bool, typer.Option("--commit")] = False,
|
|
22
23
|
):
|
|
23
24
|
"""Add a new figure."""
|
|
24
|
-
|
|
25
|
-
with open("calkit.yaml") as f:
|
|
26
|
-
ck_info = ryaml.load(f)
|
|
27
|
-
else:
|
|
28
|
-
ck_info = {}
|
|
25
|
+
ck_info = calkit.load_calkit_info()
|
|
29
26
|
figures = ck_info.get("figures", [])
|
|
30
27
|
paths = [f.get("path") for f in figures]
|
|
31
28
|
if path in paths:
|
|
@@ -49,11 +46,7 @@ def new_question(
|
|
|
49
46
|
commit: Annotated[bool, typer.Option("--commit")] = False,
|
|
50
47
|
):
|
|
51
48
|
"""Add a new question."""
|
|
52
|
-
|
|
53
|
-
with open("calkit.yaml") as f:
|
|
54
|
-
ck_info = ryaml.load(f)
|
|
55
|
-
else:
|
|
56
|
-
ck_info = {}
|
|
49
|
+
ck_info = calkit.load_calkit_info()
|
|
57
50
|
questions = ck_info.get("questions", [])
|
|
58
51
|
if question in questions:
|
|
59
52
|
raise ValueError("Question already exists")
|
|
@@ -85,11 +78,7 @@ def new_notebook(
|
|
|
85
78
|
raise ValueError("Path does not have .ipynb extension")
|
|
86
79
|
# TODO: Add option to create stages that run `calkit nb clean` and
|
|
87
80
|
# `calkit nb execute`
|
|
88
|
-
|
|
89
|
-
with open("calkit.yaml") as f:
|
|
90
|
-
ck_info = ryaml.load(f)
|
|
91
|
-
else:
|
|
92
|
-
ck_info = {}
|
|
81
|
+
ck_info = calkit.load_calkit_info()
|
|
93
82
|
notebooks = ck_info.get("notebooks", [])
|
|
94
83
|
paths = [f.get("path") for f in notebooks]
|
|
95
84
|
if path in paths:
|
calkit/core.py
CHANGED
|
@@ -44,3 +44,10 @@ def find_project_dirs(relative=False, max_depth=3) -> list[str]:
|
|
|
44
44
|
continue
|
|
45
45
|
final_res.append(path)
|
|
46
46
|
return final_res
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def load_calkit_info() -> dict:
|
|
50
|
+
if os.path.isfile("calkit.yaml"):
|
|
51
|
+
with open("calkit.yaml") as f:
|
|
52
|
+
return ryaml.load(f)
|
|
53
|
+
return {}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
calkit/__init__.py,sha256=
|
|
1
|
+
calkit/__init__.py,sha256=8H56oHKSKNSAdidQbL7gtTwIKT0bZQqqZNCRnGcM8zY,143
|
|
2
2
|
calkit/cloud.py,sha256=CnQKms4mBQo4X8jVLIa-70-3jPDl38zRNFyK5TjiaHM,2209
|
|
3
3
|
calkit/config.py,sha256=NPFRk5inn66Wy44pyx8WppyqvIzkW1sO6VjXwIcCacE,2044
|
|
4
|
-
calkit/core.py,sha256=
|
|
4
|
+
calkit/core.py,sha256=P9QOEkCIyBr5Xfig_rUeEj02ZZIyBicj3P6K4rad1tU,1383
|
|
5
5
|
calkit/data.py,sha256=DZDkj-BLFWXz56R-A9XZeSKSgXpm3aKtiqD6JstfmnY,1631
|
|
6
6
|
calkit/dvc.py,sha256=tX5172Ahw0mHcuJIrMenz1oGYxCrMzMURJJMHEHenbg,1506
|
|
7
7
|
calkit/git.py,sha256=NLd7A32dPbfVnZLa8xbmviJ-ChGZcdkcd6wcOOnsSKQ,350
|
|
@@ -12,14 +12,15 @@ calkit/server.py,sha256=gq3643ABKTQu1eVR_OqJ-SdQh2dPLHSFsipmmAK5ttA,5959
|
|
|
12
12
|
calkit/cli/__init__.py,sha256=2Id-_5dsHbL29qqScLkRUhWXzTgxsZ_A_lMPs9rf5uY,77
|
|
13
13
|
calkit/cli/config.py,sha256=y-TWv150qWvUtlMfySgCyMyk8n5SNL-8hNRm9NycJ98,1098
|
|
14
14
|
calkit/cli/core.py,sha256=N-I2Yw1STgEMN5xLmfOuVq1od1EJx2oMCyVQtNa8Nwg,424
|
|
15
|
-
calkit/cli/
|
|
16
|
-
calkit/cli/
|
|
15
|
+
calkit/cli/list.py,sha256=kxQsq1SQIZEDdWHIvakzdcMhayqJlfiCmWkj09dhXuA,1799
|
|
16
|
+
calkit/cli/main.py,sha256=baKlNsHtfWmSLLfpwkf3xxRNE8R6RGtzrpcLqe6YnPo,12561
|
|
17
|
+
calkit/cli/new.py,sha256=WVg9bEfGO8QXJj4fajSrbmQTUJMLAgHsNRTxkFZl8Xo,3088
|
|
17
18
|
calkit/cli/notebooks.py,sha256=GsNmm8pdFkbs_KyZxClfIUThD78GCdu0R5udCXhXc9E,2083
|
|
18
19
|
calkit/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
20
|
calkit/tests/test_core.py,sha256=CdRqvYnq3MidyTknvfIbkmmhMfydpyKtTW9hakAvzsc,167
|
|
20
21
|
calkit/tests/test_jupyter.py,sha256=YTL6zI740UM2KUjskSipzvSKxsyQ8rVPFQIX5cb2tMQ,114
|
|
21
|
-
calkit_python-0.0.
|
|
22
|
-
calkit_python-0.0.
|
|
23
|
-
calkit_python-0.0.
|
|
24
|
-
calkit_python-0.0.
|
|
25
|
-
calkit_python-0.0.
|
|
22
|
+
calkit_python-0.0.10.dist-info/METADATA,sha256=0-gOXZLjx62tlDHDnRI1PsHFFsNsLOvTz03yA5ddizs,4005
|
|
23
|
+
calkit_python-0.0.10.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
24
|
+
calkit_python-0.0.10.dist-info/entry_points.txt,sha256=tiPfbDDZNB-YStw5YVO_4Gww0W3Dcdy8Mh6muX_GWnY,42
|
|
25
|
+
calkit_python-0.0.10.dist-info/licenses/LICENSE,sha256=9ZamCaSUTZk9rcrnf-sWFKLOHr3ws-S_dgKMegW4nw8,1056
|
|
26
|
+
calkit_python-0.0.10.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|