lamindb 0.76.4__py3-none-any.whl → 0.76.5__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.
lamindb/__init__.py CHANGED
@@ -41,7 +41,7 @@ Modules and settings.
41
41
  """
42
42
 
43
43
  # denote a release candidate for 0.1.0 with 0.1rc1, 0.1a1, 0.1b1, etc.
44
- __version__ = "0.76.4"
44
+ __version__ = "0.76.5"
45
45
 
46
46
  import os as _os
47
47
 
@@ -108,6 +108,6 @@ if _check_instance_setup(from_lamindb=True):
108
108
  track = context.track # backward compat
109
109
  finish = context.finish # backward compat
110
110
  Curate = Curator # backward compat
111
- settings.__doc__ = """Global :class:`~lamindb.core.Settings`."""
112
- context.__doc__ = """Global :class:`~lamindb.core.Context`."""
111
+ settings.__doc__ = """Global settings (:class:`~lamindb.core.Settings`)."""
112
+ context.__doc__ = """Global run context (:class:`~lamindb.core.Context`)."""
113
113
  from django.db.models import Q
lamindb/_finish.py CHANGED
@@ -94,6 +94,7 @@ def save_context_core(
94
94
  transform: Transform,
95
95
  filepath: Path,
96
96
  finished_at: bool = False,
97
+ ignore_non_consecutive: bool | None = None,
97
98
  from_cli: bool = False,
98
99
  ) -> str | None:
99
100
  import lamindb as ln
@@ -118,17 +119,18 @@ def save_context_core(
118
119
  logger.error("install nbproject & jupytext: pip install nbproject jupytext")
119
120
  return None
120
121
  notebook_content = read_notebook(filepath) # type: ignore
121
- is_consecutive = check_consecutiveness(
122
- notebook_content, calling_statement=".finish()"
123
- )
124
- if not is_consecutive:
125
- msg = " Do you still want to proceed with finishing? (y/n) "
126
- if os.getenv("LAMIN_TESTING") is None:
127
- response = input(msg)
128
- else:
129
- response = "n"
130
- if response != "y":
131
- return "aborted-non-consecutive"
122
+ if not ignore_non_consecutive: # ignore_non_consecutive is None or False
123
+ is_consecutive = check_consecutiveness(
124
+ notebook_content, calling_statement=".finish()"
125
+ )
126
+ if not is_consecutive:
127
+ response = "n" # ignore_non_consecutive == False
128
+ if ignore_non_consecutive is None:
129
+ response = input(
130
+ " Do you still want to proceed with finishing? (y/n) "
131
+ )
132
+ if response != "y":
133
+ return "aborted-non-consecutive"
132
134
  # write the report
133
135
  report_path = ln_setup.settings.storage.cache_dir / filepath.name.replace(
134
136
  ".ipynb", ".html"
@@ -144,23 +146,20 @@ def save_context_core(
144
146
  hash, _ = hash_file(source_code_path) # ignore hash_type for now
145
147
  if (
146
148
  transform._source_code_artifact_id is not None
147
- or transform.source_code is not None
149
+ or transform.source_code is not None # equivalent to transform.hash is not None
148
150
  ):
149
151
  # check if the hash of the transform source code matches
150
152
  # (for scripts, we already run the same logic in track() - we can deduplicate the call at some point)
151
- if transform.hash is not None:
152
- condition = hash != transform.hash
153
- else:
154
- condition = hash != transform._source_code_artifact.hash
155
- if condition:
156
- if os.getenv("LAMIN_TESTING") is None:
157
- # in test, auto-confirm overwrite
158
- response = input(
159
- f"You are about to replace (overwrite) existing source code (hash '{transform._source_code_artifact.hash}') for transform version"
160
- f" '{transform.version}'. Proceed? (y/n)"
161
- )
162
- else:
163
- response = "y"
153
+ ref_hash = (
154
+ transform.hash
155
+ if transform.hash is not None
156
+ else transform._source_code_artifact.hash
157
+ )
158
+ if hash != ref_hash:
159
+ response = input(
160
+ f"You are about to overwrite existing source code (hash '{ref_hash}') for Transform('{transform.uid}')."
161
+ f"Proceed? (y/n)"
162
+ )
164
163
  if response == "y":
165
164
  transform.source_code = source_code_path.read_text()
166
165
  transform.hash = hash
@@ -210,13 +209,9 @@ def save_context_core(
210
209
  if run.report_id is not None:
211
210
  hash, _ = hash_file(report_path) # ignore hash_type for now
212
211
  if hash != run.report.hash:
213
- if os.getenv("LAMIN_TESTING") is None:
214
- # in test, auto-confirm overwrite
215
- response = input(
216
- f"You are about to replace (overwrite) an existing run report (hash '{run.report.hash}'). Proceed? (y/n)"
217
- )
218
- else:
219
- response = "y"
212
+ response = input(
213
+ f"You are about to overwrite an existing report (hash '{run.report.hash}') for Run('{run.uid}'). Proceed? (y/n)"
214
+ )
220
215
  if response == "y":
221
216
  run.report.replace(report_path)
222
217
  run.report.save(upload=True)
lamindb/_transform.py CHANGED
@@ -37,8 +37,11 @@ def __init__(transform: Transform, *args, **kwargs):
37
37
  "Only name, key, version, type, revises, reference, "
38
38
  f"reference_type can be passed, but you passed: {kwargs}"
39
39
  )
40
- if revises is None and key is not None:
41
- revises = Transform.filter(key=key).order_by("-created_at").first()
40
+ if revises is None:
41
+ if key is not None:
42
+ revises = Transform.filter(key=key).order_by("-created_at").first()
43
+ elif uid is not None and not uid.endswith("0000"):
44
+ revises = Transform.filter(uid__startswith=uid[:-4]).one_or_none()
42
45
  if revises is not None and key is not None and revises.key != key:
43
46
  note = message_update_key_in_version_family(
44
47
  suid=revises.stem_uid,
lamindb/core/_context.py CHANGED
@@ -7,6 +7,7 @@ from datetime import datetime, timezone
7
7
  from pathlib import Path, PurePath
8
8
  from typing import TYPE_CHECKING
9
9
 
10
+ import lamindb_setup as ln_setup
10
11
  from lamin_utils import logger
11
12
  from lamindb_setup.core.hashing import hash_file
12
13
  from lnschema_core import Run, Transform, ids
@@ -111,7 +112,18 @@ def pretty_pypackages(dependencies: dict) -> str:
111
112
  class Context:
112
113
  """Run context.
