obi-notebook 0.2.dev2__tar.gz → 0.4__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 (22) hide show
  1. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/PKG-INFO +1 -1
  2. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/example.ipynb +101 -37
  3. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/src/obi_notebook/get_entities.py +7 -2
  4. obi_notebook-0.4/src/obi_notebook/get_environment.py +25 -0
  5. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/src/obi_notebook/get_projects.py +6 -2
  6. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/src/obi_notebook.egg-info/PKG-INFO +1 -1
  7. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/src/obi_notebook.egg-info/SOURCES.txt +1 -0
  8. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/.github/workflows/sdist.yml +0 -0
  9. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/.github/workflows/tox.yml +0 -0
  10. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/.gitignore +0 -0
  11. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/CHANGELOG.rst +0 -0
  12. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/LICENSE.txt +0 -0
  13. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/README.md +0 -0
  14. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/demo.gif +0 -0
  15. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/pyproject.toml +0 -0
  16. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/setup.cfg +0 -0
  17. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/src/obi_notebook/__init__.py +0 -0
  18. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/src/obi_notebook.egg-info/dependency_links.txt +0 -0
  19. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/src/obi_notebook.egg-info/requires.txt +0 -0
  20. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/src/obi_notebook.egg-info/top_level.txt +0 -0
  21. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/tox.ini +0 -0
  22. {obi_notebook-0.2.dev2 → obi_notebook-0.4}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: obi_notebook
3
- Version: 0.2.dev2
3
+ Version: 0.4
4
4
  Summary: convenience functions for OBI notebooks
5
5
  Author-email: Open Brain Institute <jean-denis.courcol@epfl.ch>
6
6
  Maintainer-email: Open Brain Institute <jean-denis.courcol@epfl.ch>
@@ -3,15 +3,86 @@
3
3
  {
4
4
  "cell_type": "code",
5
5
  "execution_count": 1,
6
- "id": "7eb47475-67c6-499a-a2b4-19f8a64974d0",
6
+ "id": "d139baec",
7
7
  "metadata": {},
8
- "outputs": [],
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "production\n"
14
+ ]
15
+ },
16
+ {
17
+ "name": "stderr",
18
+ "output_type": "stream",
19
+ "text": [
20
+ "/Users/mwr/Documents/repositories/obi-notebook/.venv/lib/python3.13/site-packages/obi_notebook/get_environment.py:22: RuntimeWarning: No environment specified. Using production.\n",
21
+ " warnings.warn(f\"No environment specified. Using production.\",\n"
22
+ ]
23
+ }
24
+ ],
9
25
  "source": [
26
+ "import os\n",
27
+ "\n",
10
28
  "import obi_auth\n",
11
29
  "\n",
12
- "from obi_notebook import get_entities, get_projects\n",
30
+ "from obi_notebook import get_entities, get_environment, get_projects\n",
31
+ "from obi_notebook.get_environment import VAR_ENVIRONMENT\n",
32
+ "\n",
33
+ "# Should raise warning: Environment not selected.\n",
34
+ "environment_str = get_environment.get_environment()\n",
35
+ "print(environment_str)"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": 2,
41
+ "id": "304f4266",
42
+ "metadata": {},
43
+ "outputs": [
44
+ {
45
+ "name": "stdout",
46
+ "output_type": "stream",
47
+ "text": [
48
+ "production\n"
49
+ ]
50
+ },
51
+ {
52
+ "name": "stderr",
53
+ "output_type": "stream",
54
+ "text": [
55
+ "/Users/mwr/Documents/repositories/obi-notebook/.venv/lib/python3.13/site-packages/obi_notebook/get_environment.py:19: RuntimeWarning: Specified environment 'invalid' unknown. Using production.\n",
56
+ " warnings.warn(f\"Specified environment '{var}' unknown. Using production.\",\n"
57
+ ]
58
+ }
59
+ ],
60
+ "source": [
61
+ "os.environ[VAR_ENVIRONMENT] = \"invalid\"\n",
13
62
  "\n",
14
- "environment_str = \"staging\""
63
+ "# Should raise warning: Environment unknown.\n",
64
+ "environment_str = get_environment.get_environment()\n",
65
+ "print(environment_str)"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": 3,
71
+ "id": "7eb47475-67c6-499a-a2b4-19f8a64974d0",
72
+ "metadata": {},
73
+ "outputs": [
74
+ {
75
+ "name": "stdout",
76
+ "output_type": "stream",
77
+ "text": [
78
+ "staging\n"
79
+ ]
80
+ }
81
+ ],
82
+ "source": [
83
+ "os.environ[VAR_ENVIRONMENT] = \"staging\"\n",
84
+ "environment_str = get_environment.get_environment()\n",
85
+ "print(environment_str)"
15
86
  ]
16
87
  },
17
88
  {
@@ -19,12 +90,12 @@
19
90
  "id": "4d984b92-cadd-4b07-9813-b2333272610f",
20
91
  "metadata": {},
21
92
  "source": [
22
- "get authentication token for production"
93
+ "get authentication token"
23
94
  ]
24
95
  },
25
96
  {
26
97
  "cell_type": "code",
27
- "execution_count": 2,
98
+ "execution_count": 4,
28
99
  "id": "323cb45c-91e3-451f-8a80-374e61433d31",
29
100
  "metadata": {},
30
101
  "outputs": [],
@@ -42,14 +113,14 @@
42
113
  },
43
114
  {
44
115
  "cell_type": "code",
45
- "execution_count": 3,
116
+ "execution_count": 5,
46
117
  "id": "77c47560-1163-4466-83fc-43abc6e0801a",
47
118
  "metadata": {},
48
119
  "outputs": [
49
120
  {
50
121
  "data": {
51
122
  "application/vnd.jupyter.widget-view+json": {
52
- "model_id": "639a72897c7045f78bb7aea5afbec767",
123
+ "model_id": "45fd425a2ed84685b37a3f567f960a23",
53
124
  "version_major": 2,
54
125
  "version_minor": 0
55
126
  },
@@ -62,12 +133,12 @@
62
133
  }
63
134
  ],
64
135
  "source": [
65
- "project_context = get_projects.get_projects(token, env=\"staging\")"
136
+ "project_context = get_projects.get_projects(token)"
66
137
  ]
67
138
  },
68
139
  {
69
140
  "cell_type": "code",
70
- "execution_count": 4,
141
+ "execution_count": 6,
71
142
  "id": "d538dcac-1bdc-496b-8840-a7b32ea842ed",
72
143
  "metadata": {},
73
144
  "outputs": [
@@ -77,7 +148,7 @@
77
148
  "ProjectContext(project_id=UUID('32008ab5-76cf-47cd-b98b-a5013b30b533'), virtual_lab_id=UUID('1d8cccc0-f992-46aa-aac6-88e63c914314'), environment=<DeploymentEnvironment.staging: 'staging'>)"
78
149
  ]
79
150
  },
80
- "execution_count": 4,
151
+ "execution_count": 6,
81
152
  "metadata": {},
82
153
  "output_type": "execute_result"
83
154
  }
@@ -88,14 +159,14 @@
88
159
  },
