lamindb_setup 1.10.1__tar.gz → 1.11.0__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 (107) hide show
  1. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/PKG-INFO +1 -1
  2. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-cloud/03-add-managed-storage.ipynb +60 -59
  3. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/__init__.py +1 -1
  4. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_connect_instance.py +12 -9
  5. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_init_instance.py +1 -0
  6. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_migrate.py +8 -0
  7. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_schema_metadata.py +17 -13
  8. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_hub_core.py +8 -2
  9. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_settings.py +22 -2
  10. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/django.py +4 -1
  11. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/upath.py +10 -0
  12. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-cloud/scripts/script-init-pass-user-no-writes.py +1 -1
  13. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-cloud/scripts/script-to-fail-managed-storage.py +3 -2
  14. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-cloud/test_connect_instance.py +0 -1
  15. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/.github/workflows/build.yml +0 -0
  16. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/.github/workflows/doc-changes.yml +0 -0
  17. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/.gitignore +0 -0
  18. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/.pre-commit-config.yaml +0 -0
  19. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/LICENSE +0 -0
  20. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/README.md +0 -0
  21. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/changelog.md +0 -0
  22. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-cloud/01-init-local-instance.ipynb +0 -0
  23. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-cloud/02-connect-local-instance.ipynb +0 -0
  24. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-cloud/04-test-bionty.ipynb +0 -0
  25. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-cloud/05-init-hosted-instance.ipynb +0 -0
  26. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-cloud/06-connect-hosted-instance.ipynb +0 -0
  27. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-cloud/07-keep-artifacts-local.ipynb +0 -0
  28. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-cloud/08-test-multi-session.ipynb +0 -0
  29. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-cloud/09-test-migrate.ipynb +0 -0
  30. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-cloud/test_notebooks.py +0 -0
  31. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-prod/test-cache-management.ipynb +0 -0
  32. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-prod/test-cloud-sync.ipynb +0 -0
  33. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-prod/test-connect-anonymously.ipynb +0 -0
  34. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-prod/test-empty-init.ipynb +0 -0
  35. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-prod/test-import-schema.ipynb +0 -0
  36. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-prod/test-init-load-local-anonymously.ipynb +0 -0
  37. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-prod/test-insufficient-user-info.ipynb +0 -0
  38. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-prod/test-invalid-schema.ipynb +0 -0
  39. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-prod/test-sqlite-lock.ipynb +0 -0
  40. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/hub-prod/test_notebooks2.py +0 -0
  41. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/index.md +0 -0
  42. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/notebooks.md +0 -0
  43. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/docs/reference.md +0 -0
  44. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_cache.py +0 -0
  45. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_check.py +0 -0
  46. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_check_setup.py +0 -0
  47. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_delete.py +0 -0
  48. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_disconnect.py +0 -0
  49. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_django.py +0 -0
  50. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_entry_points.py +0 -0
  51. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_exportdb.py +0 -0
  52. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_importdb.py +0 -0
  53. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_register_instance.py +0 -0
  54. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_schema.py +0 -0
  55. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_set_managed_storage.py +0 -0
  56. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_setup_user.py +0 -0
  57. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/_silence_loggers.py +0 -0
  58. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/__init__.py +0 -0
  59. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_aws_options.py +0 -0
  60. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_aws_storage.py +0 -0
  61. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_deprecated.py +0 -0
  62. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_docs.py +0 -0
  63. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_hub_client.py +0 -0
  64. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_hub_crud.py +0 -0
  65. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_hub_utils.py +0 -0
  66. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_private_django_api.py +0 -0
  67. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_settings_instance.py +0 -0
  68. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_settings_load.py +0 -0
  69. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_settings_save.py +0 -0
  70. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_settings_storage.py +0 -0
  71. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_settings_store.py +0 -0
  72. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_settings_user.py +0 -0
  73. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/_setup_bionty_sources.py +0 -0
  74. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/cloud_sqlite_locker.py +0 -0
  75. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/exceptions.py +0 -0
  76. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/hashing.py +0 -0
  77. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/core/types.py +0 -0
  78. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/errors.py +0 -0
  79. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/py.typed +0 -0
  80. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/lamindb_setup/types.py +0 -0
  81. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/noxfile.py +0 -0
  82. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/pyproject.toml +0 -0
  83. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-cloud/test_delete_instance.py +0 -0
  84. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-cloud/test_edge_request.py +0 -0
  85. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-cloud/test_fail_managed_storage.py +0 -0
  86. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-cloud/test_init_instance.py +0 -0
  87. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-cloud/test_init_pass_user_no_writes.py +0 -0
  88. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-cloud/test_login.py +0 -0
  89. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-cloud/test_set_storage.py +0 -0
  90. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-local/conftest.py +0 -0
  91. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-local/scripts/script-connect-fine-grained-access.py +0 -0
  92. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-local/test_all.py +0 -0
  93. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-local/test_update_schema_in_hub.py +0 -0
  94. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-prod/conftest.py +0 -0
  95. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-prod/test_aws_options_manager.py +0 -0
  96. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-prod/test_django.py +0 -0
  97. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-prod/test_global_settings.py +0 -0
  98. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-prod/test_migrate.py +0 -0
  99. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-prod/test_switch_and_fallback_env.py +0 -0
  100. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/hub-prod/test_upath.py +0 -0
  101. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/storage/test_entry_point.py +0 -0
  102. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/storage/test_hashing.py +0 -0
  103. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/storage/test_storage_access.py +0 -0
  104. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/storage/test_storage_basis.py +0 -0
  105. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/storage/test_storage_settings.py +0 -0
  106. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/storage/test_storage_stats.py +0 -0
  107. {lamindb_setup-1.10.1 → lamindb_setup-1.11.0}/tests/storage/test_to_url.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lamindb_setup
