calkit-python 0.0.5__tar.gz → 0.0.7__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.
Files changed (30) hide show
  1. {calkit_python-0.0.5 → calkit_python-0.0.7}/PKG-INFO +1 -1
  2. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/__init__.py +1 -1
  3. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/cli.py +110 -21
  4. {calkit_python-0.0.5 → calkit_python-0.0.7}/.github/FUNDING.yml +0 -0
  5. {calkit_python-0.0.5 → calkit_python-0.0.7}/.github/workflows/publish-test.yml +0 -0
  6. {calkit_python-0.0.5 → calkit_python-0.0.7}/.github/workflows/publish.yml +0 -0
  7. {calkit_python-0.0.5 → calkit_python-0.0.7}/.gitignore +0 -0
  8. {calkit_python-0.0.5 → calkit_python-0.0.7}/LICENSE +0 -0
  9. {calkit_python-0.0.5 → calkit_python-0.0.7}/README.md +0 -0
  10. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/cloud.py +0 -0
  11. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/config.py +0 -0
  12. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/core.py +0 -0
  13. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/data.py +0 -0
  14. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/dvc.py +0 -0
  15. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/git.py +0 -0
  16. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/gui.py +0 -0
  17. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/jupyter.py +0 -0
  18. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/models.py +0 -0
  19. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/server.py +0 -0
  20. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/tests/__init__.py +0 -0
  21. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/tests/test_core.py +0 -0
  22. {calkit_python-0.0.5 → calkit_python-0.0.7}/calkit/tests/test_jupyter.py +0 -0
  23. {calkit_python-0.0.5 → calkit_python-0.0.7}/examples/cfd-study/README.md +0 -0
  24. {calkit_python-0.0.5 → calkit_python-0.0.7}/examples/cfd-study/calkit.yaml +0 -0
  25. {calkit_python-0.0.5 → calkit_python-0.0.7}/examples/cfd-study/config/simulations/runs.csv +0 -0
  26. {calkit_python-0.0.5 → calkit_python-0.0.7}/examples/cfd-study/notebook.ipynb +0 -0
  27. {calkit_python-0.0.5 → calkit_python-0.0.7}/examples/ms-office/.gitignore +0 -0
  28. {calkit_python-0.0.5 → calkit_python-0.0.7}/examples/ms-office/README.md +0 -0
  29. {calkit_python-0.0.5 → calkit_python-0.0.7}/examples/ms-office/calkit.yaml +0 -0
  30. {calkit_python-0.0.5 → calkit_python-0.0.7}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: calkit-python
3
- Version: 0.0.5
3
+ Version: 0.0.7
4
4
  Summary: Reproducibility simplified.
5
5
  Project-URL: Homepage, https://github.com/calkit/calkit
6
6
  Project-URL: Issues, https://github.com/calkit/calkit/issues
@@ -1,4 +1,4 @@
1
- __version__ = "0.0.5"
1
+ __version__ = "0.0.7"
2
2
 
3
3
  from .core import *
4
4
  from . import git
@@ -21,6 +21,7 @@ app = typer.Typer(
21
21
  invoke_without_command=True,
22
22
  no_args_is_help=True,
23
23
  context_settings=dict(help_option_names=["-h", "--help"]),
24
+ pretty_exceptions_show_locals=False,
24
25
  )
25
26
  config_app = typer.Typer(no_args_is_help=True)
26
27
  new_app = typer.Typer(no_args_is_help=True)
@@ -104,33 +105,108 @@ def get_status():
104
105
 
105
106
 
106
107
  @app.command(name="add")
107
- def add(paths: list[str]):
108
+ def add(
109
+ paths: list[str],
110
+ commit_message: Annotated[
111
+ str,
112
+ typer.Option(
113
+ "-m",
114
+ "--commit-message",
115
+ help="Automatically commit and use this as a message.",
116
+ ),
117
+ ] = None,
118
+ push_commit: Annotated[
119
+ bool, typer.Option("--push", help="Push after committing.")
120
+ ] = False,
121
+ to: Annotated[
122
+ str,
123
+ typer.Option(
124
+ "--to", "-t", help="System with which to add (git or dvc)."
125
+ ),
126
+ ] = None,
127
+ ):
108
128
  """Add paths to the repo.
109
129
 
110
130
  Code will be added to Git and data will be added to DVC.
131
+
132
+ Note: This will enable the 'autostage' feature of DVC, automatically
133
+ adding any .dvc files to Git when adding to DVC.
111
134
  """