89
160
  {
90
161
  "cell_type": "code",
91
- "execution_count": 5,
162
+ "execution_count": 7,
92
163
  "id": "93029f77-d71f-40f4-8c4d-9f23d2b650bc",
93
164
  "metadata": {},
94
165
  "outputs": [
95
166
  {
96
167
  "data": {
97
168
  "application/vnd.jupyter.widget-view+json": {
98
- "model_id": "e4b6463129a546d394d57efc46d07d7c",
169
+ "model_id": "b92bedf59a6a49c4b0c6d9dcf5da4268",
99
170
  "version_major": 2,
100
171
  "version_minor": 0
101
172
  },
@@ -109,7 +180,7 @@
109
180
  {
110
181
  "data": {
111
182
  "application/vnd.jupyter.widget-view+json": {
112
- "model_id": "9201fb70a891499cadada69780277194",
183
+ "model_id": "36957a0de8ea476f9fc97dbd665740d3",
113
184
  "version_major": 2,
114
185
  "version_minor": 0
115
186
  },
@@ -135,25 +206,22 @@
135
206
  " default_scale=\"small\",\n",
136
207
  " exclude_scales=[\"single\"],\n",
137
208
  " add_columns=[\"subject.name\"],\n",
138
- " env=environment_str,\n",
139
209
  ")"
140
210
  ]
141
211
  },
142
212
  {
143
213
  "cell_type": "code",
144
- "execution_count": 9,
214
+ "execution_count": 8,
145
215
  "id": "da699ed4-39fd-4602-b54d-58a0b58c2539",
146
216
  "metadata": {},
147
217
  "outputs": [
148
218
  {
149
219
  "data": {
150
220
  "text/plain": [
151
- "['b86271b6-c56f-4c26-b502-05ef5bb514b6',\n",
152
- " '3877500c-126d-410c-aa09-e44831464e80',\n",
153
- " 'd66cea8b-5c9d-4bfb-bbfd-ca3d5fb5f12c']"
221
+ "['c940188a-5408-4185-ab3b-dbb20de16621']"
154
222
  ]
155
223
  },
156
- "execution_count": 9,
224
+ "execution_count": 8,
157
225
  "metadata": {},
158
226
  "output_type": "execute_result"
159
227
  }
@@ -164,14 +232,14 @@
164
232
  },
165
233
  {
166
234
  "cell_type": "code",
167
- "execution_count": 6,
235
+ "execution_count": 9,
168
236
  "id": "a5f5445d-a61a-4fbe-962f-51e701434771",
169
237
  "metadata": {},
170
238
  "outputs": [
171
239
  {
172
240
  "data": {
173
241
  "application/vnd.jupyter.widget-view+json": {
174
- "model_id": "5fb0a08d2ce94d58a039c47fdd2f217f",
242
+ "model_id": "04360c5e3d5a4d318fa446f3e06e9853",
175
243
  "version_major": 2,
176
244
  "version_minor": 0
177
245
  },
@@ -185,7 +253,7 @@
185
253
  {
186
254
  "data": {
187
255
  "application/vnd.jupyter.widget-view+json": {
188
- "model_id": "a0c7ca20d54946f2af3e181c3adb3d70",
256
+ "model_id": "9247a1fde0a7438d853325c8a0eaf428",
189
257
  "version_major": 2,
190
258
  "version_minor": 0
191
259
  },
@@ -209,25 +277,22 @@
209
277
  " project_context=project_context,\n",
210
278
  " page_size=100,\n",
211
279
  " add_columns=[\"mtypes\"],\n",
212
- " env=environment_str,\n",
213
280
  ")"
214
281
  ]
215
282
  },
216
283
  {
217
284
  "cell_type": "code",
218
- "execution_count": 7,
285
+ "execution_count": 10,
219
286
  "id": "2c9d28c4",
220
287
  "metadata": {},
221
288
  "outputs": [
222
289
  {
223
290
  "data": {
224
291
  "text/plain": [
225
- "['50248fe3-83bd-4c88-917b-63bcf0e01385',\n",
226
- " '1c8ce2b1-3da1-4953-9b1b-bee8656000c4',\n",
227
- " '15d02969-1e40-40ba-9081-d475d05897fd']"
292
+ "['afa2434f-1ccc-4fff-a047-d399e59768c9']"
228
293
  ]
229
294
  },
230
- "execution_count": 7,
295
+ "execution_count": 10,
231
296
  "metadata": {},
232
297
  "output_type": "execute_result"
233
298
  }
@@ -238,14 +303,14 @@
238
303
  },
239
304
  {
240
305
  "cell_type": "code",
241
- "execution_count": 10,
306
+ "execution_count": 11,
242
307
  "id": "90757b52",
243
308
  "metadata": {},
244
309
  "outputs": [
245
310
  {
246
311
  "data": {
247
312
  "application/vnd.jupyter.widget-view+json": {
248
- "model_id": "c2a91b53873b4e1fa54c161a59830f6b",
313
+ "model_id": "a3915f160d944f14b1a401e643b1f7e1",
249
314
  "version_major": 2,
250
315
  "version_minor": 0
251
316
  },
@@ -259,7 +324,7 @@
259
324
  {
260
325
  "data": {
261
326
  "application/vnd.jupyter.widget-view+json": {
262
- "model_id": "a08fd579c61b4377a0dd01478a5951be",
327
+ "model_id": "d1b44ab0d11146a1a11e3f32df4ceeba",
263
328
  "version_major": 2,
264
329
  "version_minor": 0
265
330
  },
@@ -273,7 +338,7 @@
273
338
  ],
274
339
  "source": [
275
340
  "cell_mesh_ids = []\n",
276
- "circuit_ids = get_entities.get_entities(\n",
341
+ "cell_mesh_ids = get_entities.get_entities(\n",
277
342
  " \"em-cell-mesh\",\n",
278
343
  " token,\n",
279
344
  " cell_mesh_ids,\n",
@@ -282,24 +347,23 @@
282
347
  " show_pages=True,\n",
283
348
  " project_context=project_context,\n",
284
349
  " page_size=10,\n",
285
- " env=environment_str,\n",
286
350
  " add_columns=[\"dense_reconstruction_cell_id\", \"subject.name\"],\n",
287
351
  ")"
288
352
  ]
289
353
  },
290
354
  {
291
355
  "cell_type": "code",
292
- "execution_count": 11,
356
+ "execution_count": 12,
293
357
  "id": "6964ebe2",
294
358
  "metadata": {},
295
359
  "outputs": [
296
360
  {
297
361
  "data": {
298
362
  "text/plain": [
299
- "['2205be1a-a6db-4523-9a7b-0af309996583']"
363
+ "['e915d259-d03a-4544-8109-a86bbd4cd722']"
300
364
  ]
301
365
  },
302
- "execution_count": 11,
366
+ "execution_count": 12,
303
367
  "metadata": {},
304
368
  "output_type": "execute_result"
305
369
  }
@@ -8,6 +8,8 @@ from entitysdk import Client, models, types
8
8
  from ipydatagrid import DataGrid, TextRenderer
9
9
  from IPython.display import clear_output, display
10
10
 
11
+ from obi_notebook.get_environment import get_environment
12
+
11
13
  LST_MTYPES_ = None
12
14
  LST_SPECIES_ = None
13
15
  LST_EMDATASETS_ = None
@@ -86,7 +88,7 @@ def get_entities(
86
88
  entity_type,
87
89
  token,
88
90
  result,
89
- env="production",
91
+ env=None,
90
92
  project_context=None,
91
93
  return_entities=False,
92
94
  multi_select=True,
@@ -101,6 +103,8 @@ def get_entities(
101
103
  Note: The 'result' parameter is a mutable object (a list) that is modified in-place
102
104
  and also returned.
103
105
  """
106
+ if env is None:
107
+ env = get_environment()
104
108
  if page_size is not None:
105
109
  if page_size <= 0:
106
110
  raise ValueError("ERROR: Page size must be larger than 0!")
@@ -111,7 +115,7 @@ def get_entities(
111
115
  if exclude_scales is None:
112
116
  exclude_scales = []
113
117
 
114
- subdomain = "www" if env == "production" else "staging"
118
+ subdomain = "cell-a" if env == "production" else "staging.cell-a"
115
119
  entity_core_url = f"https://{subdomain}.openbraininstitute.org/api/entitycore"
116
120
 
117
121
  # Widgets
@@ -295,6 +299,7 @@ def get_entities(
295
299
  result.extend(l_ids)
296
300
 
297
301
  grid.observe(on_selection_change, names="selections")
302
+ grid.selections = [{"r1": 0, "r2": 0, "c1": 0, "c2": len(column_widths)}]
298
303
 
299
304
  for filter_ in filters_dict.values():
300
305
  filter_.observe(on_change, names="value")
@@ -0,0 +1,25 @@
1
+ """Code for handling the deployment environment."""
2
+
3
+ import warnings
4
+ from os import getenv
5
+
6
+ from obi_auth.typedef import DeploymentEnvironment
7
+
8
+ VAR_ENVIRONMENT = "OBI_ENVIRONMENT"
9
+
10
+
11
+ def get_environment():
12
+ """Try to get the environment to run in from environment variable."""
13
+ var = getenv(VAR_ENVIRONMENT)
14
+ if var is not None:
15
+ if var in DeploymentEnvironment._member_map_:
16
+ return DeploymentEnvironment(var)
17
+ else:
18
+ warnings.warn(
19
+ f"Specified environment '{var}' unknown. Using production.",
20
+ RuntimeWarning,
21
+ stacklevel=2,
22
+ )
23
+ else:
24
+ warnings.warn("No environment specified. Using production.", RuntimeWarning, stacklevel=2)
25
+ return DeploymentEnvironment.production
@@ -5,17 +5,21 @@ import requests
5
5
  from entitysdk import ProjectContext
6
6
  from IPython.display import display
7
7
 
8
+ from obi_notebook.get_environment import get_environment
9
+
8
10
  selected_project = None # Global variable
9
11
 
10
12
 
11
- def get_projects(token, env="production"):
13
+ def get_projects(token, env=None):
12
14
  """Returns available project for the end user."""
15
+ if env is None:
16
+ env = get_environment()
13
17
 
14
18
  def project_handler(selected, project_context):
15
19
  project_context.project_id = selected["id"]
16
20
  project_context.virtual_lab_id = selected["virtual_lab_id"]
17
21
 
18
- subdomain = "www" if env == "production" else "staging"
22
+ subdomain = "cell-a" if env == "production" else "staging.cell-a"
19
23
 
20
24
  url = (
21
25
  f"https://{subdomain}.openbraininstitute.org/api/virtual-lab-manager/virtual-labs/projects"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: obi_notebook
3
- Version: 0.2.dev2
3
+ Version: 0.4
4
4
  Summary: convenience functions for OBI notebooks
5
5
  Author-email: Open Brain Institute <jean-denis.courcol@epfl.ch>
6
6
  Maintainer-email: Open Brain Institute <jean-denis.courcol@epfl.ch>
@@ -11,6 +11,7 @@ uv.lock
11
11
  .github/workflows/tox.yml
12
12
  src/obi_notebook/__init__.py
13
13
  src/obi_notebook/get_entities.py
14
+ src/obi_notebook/get_environment.py
14
15
  src/obi_notebook/get_projects.py
15
16
  src/obi_notebook.egg-info/PKG-INFO
16
17
  src/obi_notebook.egg-info/SOURCES.txt
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes