lamin_cli 1.5.1__py2.py3-none-any.whl → 1.5.3__py2.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.
lamin_cli/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Lamin CLI."""
2
2
 
3
- __version__ = "1.5.1"
3
+ __version__ = "1.5.3"
lamin_cli/__main__.py CHANGED
@@ -9,8 +9,9 @@ from collections import OrderedDict
9
9
  from functools import wraps
10
10
  from importlib.metadata import PackageNotFoundError, version
11
11
  from pathlib import Path
12
- from typing import TYPE_CHECKING
12
+ from typing import TYPE_CHECKING, Literal
13
13
 
14
+ from lamin_utils import logger
14
15
  from lamindb_setup._init_instance import (
15
16
  DOC_DB,
16
17
  DOC_INSTANCE_NAME,
@@ -54,11 +55,11 @@ else:
54
55
  },
55
56
  {
56
57
  "name": "Read & write data",
57
- "commands": ["load", "save", "get", "delete"],
58
+ "commands": ["load", "save", "get", "delete", "create", "list"],
58
59
  },
59
60
  {
60
61
  "name": "Configure",
61
- "commands": ["cache", "settings", "migrate"],
62
+ "commands": ["checkout", "switch", "cache", "settings", "migrate"],
62
63
  },
63
64
  {
64
65
  "name": "Auth",
@@ -209,6 +210,66 @@ def disconnect():
209
210
  return close_()
210
211
 
211
212
 
213
+ # fmt: off
214
+ @main.command()
215
+ @click.argument("entity", type=str)
216
+ @click.option("--name", type=str, default=None, help="A name.")
217
+ # fmt: on
218
+ def create(entity: Literal["branch"], name: str | None = None):
219
+ """Create a record for an entity.
220
+
221
+ Currently only supports creating a branch.
222
+
223
+ ```
224
+ lamin create branch --name my_branch
225
+ ```
226
+ """
227
+ assert entity == "branch", "Currently only supports creating a branch."
228
+
229
+ from lamindb.models import Branch
230
+
231
+ branch = Branch(name=name).save()
232
+ logger.important(f"created branch: {branch.name}")
233
+
234
+
235
+ # fmt: off
236
+ @main.command(name="list")
237
+ @click.argument("entity", type=str)
238
+ @click.option("--name", type=str, default=None, help="A name.")
239
+ # fmt: on
240
+ def list_(entity: Literal["branch"], name: str | None = None):
241
+ """List records for an entity.
242
+
243
+ ```
244
+ lamin list branch
245
+ lamin list space
246
+ ```
247
+ """
248
+ assert entity in {"branch", "space"}, "Currently only supports listing branches and spaces."
249
+
250
+ from lamindb.models import Branch, Space
251
+
252
+ if entity == "branch":
253
+ print(Branch.df())
254
+ else:
255
+ print(Space.df())
256
+
257
+
258
+ # fmt: off
259
+ @main.command()
260
+ @click.option("--branch", type=str, default=None, help="A valid branch name or uid.")
261
+ @click.option("--space", type=str, default=None, help="A valid branch name or uid.")
262
+ # fmt: on
263
+ def switch(branch: str | None = None, space: str | None = None):
264
+ """Switch between branches or spaces.
265
+
266
+ Currently only supports creating a branch.
267
+ """
268
+ from lamindb.setup import switch as switch_
269
+
270
+ switch_(branch=branch, space=space)
271
+
272
+
212
273
  @main.command()
213
274
  @click.option("--schema", is_flag=True, help="View database schema.")
214
275
  def info(schema: bool):
@@ -226,17 +287,30 @@ def info(schema: bool):
226
287
 
227
288
  # fmt: off
228
289
  @main.command()
229
- @click.argument("instance", type=str, default=None)
230
- @click.option("--force", is_flag=True, default=False, help="Do not ask for confirmation.")
290
+ @click.argument("entity", type=str)
291
+ @click.option("--name", type=str, default=None)
292
+ @click.option("--slug", type=str, default=None)
293
+ @click.option("--force", is_flag=True, default=False, help="Do not ask for confirmation (only relevant for instance).")
231
294
  # fmt: on
232
- def delete(instance: str, force: bool = False):
295
+ def delete(entity: str, name: str | None = None, slug: str | None = None, force: bool = False):
233
296
  """Delete an entity.