113
114
 
114
- Bundles all metadata to track run contexts.
115
+ Enables convenient data lineage tracking by managing a transform & run
116
+ upon :meth:`~lamindb.core.Context.track` & :meth:`~lamindb.core.Context.finish`.
117
+
118
+ Examples:
119
+
120
+ Is typically used via :class:`~lamindb.context`:
121
+
122
+ >>> import lamindb as ln
123
+ >>> ln.context.track()
124
+ >>> # do things while tracking data lineage
125
+ >>> ln.context.finish()
126
+
115
127
  """
116
128
 
117
129
  def __init__(self):
@@ -165,42 +177,35 @@ class Context:
165
177
  self,
166
178
  *,
167
179
  params: dict | None = None,
168
- transform: Transform | None = None,
169
180
  new_run: bool | None = None,
170
181
  path: str | None = None,
182
+ transform: Transform | None = None,
171
183
  ) -> None:
172
- """Track notebook or script run.
184
+ """Starts data lineage tracking for a run.
173
185
 
174
- Creates or loads a global :class:`~lamindb.Run` that enables data
175
- lineage tracking.
186
+ - sets :attr:`~lamindb.core.Context.transform` &
187
+ :attr:`~lamindb.core.Context.run` by creating or loading `Transform` &
188
+ `Run` records
189
+ - saves compute environment as a `requirements.txt` file: `run.environment`
176
190
 
177
- Saves source code and compute environment.
178
-
179
- If :attr:`~lamindb.core.Settings.sync_git_repo` is set, will first check
180
- whether the script exists in the git repository and add a link.
191
+ If :attr:`~lamindb.core.Settings.sync_git_repo` is set, checks whether a
192
+ script-like transform exists in a git repository and links it.
181
193
 
182
194
  Args:
183
195
  params: A dictionary of parameters to track for the run.
184
- transform: Can be of type `"pipeline"` or `"notebook"`
185
- (:class:`~lamindb.core.types.TransformType`).
186
196
  new_run: If `False`, loads latest run of transform
187
197
  (default notebook), if `True`, creates new run (default pipeline).
188
198
  path: Filepath of notebook or script. Only needed if it can't be
189
199
  automatically detected.
200
+ transform: Useful to track an abstract pipeline.
190
201
 
191
202
  Examples:
192
203
 
193
- To track a notebook or script, call:
204
+ To track the run of a notebook or script, call:
194
205
 
195
206
  >>> import lamindb as ln
196
207
  >>> ln.context.track()
197
208
 
198
- If you'd like to track an abstract pipeline run, pass a
199
- :class:`~lamindb.Transform` object of ``type`` ``"pipeline"``:
200
-
201
- >>> ln.Transform(name="Cell Ranger", version="2", type="pipeline").save()
202
- >>> transform = ln.Transform.get(name="Cell Ranger", version="2")
203
- >>> ln.context.track(transform=transform)
204
209
  """