3
- Version: 1.10.1
3
+ Version: 1.11.0
4
4
  Summary: Setup & configure LaminDB.
5
5
  Author-email: Lamin Labs <open-source@lamin.ai>
6
6
  Requires-Python: >=3.10
@@ -52,6 +52,7 @@
52
52
  "metadata": {},
53
53
  "outputs": [],
54
54
  "source": [
55
+ "import os\n",
55
56
  "import laminci\n",
56
57
  "import pytest\n",
57
58
  "from pathlib import Path\n",
@@ -305,6 +306,16 @@
305
306
  "Cloud storage:"
306
307
  ]
307
308
  },
309
+ {
310
+ "cell_type": "code",
311
+ "execution_count": null,
312
+ "id": "47affaad",
313
+ "metadata": {},
314
+ "outputs": [],
315
+ "source": [
316
+ "cloud_storage = f\"s3://lamindb-ci/storage3_{os.getenv('LAMIN_ENV', 'prod')}\""
317
+ ]
318
+ },
308
319
  {
309
320
  "cell_type": "code",
310
321
  "execution_count": null,
@@ -312,7 +323,7 @@
312
323
  "metadata": {},
313
324
  "outputs": [],
314
325
  "source": [
315
- "set_managed_storage(\"s3://lamindb-ci/storage3\")"
326
+ "set_managed_storage(cloud_storage)"
316
327
  ]
317
328
  },