112
- dvc_extensions = [".png", ".h5", ".parquet", ".pickle"]
113
- dvc_size_thresh_bytes = 1_000_000
114
- dvc_folders = ["data", "figures"]
115
- if "." in paths:
116
- print("ERROR: Cannot add '.' with calkit; use git or dvc")
117
- sys.exit(1)
118
- for path in paths:
119
- if os.path.isdir(path):
120
- print("ERROR: Cannot add directories with calkit; use git or dvc")
121
- sys.exit(1)
122
- # Detect if this file should be tracked with Git or DVC
123
- # TODO: Add to whatever
135
+ if to is not None and to not in ["git", "dvc"]:
136
+ typer.echo(f"Invalid option for 'to': {to}")
137
+ raise typer.Exit(1)
138
+ # Ensure autostage is enabled for DVC
139
+ subprocess.call(["dvc", "config", "core.autostage", "true"])
140
+ subprocess.call(["git", "add", ".dvc/config"])
141
+ if to is not None:
142
+ subprocess.call([to, "add"] + paths)
143
+ else:
144
+ dvc_extensions = [
145
+ ".png",
146
+ ".h5",
147
+ ".parquet",
148
+ ".pickle",
149
+ ".mp4",
150
+ ".avi",
151
+ ".webm",
152
+ ".pdf",
153
+ ]
154
+ dvc_size_thresh_bytes = 1_000_000
155
+ if "." in paths and to is None:
156
+ typer.echo("Cannot add '.' with calkit; use git or dvc")
157
+ raise typer.Exit(1)
158
+ if to is None:
159
+ for path in paths:
160
+ if os.path.isdir(path):
161
+ typer.echo("Cannot auto-add directories; use git or dvc")
162
+ raise typer.Exit(1)
163
+ for path in paths:
164
+ # Detect if this file should be tracked with Git or DVC
165
+ if os.path.splitext(path)[-1] in dvc_extensions:
166
+ typer.echo(f"Adding {path} to DVC per its extension")
167
+ subprocess.call(["dvc", "add", path])
168
+ continue
169
+ if os.path.getsize(path) > dvc_size_thresh_bytes:
170
+ typer.echo(
171
+ f"Adding {path} to DVC since it's greater than 1 MB"
172
+ )
173
+ subprocess.call(["dvc", "add", path])
174
+ continue
175
+ typer.echo(f"Adding {path} to Git")
176
+ subprocess.call(["git", "add", path])
177
+ if commit_message is not None:
178
+ subprocess.call(["git", "commit", "-m", commit_message])
179
+ if push_commit:
180
+ push()
124
181
 
125
182
 
126
183
  @app.command(name="commit")
127
184
  def commit(
128
- all: Annotated[Optional[bool], typer.Option("--all", "-a")] = False,
129
- message: Annotated[Optional[str], typer.Option("--message", "-m")] = None,
185
+ all: Annotated[
186
+ Optional[bool],
187
+ typer.Option(
188
+ "--all", "-a", help="Automatically stage all changed files."
189
+ ),
190
+ ] = False,
191
+ message: Annotated[
192
+ Optional[str], typer.Option("--message", "-m", help="Commit message.")
193
+ ] = None,
194
+ push_commit: Annotated[
195
+ bool,
196
+ typer.Option(
197
+ "--push", help="Push to both Git and DVC after committing."
198
+ ),
199
+ ] = False,
130
200
  ):
131
201
  """Commit a change to the repo."""
132
- print(all, message)
133
- raise NotImplementedError
202
+ cmd = ["git", "commit"]
203
+ if all:
204
+ cmd.append("-a")
205
+ if message:
206
+ cmd += ["-m", message]
207
+ subprocess.call(cmd)
208
+ if push_commit:
209
+ push()
134
210
 
135
211
 
136
212
  @app.command(name="pull", help="Pull with both Git and DVC.")
@@ -270,15 +346,28 @@ def clean_notebook_outputs(path: str):
270
346
 
271
347
 
272
348
  @notebooks_app.command("execute")
273
- def execute_notebook(path: str):
274
- """Execute notebook and place a copy in the executed notebooks directory.
349
+ def execute_notebook(
350
+ path: str,
351
+ to: Annotated[
352
+ str, typer.Option("--to", help="Output format ('html' or 'notebook').")
353
+ ] = "notebook",
354
+ ):
355
+ """Execute notebook and place a copy in the relevant directory.
275
356
 
276
357
  This can be useful to use as a preprocessing DVC stage to use a clean
277
358
  notebook as a dependency for a stage that caches and executed notebook.
278
359
  """
279
360
  if os.path.isabs(path):
280
361
  raise ValueError("Path must be relative")
281
- fpath_out = os.path.join(".calkit", "notebooks", "executed", path)
362
+ if to == "html":
363
+ subdir = "html"
364
+ fname_out = path.removesuffix(".ipynb") + ".html"
365
+ elif to == "notebook":
366
+ subdir = "executed"
367
+ fname_out = path
368
+ else:
369
+ raise ValueError(f"Invalid output format: '{to}'")
370
+ fpath_out = os.path.join(".calkit", "notebooks", subdir, fname_out)
282
371
  folder = os.path.dirname(fpath_out)
283
372
  os.makedirs(folder, exist_ok=True)
284
373
  subprocess.call(
@@ -288,7 +377,7 @@ def execute_notebook(path: str):
288
377
  path,
289
378
  "--execute",
290
379
  "--to",
291
- "notebook",
380
+ to,
292
381
  "--output",
293
382
  fpath_out,
294
383
  ]
File without changes
File without changes
File without changes