205
210
  self._path = None
206
211
  if transform is None:
@@ -488,10 +493,31 @@ class Context:
488
493
  self._logging_message += f"loaded Transform('{transform.uid}')"
489
494
  self._transform = transform
490
495
 
491
- def finish(self) -> None:
492
- """Mark a tracked run as finished.
496
+ def finish(self, ignore_non_consecutive: None | bool = None) -> None:
497
+ """Mark the run context as finished.
498
+
499
+ - writes a timestamp: `run.finished_at`
500
+ - saves the source code: `transform.source_code`
501
+
502
+ When called in the last cell of a notebook:
503
+
504
+ - prompts for user input if not consecutively executed
505
+ - requires to save the notebook in your editor
506
+ - saves a run report: `run.report`
507
+
508
+ Args:
509
+ ignore_non_consecutive: Whether to ignore if a notebook was non-consecutively executed.
510
+
511
+ Examples:
512
+
513
+ >>> import lamindb as ln
514
+ >>> ln.context.track()
515
+ >>> # do things while tracking data lineage
516
+ >>> ln.context.finish()
517
+
518
+ See Also:
519
+ `lamin save script.py` or `lamin save notebook.ipynb` → `docs </cli#lamin-save>`__
493
520
 
494
- Saves source code and, for notebooks, a run report to your default storage location.
495
521
  """
496
522
  from lamindb._finish import save_context_core
497
523
 
@@ -510,18 +536,16 @@ class Context:
510
536
  # nothing else to do
511
537
  return None
512
538
  if is_run_from_ipython: # notebooks
513
- if (
514
- get_seconds_since_modified(context._path) > 3
515
- and os.getenv("LAMIN_TESTING") is None
516
- ):
539
+ if get_seconds_since_modified(context._path) > 2 and not ln_setup._TESTING:
517
540
  raise NotebookFileNotSavedToDisk(
518
- "Please save the notebook manually in your editor right before running `ln.finish()`"
541
+ "Please save the notebook manually in your editor right before running `ln.context.finish()`"
519
542
  )
520
543
  save_context_core(
521
544
  run=context.run,
522
545
  transform=context.run.transform,
523
546
  filepath=context._path,
524
547
  finished_at=True,
548
+ ignore_non_consecutive=ignore_non_consecutive,
525
549
  )
526
550
 
527
551
 
@@ -73,12 +73,16 @@ def save_vitessce_config(
73
73
  )
74
74
  else:
75
75
  dataset_artifacts.append(artifact)
76
- # link inputs
76
+ # the below will be replaced with a `ln.tracked()` decorator soon
77
77
  with logger.mute():
78
- transform = Transform(name="save_vitessce_config", type="function", version="2")
78
+ transform = Transform(
79
+ uid="kup03MJBsIVa0001",
80
+ name="save_vitessce_config",
81
+ type="function",
82
+ version="2",
83
+ )
79
84
  transform.save()
80
- run = Run(transform=transform)
81
- run.save()
85
+ run = Run(transform=transform).save()
82
86
  if len(dataset_artifacts) > 1:
83
87
  # if we have more datasets, we should create a collection
84
88
  # and attach an action to the collection
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lamindb
3
- Version: 0.76.4
3
+ Version: 0.76.5
4
4
  Summary: A data framework for biology.
5
5
  Author-email: Lamin Labs <open-source@lamin.ai>
6
6
  Requires-Python: >=3.8
@@ -10,9 +10,9 @@ Classifier: Programming Language :: Python :: 3.9
10
10
  Classifier: Programming Language :: Python :: 3.10
11
11
  Classifier: Programming Language :: Python :: 3.11
12
12
  Requires-Dist: lnschema_core==0.73.5
13
- Requires-Dist: lamindb_setup==0.76.8
13
+ Requires-Dist: lamindb_setup==0.77.1
14
14
  Requires-Dist: lamin_utils==0.13.4
15
- Requires-Dist: lamin_cli==0.17.0
15
+ Requires-Dist: lamin_cli==0.17.1
16
16
  Requires-Dist: rapidfuzz
17
17
  Requires-Dist: pyarrow
18
18
  Requires-Dist: typing_extensions!=4.6.0
@@ -1,4 +1,4 @@
1
- lamindb/__init__.py,sha256=faIPIM0ynMz0AU9pziDSQJT-rQhUXqpJ3PWRlmijqbs,2319
1
+ lamindb/__init__.py,sha256=jllkTTXtX6UHCCnv7BvPAywnywCNWlWm0l5UbCnK9nM,2344
2
2
  lamindb/_artifact.py,sha256=QjCge5kaAcfhGv84s299OT99LmHTSYDxgzw5kN-x3-8,44416
3
3
  lamindb/_can_validate.py,sha256=9di9FLmC2m3dpT42sceF34UEFzQITi2e_hjVMa8DIc4,18261
4
4
  lamindb/_collection.py,sha256=F_VgpLBprrzUQ-tPngWvO9vFd7jX66MVwIi031JOris,14871
@@ -6,7 +6,7 @@ lamindb/_curate.py,sha256=gCbDiqhsJzVZZ6BuEoFXUpsNOffpUNDlrX1dJiOqJJo,58753
6
6
  lamindb/_feature.py,sha256=nZhtrH0ssoNls-hV-dkwfK9sKypg2El59R9qfarxfUE,5340
7
7
  lamindb/_feature_set.py,sha256=DmAy96V_RyV0yiyvWOCHgustXPsCaMwn4TrWwh2qDd8,8104
8
8
  lamindb/_filter.py,sha256=9QHa9J-_6QeYPQATZpTun2VGiFofwzB0Km-KnKajHcM,663
9
- lamindb/_finish.py,sha256=NEZmTW7sWzwi-QYTwVgoOeeD-pZxWBrZOITK_YoJreU,9434
9
+ lamindb/_finish.py,sha256=riwm7mA-RXej_L0iz_svt6j5Z6faQb3NmQGKjAwhx8g,9282
10
10
  lamindb/_from_values.py,sha256=8kYpR8Q85EOaTcsPGjVHeZh29fGVgum5OEQf4Hsz_80,13533
11
11
  lamindb/_is_versioned.py,sha256=5lAnhTboltFkZCKVRV1uxkm0OCjJz_HKi3yQq_vEuMs,1306
12
12
  lamindb/_parents.py,sha256=eMavdd6IO6STOVJSlR2TzdRtx6sKYDKsMOtlR3DZlgQ,15599
@@ -16,12 +16,12 @@ lamindb/_record.py,sha256=53_0oU6v45V5gIDJgkAUSX7iIV5Si_4cuOWUHJa8JVo,21241
16
16
  lamindb/_run.py,sha256=5M_r1zGDv9HlqbqRKTWCYCOtENovJ-8mQ4kY7XqcLaU,1888
17
17
  lamindb/_save.py,sha256=Fu7Z84btKOXfTfpunKLni21s5ER2zIllqg5e3nPq-0A,10910
18
18
  lamindb/_storage.py,sha256=GBVChv-DHVMNEBJL5l_JT6B4RDhZ6NnwgzmUICphYKk,413
19
- lamindb/_transform.py,sha256=Rgj8uq6t4NpyP7DtQ-0IRJs7vSEKHyWftY5dvwKNFgs,4063
19
+ lamindb/_transform.py,sha256=ekwHQc4fv8PV1cffCYtTPfxL1RJtENd9_Y3v9CwxqYc,4213
20
20
  lamindb/_ulabel.py,sha256=XDSdZBXX_ki5s1vOths3MjF2x5DPggBR_PV_KF4SGyg,1611
21
21
  lamindb/_utils.py,sha256=LGdiW4k3GClLz65vKAVRkL6Tw-Gkx9DWAdez1jyA5bE,428
22
22
  lamindb/_view.py,sha256=4Ln2ItTb3857PAI-70O8eJYqoTJ_NNFc7E_wds6OGns,2412
23
23
  lamindb/core/__init__.py,sha256=hxPWM_Jnrllx0G_6itEGU2meXwptkkgiL9zsBvlhHM4,1495
24
- lamindb/core/_context.py,sha256=U-vmMH4s0ZfvS6KBRj5mOsOFuvcioJ7FgUdn0OOkLvA,19972
24
+ lamindb/core/_context.py,sha256=zt4aJz_IxPu3ujENyPjwJCebh_3w5Vu6QkDh0dspZFA,20719
25
25
  lamindb/core/_data.py,sha256=eocOXsZGu62LPtz6yIlvHhPSJTf3yF2ITZTffyflWYI,16269
26
26
  lamindb/core/_feature_manager.py,sha256=94tX6gq_Rx7fkDARQBxB2z92qUDpHocFSAdKv5izMT4,32490
27
27
  lamindb/core/_label_manager.py,sha256=zCE-PS1Y5ALpzoSOx1P6ZTFVPgFNRAmmyTQF0e8QBXA,9131
@@ -50,10 +50,10 @@ lamindb/core/subsettings/__init__.py,sha256=KFHPzIE7f7Bj4RgMjGQF4CjTdHVG_VNFBrCn
50
50
  lamindb/core/subsettings/_creation_settings.py,sha256=54mfMH_osC753hpxcl7Dq1rwBD2LHnWveXtQpkLBITE,1194
51
51
  lamindb/core/subsettings/_transform_settings.py,sha256=4YbCuZtJo6zdytl6UQR4GvdDkTtT6SRBqVzofGzNOt8,583
52
52
  lamindb/integrations/__init__.py,sha256=RWGMYYIzr8zvmNPyVB4m-p4gMDhxdRbjES2Ed23OItw,215
53
- lamindb/integrations/_vitessce.py,sha256=4DM_EXe-o7BVmX7QGTiwREWMHDzAtOqpqDvL70xQKfE,4451
53
+ lamindb/integrations/_vitessce.py,sha256=671jHIF8LgUjcOgRvJNhP0aK1Xty9pHkQ8ukx1U2gLY,4578
54
54
  lamindb/setup/__init__.py,sha256=OwZpZzPDv5lPPGXZP7-zK6UdO4FHvvuBh439yZvIp3A,410
55
55
  lamindb/setup/core/__init__.py,sha256=SevlVrc2AZWL3uALbE5sopxBnIZPWZ1IB0NBDudiAL8,167
56
- lamindb-0.76.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
57
- lamindb-0.76.4.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
58
- lamindb-0.76.4.dist-info/METADATA,sha256=X_O43XFARj0Vg5pAgez5uCI4IQG5jUp6cqd_pMAc0YQ,2372
59
- lamindb-0.76.4.dist-info/RECORD,,
56
+ lamindb-0.76.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
57
+ lamindb-0.76.5.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
58
+ lamindb-0.76.5.dist-info/METADATA,sha256=lmB6jhR6ZnklsigeYZFeCiNWMyGHqStcg_teeo1JmNk,2372
59
+ lamindb-0.76.5.dist-info/RECORD,,