318
329
  {
@@ -327,7 +338,7 @@
327
338
  "outputs": [],
328
339
  "source": [
329
340
  "assert ln_setup.settings.storage.type_is_cloud\n",
330
- "assert ln_setup.settings.storage.root_as_str == \"s3://lamindb-ci/storage3\"\n",
341
+ "assert ln_setup.settings.storage.root_as_str == cloud_storage\n",
331
342
  "assert ln_setup.settings.storage.region == \"us-west-1\"\n",
332
343
  "assert (\n",
333
344
  " ln_setup.settings.storage.root / \".lamindb/storage_uid.txt\"\n",
@@ -354,7 +365,7 @@
354
365
  "metadata": {},
355
366
  "outputs": [],
356
367
  "source": [
357
- "set_managed_storage(\"s3://lamindb-ci/storage3\", cache_regions=False)"
368
+ "set_managed_storage(cloud_storage, cache_regions=False)"
358
369
  ]
359
370
  },
360
371
  {
@@ -395,71 +406,61 @@
395
406
  "id": "83a2ee6b",
396
407
  "metadata": {},
397
408
  "source": [
398
- "Add testuser2 as a collaborator to the instance:"
409
+ "Add testuser2 as a collaborator to the instance, sign them in and let them add another storage location:"
399
410
  ]
400
411
  },
401
412
  {
402
413
  "cell_type": "code",
403
414
  "execution_count": null,
404
- "id": "9a4029b0",
415
+ "id": "67e455af",
405
416
  "metadata": {},
406
417
  "outputs": [],
407
418
  "source": [
408
- "from laminhub_rest.core.legacy._instance_collaborator import InstanceCollaboratorHandler\n",
409
- "from laminhub_rest.core.account import AccountHandler\n",
410
419
  "from lamindb_setup.core._hub_client import connect_hub_with_auth\n",
411
- "from lamindb.models import User\n",
420
+ "from laminhub_rest.core._central_client import SupabaseClientWrapper\n",
421
+ "from laminhub_rest.core.instance_collaborator import InstanceCollaboratorHandler\n",
422
+ "from laminhub_rest.core.organization import OrganizationMemberHandler\n",
423
+ "\n",
424
+ "admin_hub = SupabaseClientWrapper(connect_hub_with_auth())\n",
425
+ "organization_member_handler = OrganizationMemberHandler(admin_hub)\n",
426
+ "\n",
427
+ "assert ln_setup.settings.user.handle == \"testuser1\"\n",
428
+ "organization_id = ln_setup.settings.user._uuid # testuser1\n",
412
429
  "\n",
413
- "admin_hub = connect_hub_with_auth()\n",
414
- "testuser2 = AccountHandler(admin_hub).get_by_handle(\"testuser2\")\n",
415
- "InstanceCollaboratorHandler(admin_hub).add(\n",
416
- " instance_id=instance_id,\n",
417
- " account_id=testuser2.id,\n",
418
- " role=\"write\",\n",
419
- " schema_id=None,\n",
420
- " skip_insert_user_table=True,\n",
421
- ")\n",
422
- "User.objects.create(uid=testuser2.lnid, handle=testuser2.handle, name=testuser2.name)\n",
423
- "admin_hub.auth.close()"
424
- ]
425
- },
426
- {
427
- "cell_type": "markdown",
428
- "id": "e9d64cad",
429
- "metadata": {},
430
- "source": [
431
- "Sign them in and let them add another storage location:"
432
- ]
433
- },
434
- {
435
- "cell_type": "code",
436
- "execution_count": null,
437
- "id": "d6915638-db49-4d3d-bd91-819bb4719ef7",
438
- "metadata": {},
439
- "outputs": [],
440
- "source": [
441
430
  "ln_setup.login(\"testuser2\")\n",
442
- "set_managed_storage(\"./storage4\", host=\"testuser2-laptop\")\n",
443
- "assert ln_setup.settings.storage.root_as_str == f\"{Path.cwd()}/storage4\""
444
- ]
445
- },
446
- {
447
- "cell_type": "markdown",
448
- "id": "60ac7cb2",
449
- "metadata": {},
450
- "source": [
451
- "Attempt to delete instance with testuser2:"
452
- ]
453
- },
454
- {
455
- "cell_type": "code",
456
- "execution_count": null,
457
- "id": "6de90900",
458
- "metadata": {},
459
- "outputs": [],
460
- "source": [
461
- "with pytest.raises(PermissionError) as error:\n",
462
- " ln_setup.delete(\"testuser1/test-add-managed-storage\", force=True)"
431
+ "assert ln_setup.settings.user.handle == \"testuser2\"\n",
432
+ "account_id = ln_setup.settings.user._uuid\n",
433
+ "\n",
434
+ "try:\n",
435
+ " organization_member_handler.add(\n",
436
+ " organization_id=organization_id,\n",
437
+ " account_id=account_id,\n",
438
+ " role=\"member\",\n",
439
+ " )\n",
440
+ " try:\n",
441
+ " InstanceCollaboratorHandler(admin_hub).add(\n",
442
+ " account_id=account_id,\n",
443
+ " instance_id=instance_id,\n",
444
+ " role=\"write\",\n",
445
+ " )\n",
446
+ " except TypeError:\n",
447
+ " # the above failes in the mid due to no resource_db_server associated with the instance\n",
448
+ " # but still adds the collaborator\n",
449
+ " pass\n",
450
+ "\n",
451
+ " # although technically a user doesn't have to be a collaborator to insert into storage table\n",
452
+ " set_managed_storage(\"./storage4\", host=\"testuser2-laptop\")\n",
453
+ " assert ln_setup.settings.storage.root_as_str == f\"{Path.cwd()}/storage4\"\n",
454
+ " # attempt to delete the instance with testuser2\n",
455
+ " with pytest.raises(PermissionError) as error:\n",
456
+ " ln_setup.delete(\"testuser1/test-add-managed-storage\", force=True)\n",
457
+ "\n",
458
+ "finally:\n",
459
+ " organization_member_handler.remove(\n",
460
+ " organization_id=organization_id,\n",
461
+ " account_id=account_id,\n",
462
+ " )\n",
463
+ " admin_hub.auth.sign_out(options={\"scope\": \"local\"})"
463
464
  ]
464
465
  },
465
466
  {
@@ -510,7 +511,7 @@
510
511
  ],
511
512
  "metadata": {
512
513
  "kernelspec": {
513
- "display_name": "py312",
514
+ "display_name": "Python 3 (ipykernel)",
514
515
  "language": "python",
515
516
  "name": "python3"
516
517
  },
@@ -524,7 +525,7 @@
524
525
  "name": "python",
525
526
  "nbconvert_exporter": "python",
526
527
  "pygments_lexer": "ipython3",
527
- "version": "3.12.8"
528
+ "version": "3.10.16"
528
529
  }
529
530
  },