234
297
 
235
- Currently only supports instance deletion.
298
+ Currently supported: `branch` and `instance`.
299
+
300
+ ```
301
+ lamin delete instance --slug account/name
302
+ lamin delete branch --name my_branch
303
+ ```
236
304
  """
305
+ from lamindb import Branch
237
306
  from lamindb_setup._delete import delete
238
307
 
239
- return delete(instance, force=force)
308
+ if entity == "branch":
309
+ Branch.get(name=name).delete()
310
+ elif entity == "instance":
311
+ return delete(slug, force=force)
312
+ else: # backwars compatibility
313
+ return delete(entity, force=force)
240
314
 
241
315
 
242
316
  @main.command()
lamin_cli/_load.py CHANGED
@@ -163,10 +163,11 @@ def load(
163
163
 
164
164
  # we don't use .get here because DoesNotExist is hard to catch
165
165
  # due to private django API
166
+ # we use `.objects` here because we don't want to exclude kind = __lamindb_run__ artifacts
166
167
  if query_by_uid:
167
- entities = EntityClass.filter(uid__startswith=uid)
168
+ entities = EntityClass.objects.filter(uid__startswith=uid)
168
169
  else:
169
- entities = EntityClass.filter(key=key)
170
+ entities = EntityClass.objects.filter(key=key)
170
171
 
171
172
  if (n_entities := len(entities)) == 0:
172
173
  err_msg = f"uid={uid}" if query_by_uid else f"key={key}"
lamin_cli/_save.py CHANGED
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING
6
6
 
7
7
  import click
8
8
  from lamin_utils import logger
9
+ from lamindb_setup.core.hashing import hash_file
9
10
 
10
11
  if TYPE_CHECKING:
11
12
  from pathlib import Path
@@ -155,6 +156,10 @@ def save_from_path_cli(
155
156
  return None
156
157
 
157
158
  if registry == "transform":
159
+ if key is not None:
160
+ logger.warning(
161
+ "key is ignored for transforms, the transform key is determined by the filename"
162
+ )
158
163
  if is_cloud_path:
159
164
  logger.error("Can not register a transform from a cloud path")
160
165
  return "transform-with-cloud-path"
@@ -201,8 +206,19 @@ def save_from_path_cli(
201
206
  if transform is None:
202
207
  uid = f"{stem_uid}0000"
203
208
  else:
204
- # TODO: account for folders and hash equivalence as we do in ln.track()
209
+ # TODO: account for folders as we do in ln.track()
210
+ transform_hash, _ = hash_file(path)
205
211
  transform = ln.Transform.filter(key=path.name, is_latest=True).one_or_none()
212
+ if transform is not None and transform.hash is not None:
213
+ if transform.hash == transform_hash:
214
+ logger.important(
215
+ f"found existing Transform('{uid}') with matching hash"
216
+ )
217
+ return None
218
+ else:
219
+ # we need to create a new version
220
+ stem_uid = transform.uid[:12]
221
+ transform = None
206
222
  revises = None
207
223
  if stem_uid is not None:
208
224
  revises = (
@@ -1,10 +1,9 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.3
2
2
  Name: lamin_cli
3
- Version: 1.5.1
3
+ Version: 1.5.3
4
4
  Summary: Lamin CLI.
5
5
  Author-email: Lamin Labs <open-source@lamin.ai>
6
6
  Description-Content-Type: text/markdown
7
- License-File: LICENSE
8
7
  Requires-Dist: rich-click>=1.7
9
8
  Project-URL: Home, https://github.com/laminlabs/lamin-cli
10
9
 
@@ -0,0 +1,14 @@
1
+ lamin_cli/__init__.py,sha256=LBeGwsZuICY7sdEYZSugLgtHOU3Wh7heajX7B22wO3I,40
2
+ lamin_cli/__main__.py,sha256=1hYODyzurDvq198STsIZ2slp_t_xq_c7QS0oyts33PA,15528
3
+ lamin_cli/_cache.py,sha256=oplwE8AcS_9PYptQUZxff2qTIdNFS81clGPkJNWk098,800
4
+ lamin_cli/_load.py,sha256=QqiFxGYmvFz2RjhvwKO5r1fmPWMZ5Ai4y1pJytdYKak,8301
5
+ lamin_cli/_migration.py,sha256=xQi6mwnpBzY5wcv1-TJhveD7a3XJIlpiYx6Z3AJ1NF0,1063
6
+ lamin_cli/_save.py,sha256=W4sNGXGFWy9ilFozVYbmxROCD8kkD0jDBB51cTLgZWA,10769
7
+ lamin_cli/_settings.py,sha256=O2tecCf5EIZu98ima4DTJujo4KuywckOLgw8c-Ke3dY,1142
8
+ lamin_cli/compute/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ lamin_cli/compute/modal.py,sha256=QnR7GyyvWWWkLnou95HxS9xxSQfw1k-SiefM_qRVnU0,6010
10
+ lamin_cli-1.5.3.dist-info/entry_points.txt,sha256=Qms85i9cZPlu-U7RnVZhFsF7vJ9gaLZUFkCjcGcXTpg,49
11
+ lamin_cli-1.5.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
+ lamin_cli-1.5.3.dist-info/WHEEL,sha256=ssQ84EZ5gH1pCOujd3iW7HClo_O_aDaClUbX4B8bjKY,100
13
+ lamin_cli-1.5.3.dist-info/METADATA,sha256=nKdmSG7KwhZG3c1l_G8FkROI9xFdy_zdwmg6leWo7_Q,337
14
+ lamin_cli-1.5.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: flit 3.12.0
2
+ Generator: flit 3.10.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any
@@ -1,14 +0,0 @@
1
- lamin_cli/__init__.py,sha256=LmyJRrP1UTrfQvwJPwpd_N8S8yv0IA87nvbNVtF82Iw,40
2
- lamin_cli/__main__.py,sha256=dHR3SNbuzg04ceVmTKdIPz2iXFCSdd2XsIb3OMmuvE0,13401
3
- lamin_cli/_cache.py,sha256=oplwE8AcS_9PYptQUZxff2qTIdNFS81clGPkJNWk098,800
4
- lamin_cli/_load.py,sha256=ow9IPQog_mPvjoGj1Bn08l4AG1YyRNnEyBpQvQkfLZs,8182
5
- lamin_cli/_migration.py,sha256=xQi6mwnpBzY5wcv1-TJhveD7a3XJIlpiYx6Z3AJ1NF0,1063
6
- lamin_cli/_save.py,sha256=wdTMmALkkNUpleUfXkNbh2Ila_pUIi5vhVbr30wLhEA,10069
7
- lamin_cli/_settings.py,sha256=O2tecCf5EIZu98ima4DTJujo4KuywckOLgw8c-Ke3dY,1142
8
- lamin_cli/compute/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- lamin_cli/compute/modal.py,sha256=QnR7GyyvWWWkLnou95HxS9xxSQfw1k-SiefM_qRVnU0,6010
10
- lamin_cli-1.5.1.dist-info/entry_points.txt,sha256=Qms85i9cZPlu-U7RnVZhFsF7vJ9gaLZUFkCjcGcXTpg,49
11
- lamin_cli-1.5.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
- lamin_cli-1.5.1.dist-info/WHEEL,sha256=Dyt6SBfaasWElUrURkknVFAZDHSTwxg3PaTza7RSbkY,100
13
- lamin_cli-1.5.1.dist-info/METADATA,sha256=Id-yCqUTghn94D3gvLc69Mhv2qxi1sPfCH3Oz4KPxsE,359
14
- lamin_cli-1.5.1.dist-info/RECORD,,