lamindb_setup 0.80.0__py3-none-any.whl → 0.80.1__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_setup/__init__.py CHANGED
@@ -33,7 +33,7 @@ Modules & settings:
33
33
 
34
34
  """
35
35
 
36
- __version__ = "0.80.0" # denote a release candidate for 0.1.0 with 0.1rc1
36
+ __version__ = "0.80.1" # denote a release candidate for 0.1.0 with 0.1rc1
37
37
 
38
38
  import os as _os
39
39
  import sys as _sys
@@ -415,9 +415,10 @@ def infer_instance_name(
415
415
  if storage == "create-s3":
416
416
  raise ValueError("pass name to init if storage = 'create-s3'")
417
417
  storage_path = UPath(storage)
418
+ # not sure if name is ever ""
418
419
  if storage_path.name != "":
419
420
  name = storage_path.name
420
421
  else:
421
422
  # dedicated treatment of bucket names
422
- name = storage_path._url.netloc
423
+ name = storage_path.drive
423
424
  return name.lower()
@@ -15,9 +15,7 @@ HOSTED_REGIONS = [
15
15
  ]
16
16
  lamin_env = os.getenv("LAMIN_ENV")
17
17
  if lamin_env is None or lamin_env == "prod":
18
- hosted_buckets_list = [f"s3://lamin-{region}" for region in HOSTED_REGIONS]
19
- hosted_buckets_list.append("s3://scverse-spatial-eu-central-1")
20
- HOSTED_BUCKETS = tuple(hosted_buckets_list)
18
+ HOSTED_BUCKETS = tuple([f"s3://lamin-{region}" for region in HOSTED_REGIONS])
21
19
  else:
22
20
  HOSTED_BUCKETS = ("s3://lamin-hosted-test",) # type: ignore
23
21
 
@@ -29,6 +27,11 @@ def _keep_trailing_slash(path_str: str):
29
27
  AWS_CREDENTIALS_EXPIRATION = 11 * 60 * 60 # refresh credentials after 11 hours
30
28
 
31
29
 
30
+ # set anon=True for these buckets if credentials fail for a public bucket
31
+ # to be expanded
32
+ PUBLIC_BUCKETS = ("cellxgene-data-public",)
33
+
34
+
32
35
  class AWSCredentialsManager:
33
36
  def __init__(self):
34
37
  self._credentials_cache = {}
@@ -38,7 +41,15 @@ class AWSCredentialsManager:
38
41
  # this is cached so will be resued with the connection initialized
39
42
  fs = S3FileSystem(cache_regions=True)
40
43
  fs.connect()
41
- self.anon = fs.session._credentials is None
44
+ self.anon: bool = fs.session._credentials is None
45
+ self.anon_public: bool | None = None
46
+ if not self.anon:
47
+ try:
48
+ # use lamindata public bucket for this test
49
+ fs.call_s3("head_bucket", Bucket="lamindata")
50
+ self.anon_public = False
51
+ except Exception as e:
52
+ self.anon_public = isinstance(e, PermissionError)
42
53
 
43
54
  def _find_root(self, path_str: str) -> str | None:
44
55
  roots = self._credentials_cache.keys()
@@ -73,6 +84,8 @@ class AWSCredentialsManager:
73
84
  anon = False
74
85
  else:
75
86
  anon = self.anon
87
+ if not anon and self.anon_public and path.drive in PUBLIC_BUCKETS:
88
+ anon = True
76
89
  connection_options = {"anon": anon}
77
90
  else:
78
91
  connection_options = credentials
@@ -132,7 +145,7 @@ class AWSCredentialsManager:
132
145
  root = "/".join(path.path.rstrip("/").split("/")[:2])
133
146
  else:
134
147
  # write the bucket for everything else
135
- root = path._url.netloc
148
+ root = path.drive
136
149
  root = "s3://" + root
137
150
  self._set_cached_credentials(_keep_trailing_slash(root), credentials)
138
151
 
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os
4
+ import sys
4
5
  from typing import TYPE_CHECKING
5
6
 
6
7
  from appdirs import AppDirs
@@ -172,6 +173,9 @@ class SetupSettings:
172
173
 
173
174
  def __repr__(self) -> str:
174
175
  """Rich string representation."""
176
+ # do not show current setting representation when building docs
177
+ if "sphinx" in sys.modules:
178
+ return object.__repr__(self)
175
179
  repr = self.user.__repr__()
176
180
  repr += f"\nAuto-connect in Python: {self.auto_connect}\n"
177
181
  repr += f"Private Django API: {self.private_django_api}\n"
@@ -8,14 +8,14 @@ from collections import defaultdict
8
8
  from datetime import datetime, timezone
9
9
  from functools import partial
10
10
  from itertools import islice
11
- from pathlib import Path, PurePosixPath
11
+ from pathlib import Path, PosixPath, PurePosixPath, WindowsPath
12
12
  from typing import TYPE_CHECKING, Any, Literal
13
13
 
14
14
  import fsspec
15
15
  from lamin_utils import logger
16
16
  from upath import UPath
17
17
  from upath.implementations.cloud import CloudPath, S3Path # keep CloudPath!
18
- from upath.implementations.local import LocalPath, PosixUPath, WindowsUPath
18
+ from upath.implementations.local import LocalPath
19
19
 
20
20
  from ._aws_credentials import HOSTED_BUCKETS, get_aws_credentials_manager
21
21
  from .hashing import HASH_LENGTH, b16_to_b64, hash_md5s_from_dir
@@ -23,7 +23,7 @@ from .hashing import HASH_LENGTH, b16_to_b64, hash_md5s_from_dir
23
23
  if TYPE_CHECKING:
24
24
  from .types import UPathStr
25
25
 
26
- LocalPathClasses = (PosixUPath, WindowsUPath, LocalPath)
26
+ LocalPathClasses = (PosixPath, WindowsPath, LocalPath)
27
27
 
28
28
  # also see https://gist.github.com/securifera/e7eed730cbe1ce43d0c29d7cd2d582f4
29
29
  # ".gz" is not listed here as it typically occurs with another suffix
@@ -291,21 +291,25 @@ def upload_from(
291
291
  callback = ProgressCallback(local_path.name, "uploading")
292
292
  kwargs["callback"] = callback
293
293
 
294
+ source: str | list[str]
295
+ destination: str | list[str]
294
296
  if local_path_is_dir and not create_folder:
295
- source = [f for f in local_path.rglob("*") if f.is_file()]
296
- destination = [str(self / f.relative_to(local_path)) for f in source]
297
- source = [str(f) for f in source] # type: ignore
297
+ source = [f.as_posix() for f in local_path.rglob("*") if f.is_file()]
298
+ destination = fsspec.utils.other_paths(
299
+ source, self.as_posix(), exists=False, flatten=False
300
+ )
298
301
  else:
299
- source = str(local_path) # type: ignore
300
- destination = str(self) # type: ignore
302
+ source = local_path.as_posix()
303
+ destination = self.as_posix()
301
304
 
302
305
  # the below lines are to avoid s3fs triggering create_bucket in upload if
303
306
  # dirs are present it allows to avoid permission error
304
307
  # would be easier to just
305
308
  if self.protocol == "s3" and local_path_is_dir and create_folder:
306
- bucket = self._url.netloc
309
+ bucket = self.drive
307
310
  if bucket not in self.fs.dircache:
308
311
  self.fs.dircache[bucket] = [{}]
312
+ assert isinstance(destination, str)
309
313
  if not destination.endswith(TRAILING_SEP): # type: ignore
310
314
  destination += "/"
311
315
  cleanup_cache = True
@@ -399,8 +403,8 @@ def synchronize(
399
403
  callback.set_size(len(files))
400
404
  origin_file_keys = []
401
405
  for file, stat in callback.wrap(files.items()):
402
- file_key = PurePosixPath(file).relative_to(self.path)
403
- origin_file_keys.append(file_key.as_posix())
406
+ file_key = PurePosixPath(file).relative_to(self.path).as_posix()
407
+ origin_file_keys.append(file_key)
404
408
  timestamp = stat[modified_key].timestamp()
405
409
 
406
410
  origin = f"{self.protocol}://{file}"
@@ -615,11 +619,11 @@ def to_url(upath):
615
619
  if upath.protocol != "s3":
616
620
  raise ValueError("The provided UPath must be an S3 path.")
617
621
  key = "/".join(upath.parts[1:])
618
- bucket = upath._url.netloc
622
+ bucket = upath.drive
619
623
  if bucket == "scverse-spatial-eu-central-1":
620
624
  region = "eu-central-1"
621
625
  elif f"s3://{bucket}" not in HOSTED_BUCKETS:
622
- response = upath.fs.call_s3("head_bucket", Bucket=upath._url.netloc)
626
+ response = upath.fs.call_s3("head_bucket", Bucket=bucket)
623
627
  headers = response["ResponseMetadata"]["HTTPHeaders"]
624
628
  region = headers.get("x-amz-bucket-region")
625
629
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lamindb_setup
3
- Version: 0.80.0
3
+ Version: 0.80.1
4
4
  Summary: Setup & configure LaminDB.
5
5
  Author-email: Lamin Labs <open-source@lamin.ai>
6
6
  Requires-Python: >=3.9
@@ -1,4 +1,4 @@
1
- lamindb_setup/__init__.py,sha256=hCbASHI6nzxl7Xre0B3sTSQaCJ5mWkjI2xSF2odlJ8Q,1714
1
+ lamindb_setup/__init__.py,sha256=kc1LSkxZIe6SeFBsho6Xg6WyYxKcsUYoLNgQlQSRnxo,1714
2
2
  lamindb_setup/_cache.py,sha256=1XnM-V_KprbjpgPY7Bg3FYn53Iz_2_fEgcMOaSdKKbg,1332
3
3
  lamindb_setup/_check.py,sha256=28PcG8Kp6OpjSLSi1r2boL2Ryeh6xkaCL87HFbjs6GA,129
4
4
  lamindb_setup/_check_setup.py,sha256=6cSfpmVOSgU7YiVHfJpBTGTQ7rrnwunt1pJT_jkgNM8,3196
@@ -9,7 +9,7 @@ lamindb_setup/_django.py,sha256=DWUTjjVhEViX0S-zIkeqQgKovWqVgWMl4Y0ANwlA3Pw,1505
9
9
  lamindb_setup/_entry_points.py,sha256=Hs2oJQOCTaGUdWn-1mufM6qUZr9W_EJ_Oc3f0_Vc0Yw,616
10
10
  lamindb_setup/_exportdb.py,sha256=43g77-tH-vAlTn8ig1mMD9-KXLKvxUeDLaq0gVu3l-c,2114
11
11
  lamindb_setup/_importdb.py,sha256=yYYShzUajTsR-cTW4CZ-UNDWZY2uE5PAgNbp-wn8Ogc,1874
12
- lamindb_setup/_init_instance.py,sha256=6Db289T2A2464KqW0NsfSKg59zrhfny9RZxBgb9kPVs,14340
12
+ lamindb_setup/_init_instance.py,sha256=zJbkP22h4Yif_VNooL06FFoHqH1EU45CqiLwF8FUaKs,14368
13
13
  lamindb_setup/_migrate.py,sha256=x_b4k4XRfLSD-EEFMc324yK6DIK7goW33wUytbIWlNs,8917
14
14
  lamindb_setup/_register_instance.py,sha256=alQuYp2f8Ct8xvRC1gt8p_HZ0tqCd3gZD3kiPBLPpsI,1269
15
15
  lamindb_setup/_schema.py,sha256=b3uzhhWpV5mQtDwhMINc2MabGCnGLESy51ito3yl6Wc,679
@@ -18,7 +18,7 @@ lamindb_setup/_set_managed_storage.py,sha256=4tDxXQMt8Gw028uY3vIQxZQ7qBNXhQMc8sa
18
18
  lamindb_setup/_setup_user.py,sha256=-g7Xj6510BDyM8kuqAsVBZFwehlhBa_uWBSV1rPeuM8,4586
19
19
  lamindb_setup/_silence_loggers.py,sha256=AKF_YcHvX32eGXdsYK8MJlxEaZ-Uo2f6QDRzjKFCtws,1568
20
20
  lamindb_setup/core/__init__.py,sha256=BxIVMX5HQq8oZ1OuY_saUEJz5Tdd7gaCPngxVu5iou4,417
21
- lamindb_setup/core/_aws_credentials.py,sha256=uKMQO9q42Hnepz8aj3RxwLKDWUJx8pNOYrFnnNh5X40,5325
21
+ lamindb_setup/core/_aws_credentials.py,sha256=E8yanKOq-idaIz5y9D9SazHaYJKX69VLK3pn7jl82do,5815
22
22
  lamindb_setup/core/_aws_storage.py,sha256=nEjeUv4xUVpoV0Lx-zjjmyb9w804bDyaeiM-OqbfwM0,1799
23
23
  lamindb_setup/core/_deprecated.py,sha256=3qxUI1dnDlSeR0BYrv7ucjqRBEojbqotPgpShXs4KF8,2520
24
24
  lamindb_setup/core/_docs.py,sha256=3k-YY-oVaJd_9UIY-LfBg_u8raKOCNfkZQPA73KsUhs,276
@@ -27,7 +27,7 @@ lamindb_setup/core/_hub_core.py,sha256=eUxRz9iJj6RA5-MWgQqqZYAU-di5LQDamRZn6t-VO
27
27
  lamindb_setup/core/_hub_crud.py,sha256=eZErpq9t1Cp2ULBSi457ekrcqfesw4Y6IJgaqyrINMY,5276
28
28
  lamindb_setup/core/_hub_utils.py,sha256=08NwQsb53-tXa_pr-f0tPTN0FeeVf_i1p3dEbEWD0F4,3016
29
29
  lamindb_setup/core/_private_django_api.py,sha256=KIn43HOhiRjkbTbddyJqv-WNTTa1bAizbM1tWXoXPBg,2869
30
- lamindb_setup/core/_settings.py,sha256=Iv2FUz1l92V4AcuyvRsYlJxoY1oB-UB4gAaA6QgWioE,7792
30
+ lamindb_setup/core/_settings.py,sha256=mpGsSb98UsBedLsW2RuowZ17EP2tI2XRGPztqrJtrV4,7952
31
31
  lamindb_setup/core/_settings_instance.py,sha256=ajcq9zRNE598tTqyMkMqaEOubVfFeE998DPtbgyzK3A,18801
32
32
  lamindb_setup/core/_settings_load.py,sha256=5OpghcbkrK9KBM_0Iu-61FTI76UbOpPkkJpUittXS-w,4098
33
33
  lamindb_setup/core/_settings_save.py,sha256=rxGxgaK5i9exKqSJERQQyY1WZio20meoQJoYXlVW-1w,3138
@@ -40,8 +40,8 @@ lamindb_setup/core/django.py,sha256=E4U9nUlV2kHd-G5v6iSdFGAAWixlQDxOFwMwOMG9xfw,
40
40
  lamindb_setup/core/exceptions.py,sha256=4NpLUNUIfXYVTFX2FvLZF8RW34exk2Vn2X3G4YhnTRg,276
41
41
  lamindb_setup/core/hashing.py,sha256=bkuvZyAuC7-Y_qZumJd_rybF-upJ5J3KxnKiymRUifw,3148
42
42
  lamindb_setup/core/types.py,sha256=zJii2le38BJUmsNVvzDrbzGYr0yaeb-9Rw9IKmsBr3k,523
43
- lamindb_setup/core/upath.py,sha256=DJ0S3JufnCmG6EAGy2eqTp5rVX3Oqw-bUlh9-9ipKYI,27091
44
- lamindb_setup-0.80.0.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
45
- lamindb_setup-0.80.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
46
- lamindb_setup-0.80.0.dist-info/METADATA,sha256=IBWXhrRyGmMeYdgByW0TJV2h70cSVssuxA1Do6cmfLM,1743
47
- lamindb_setup-0.80.0.dist-info/RECORD,,
43
+ lamindb_setup/core/upath.py,sha256=q6WvpdXO_-Ajl5qjU4CIf0Q1ZbYxA0Po54LG9iHYn28,27151
44
+ lamindb_setup-0.80.1.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
45
+ lamindb_setup-0.80.1.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
46
+ lamindb_setup-0.80.1.dist-info/METADATA,sha256=kMZ0UUKGc3sxehsLkXFPedNRYpo_VNNHKA-iu7I5W4I,1743
47
+ lamindb_setup-0.80.1.dist-info/RECORD,,