530
531
  "nbformat": 4,
@@ -35,7 +35,7 @@ Modules & settings:
35
35
 
36
36
  """
37
37
 
38
- __version__ = "1.10.1" # denote a release candidate for 0.1.0 with 0.1rc1
38
+ __version__ = "1.11.0" # denote a release candidate for 0.1.0 with 0.1rc1
39
39
 
40
40
  import os
41
41
 
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import importlib
4
4
  import os
5
5
  import sys
6
+ import types
6
7
  from typing import TYPE_CHECKING, Any
7
8
  from uuid import UUID
8
9
 
@@ -184,24 +185,26 @@ def _connect_instance(
184
185
  def reset_django_module_variables():
185
186
  # This function updates all module-level references to Django classes
186
187
  # But it will fail to update function level references
188
+ # This is not a problem unless for the function that calls ln.connect() itself
187
189
  # So, if a user has
190
+ #
188
191
  # def my_function():
189
192
  # import lamindb as ln
190
- # ...
193
+ # ln.connect(...)
191
194
  #
192
- # Then it will **not** work and the `ln` variable will become stale and hold a reference
195
+ # Then it will **not** work and the `ln` variable becomes stale and hold a reference
193
196
  # to the old classes
194
- # There doesn't seem to be an easy way to fix this problem
195
-
196
- logger.important_hint("resetting django module variables")
197
-
198
- import types
197
+ # Other functions that dynamically import are no problem because the variables
198
+ # are automatically refreshed when the function runs the next time after ln.connect() was called
199
+ logger.debug("resetting django module variables")
199
200
 
201
+ # django.apps needs to be a local import to refresh variables
200
202
  from django.apps import apps
201
203
 
202
204
  app_names = {app.name for app in apps.get_app_configs()}
203
-
204
- for name, module in sys.modules.items():
205
+ # always copy before iterations over sys.modules
206
+ # see https://docs.python.org/3/library/sys.html#sys.modules
207
+ for name, module in sys.modules.copy().items():
205
208
  if (
206
209
  module is not None
207
210
  and (not name.startswith("__") or name == "__main__")
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import importlib
4
4
  import os
5
5
  import uuid
6
+ from pathlib import Path
6
7
  from typing import TYPE_CHECKING, Literal
7
8
  from uuid import UUID
8
9
 
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import requests # type: ignore
3
4
  from django.db import connection
4
5
  from django.db.migrations.loader import MigrationLoader
5
6
  from lamin_utils import logger
@@ -142,6 +143,13 @@ class migrate:
142
143
  logger.important(f"updating lamindb version in hub: {lamindb.__version__}")
143
144
  if settings.instance.dialect != "sqlite":
144
145
  update_schema_in_hub()
146
+ logger.warning(
147
+ "clearing instance cache in hub; if this fails, re-run with latest lamindb version"
148
+ )
149
+ requests.delete(
150
+ f"{settings.instance.api_url}/cache/instances/{settings.instance._id.hex}",
151
+ headers={"Authorization": f"Bearer {settings.user.access_token}"},
152
+ )
145
153
  call_with_fallback_auth(
146
154
  update_instance,
147
155
  instance_id=settings.instance._id.hex,
@@ -404,23 +404,27 @@ class _SchemaHandler:
404
404
  return self.to_dict(include_django_objects=False)
405
405
 
406
406
  def _get_modules_metadata(self):
407
+ from django.apps import apps
407
408
  from lamindb.models import Registry, SQLRecord
408
409
 
409
- all_models = {
410
- module_name: {
411
- model._meta.model_name: _ModelHandler(
412
- model, module_name, self.included_modules
413
- )
414
- for model in self._get_schema_module(
415
- module_name
416
- ).models.__dict__.values()
417
- if model.__class__ is Registry
410
+ all_models = {module_name: {} for module_name in self.included_modules}
411
+
412
+ # Iterate through all registered Django models
413
+ for model in apps.get_models():
414
+ # Check if model meets the criteria
415
+ if (
416
+ model.__class__ is Registry
418
417
  and model is not SQLRecord
419
418
  and not model._meta.abstract
420
- and model.__get_module_name__() == module_name
421
- }
422
- for module_name in self.included_modules
423
- }
419
+ ):
420
+ module_name = model.__get_module_name__()
421
+ # Only include if module is in our included list
422
+ if module_name in self.included_modules:
423
+ model_name = model._meta.model_name
424
+ all_models[module_name][model_name] = _ModelHandler(
425
+ model, module_name, self.included_modules
426
+ )
427
+
424
428
  assert all_models
425
429
  return all_models
426
430
 
@@ -661,7 +661,12 @@ def _sign_in_hub(email: str, password: str, handle: str | None, client: Client):
661
661
  "password": password,
662
662
  }
663
663
  )
664
- data = client.table("account").select("*").eq("id", auth.user.id).execute().data
664
+ # normally public.account.id is equal to auth.user.id
665
+ # but it might be not the case in the future
666
+ # this is why we check public.account.user_id that references auth.user.id
667
+ data = (
668
+ client.table("account").select("*").eq("user_id", auth.user.id).execute().data
669
+ )
665
670
  if data: # sync data from hub to local cache in case it was updated on the hub
666
671
  user = data[0]
667
672
  user_uuid = UUID(user["id"])
@@ -710,8 +715,9 @@ def _sign_in_hub_api_key(api_key: str, client: Client):
710
715
  # probably need more info here to avoid additional queries
711
716
  # like handle, uid etc
712
717
  account_id = jwt.decode(access_token, options={"verify_signature": False})["sub"]
718
+
713
719
  client.postgrest.auth(access_token)
714
- # normally public.account.id is equal to auth.user.id
720
+
715
721
  data = client.table("account").select("*").eq("id", account_id).execute().data
716
722
  if data:
717
723
  user = data[0]
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import os
4
4
  import sys
5
5
  import warnings
6
+ from pathlib import Path
6
7
  from typing import TYPE_CHECKING
7
8
 
8
9
  from lamin_utils import logger
@@ -23,8 +24,6 @@ from ._settings_store import (
23
24
  from .upath import LocalPathClasses, UPath
24
25
 
25
26
  if TYPE_CHECKING:
26
- from pathlib import Path
27
-
28
27
  from lamindb.models import Branch, Space
29
28
 
30
29
  from lamindb_setup.core import InstanceSettings, StorageSettings, UserSettings
@@ -60,6 +59,7 @@ class SetupSettings:
60
59
 
61
60
  _auto_connect_path: Path = settings_dir / "auto_connect"
62
61
  _private_django_api_path: Path = settings_dir / "private_django_api"
62
+ _work_dir: Path = settings_dir / "work_dir.txt"
63
63
 
64
64
  _cache_dir: Path | None = None
65
65
 
@@ -70,6 +70,25 @@ class SetupSettings:
70
70
  def _instance_settings_path(self) -> Path:
71
71
  return current_instance_settings_file()
72
72
 
73
+ @property
74
+ def work_dir(self) -> Path | None:
75
+ """Get or set the current working directory.
76
+
77
+ If setting it to `None`, the working directory is unset
78
+ """
79
+ if not self._work_dir.exists():
80
+ return None
81
+ return Path(self._work_dir.read_text())
82
+
83
+ @work_dir.setter
84
+ def work_dir(self, value: str | Path | None) -> None:
85
+ if value is None:
86
+ if self._work_dir.exists():
87
+ self._work_dir.unlink()
88
+ else:
89
+ value_str = Path(value).expanduser().resolve().as_posix()
90
+ self._work_dir.write_text(value_str)
91
+
73
92
  @property
74
93
  def settings_dir(self) -> Path:
75
94
  """The directory that holds locally persisted settings."""
@@ -317,6 +336,7 @@ class SetupSettings:
317
336
  repr += "\nConfig:\n"
318
337
  repr += f" - private Django API: {self.private_django_api}\n"
319
338
  repr += "Local directories:\n"
339
+ repr += f" - working directory: {self.work_dir}\n"
320
340
  repr += f" - cache: {self.cache_dir.as_posix()}\n"
321
341
  repr += f" - user settings: {settings_dir.as_posix()}\n"
322
342
  repr += f" - system settings: {system_settings_dir.as_posix()}\n"
@@ -168,7 +168,10 @@ def setup_django(
168
168
  ssl_require = False
169
169
  else:
170
170
  ssl_require = not is_local_db_url(instance_db)
171
- options = {"connect_timeout": os.getenv("PGCONNECT_TIMEOUT", 20)}
171
+ options = {
172
+ "connect_timeout": os.getenv("PGCONNECT_TIMEOUT", 20),
173
+ "gssencmode": "disable",
174
+ }
172
175
  else:
173
176
  ssl_require = False
174
177
  options = {}
@@ -3,6 +3,7 @@
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
+ import math
6
7
  import os
7
8
  import warnings
8
9
  from collections import defaultdict
@@ -353,6 +354,15 @@ def upload_from(
353
354
  destination = fsspec.utils.other_paths(
354
355
  files, self.as_posix(), exists=False, flatten=False
355
356
  )
357
+ elif self.protocol == "s3" and "chunksize" not in kwargs:
358
+ size = local_path.stat().st_size
359
+ MiB = 1024**2
360
+ DEFAULT_CHUNKSIZE = 50 * MiB # so in s3fs
361
+ if size / DEFAULT_CHUNKSIZE > 10000: # should be no more than 10k parts for s3
362
+ raw = math.ceil(size / 10000)
363
+ step = 5 * MiB
364
+ rounded = math.ceil(raw / step) * step
365
+ kwargs["chunksize"] = rounded
356
366
 
357
367
  # the below lines are to avoid s3fs triggering create_bucket in upload if
358
368
  # dirs are present, it allows to avoid the permission error
@@ -16,7 +16,7 @@ current_instance_exists = current_instance_file.exists()
16
16
  testuser1 = load_user_settings(user_settings_file_handle("testuser1"))
17
17
  assert testuser1.handle == "testuser1"
18
18
 
19
- storage = f"s3://lamindb-ci/{os.environ['LAMIN_ENV']}_test/test-init-no-writes"
19
+ storage = f"s3://lamindb-ci/{os.getenv('LAMIN_ENV', 'prod')}_test/test-init-no-writes"
20
20
 
21
21
  ln_setup.init(
22
22
  storage=storage,
@@ -14,9 +14,10 @@ test_root = Path("./test_script_ci_storage").resolve().as_posix()
14
14
 
15
15
  with pytest.raises(ProgrammingError) as error:
16
16
  set_managed_storage(test_root, host="test-host-1234")
17
- assert error.exconly().endswith(
17
+ error_str = error.exconly()
18
+ assert error_str.endswith(
18
19
  "ProgrammingError: permission denied for table lamindb_storage"
19
- )
20
+ ), error_str
20
21
 
21
22
  hub_client = connect_hub_with_auth()
22
23
 
@@ -39,7 +39,6 @@ def test_connect_after_revoked_access():
39
39
  "testuser1/static-test-instance-private-sqlite",
40
40
  "testuser2",
41
41
  "write",
42
- "default",
43
42
  skip_insert_user_table=True,
44
43
  )
45
44
  except APIError:
File without changes
File without changes