calkit-python 0.0.6__py3-none-any.whl → 0.0.7__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 CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "0.0.6"
1
+ __version__ = "0.0.7"
2
2
 
3
3
  from .core import *
4
4
  from . import git
calkit/cli.py CHANGED
@@ -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.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: calkit-python
3
- Version: 0.0.6
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,5 +1,5 @@
1
- calkit/__init__.py,sha256=MLdE9hjYmVEWkHdbusBCZDUzUC3oiY_AL-IfCGKX8eI,142
2
- calkit/cli.py,sha256=Ko3ntXUTqYeiLv00PQz68SWRp_vY1hruQgjmgwXnuzc,11788
1
+ calkit/__init__.py,sha256=uoXIE8mOCRYee4G20-SznuFNUiUdjdR8jJpkpbrYY-c,142
2
+ calkit/cli.py,sha256=IxF2P_sO2J9MiO8mIxYedVfjWWTTKlLYFGZqYXjPIxI,14112
3
3
  calkit/cloud.py,sha256=CnQKms4mBQo4X8jVLIa-70-3jPDl38zRNFyK5TjiaHM,2209
4
4
  calkit/config.py,sha256=NPFRk5inn66Wy44pyx8WppyqvIzkW1sO6VjXwIcCacE,2044
5
5
  calkit/core.py,sha256=qLNjBwlECzMitL85pMGIHzne4j7FpQAR9-ukYtdIMig,1225
@@ -13,8 +13,8 @@ calkit/server.py,sha256=gq3643ABKTQu1eVR_OqJ-SdQh2dPLHSFsipmmAK5ttA,5959
13
13
  calkit/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  calkit/tests/test_core.py,sha256=CdRqvYnq3MidyTknvfIbkmmhMfydpyKtTW9hakAvzsc,167
15
15
  calkit/tests/test_jupyter.py,sha256=YTL6zI740UM2KUjskSipzvSKxsyQ8rVPFQIX5cb2tMQ,114
16
- calkit_python-0.0.6.dist-info/METADATA,sha256=kL3dH09fqVyHjPjkKnclC21IAHwmwP8NNdvWgOEEthg,4004
17
- calkit_python-0.0.6.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
18
- calkit_python-0.0.6.dist-info/entry_points.txt,sha256=tiPfbDDZNB-YStw5YVO_4Gww0W3Dcdy8Mh6muX_GWnY,42
19
- calkit_python-0.0.6.dist-info/licenses/LICENSE,sha256=9ZamCaSUTZk9rcrnf-sWFKLOHr3ws-S_dgKMegW4nw8,1056
20
- calkit_python-0.0.6.dist-info/RECORD,,
16
+ calkit_python-0.0.7.dist-info/METADATA,sha256=IrdVfoHNAjkHwlKb3s_SsjMujO9QTKLi9lzY4Q3n9kE,4004
17
+ calkit_python-0.0.7.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
18
+ calkit_python-0.0.7.dist-info/entry_points.txt,sha256=tiPfbDDZNB-YStw5YVO_4Gww0W3Dcdy8Mh6muX_GWnY,42
19
+ calkit_python-0.0.7.dist-info/licenses/LICENSE,sha256=9ZamCaSUTZk9rcrnf-sWFKLOHr3ws-S_dgKMegW4nw8,1056
20
+ calkit_python-0.0.7.dist-info/RECORD,,