fractal-server 2.9.0a7__py3-none-any.whl → 2.9.0a9__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.
@@ -1 +1 @@
1
- __VERSION__ = "2.9.0a7"
1
+ __VERSION__ = "2.9.0a9"
@@ -108,8 +108,6 @@ async def deactivate_task_group(
108
108
  version=task_group.version,
109
109
  timestamp_started=get_timestamp(),
110
110
  )
111
- task_group.active = False
112
- db.add(task_group)
113
111
  db.add(task_group_activity)
114
112
  await db.commit()
115
113
 
@@ -1,6 +1,8 @@
1
1
  """
2
2
  Definition of `/auth/current-user/` endpoints
3
3
  """
4
+ import os
5
+
4
6
  from fastapi import APIRouter
5
7
  from fastapi import Depends
6
8
  from fastapi_users import schemas
@@ -22,6 +24,8 @@ from fractal_server.app.schemas import UserSettingsReadStrict
22
24
  from fractal_server.app.schemas import UserSettingsUpdateStrict
23
25
  from fractal_server.app.security import get_user_manager
24
26
  from fractal_server.app.security import UserManager
27
+ from fractal_server.config import get_settings
28
+ from fractal_server.syringe import Inject
25
29
 
26
30
  router_current_user = APIRouter()
27
31
 
@@ -109,26 +113,65 @@ async def patch_current_user_settings(
109
113
 
110
114
 
111
115
  @router_current_user.get(
112
- "/current-user/viewer-paths/", response_model=list[str]
116
+ "/current-user/allowed-viewer-paths/", response_model=list[str]
113
117
  )
114
- async def get_current_user_viewer_paths(
118
+ async def get_current_user_allowed_viewer_paths(
115
119
  current_user: UserOAuth = Depends(current_active_user),
116
120
  db: AsyncSession = Depends(get_async_db),
117
121
  ) -> list[str]:
118
- """Returns the union of `viewer_paths` for all user's groups"""
119
- cmd = (
120
- select(UserGroup.viewer_paths)
121
- .join(LinkUserGroup)
122
- .where(LinkUserGroup.group_id == UserGroup.id)
123
- .where(LinkUserGroup.user_id == current_user.id)
124
- )
125
- res = await db.execute(cmd)
126
- viewer_paths_nested = res.scalars().all()
122
+ """
123
+ Returns the allowed viewer paths for current user, according to the
124
+ selected FRACTAL_VIEWER_AUTHORIZATION_SCHEME
125
+ """
127
126
 
128
- # Flatten a nested object and make its elements unique
129
- all_viewer_paths_set = set(
130
- path for _viewer_paths in viewer_paths_nested for path in _viewer_paths
131
- )
132
- all_viewer_paths = list(all_viewer_paths_set)
127
+ settings = Inject(get_settings)
128
+
129
+ if settings.FRACTAL_VIEWER_AUTHORIZATION_SCHEME == "none":
130
+ return []
133
131
 
134
- return all_viewer_paths
132
+ authorized_paths = []
133
+
134
+ # Respond with 422 error if user has no settings
135
+ verify_user_has_settings(current_user)
136
+
137
+ # Load current user settings
138
+ current_user_settings = await db.get(
139
+ UserSettings, current_user.user_settings_id
140
+ )
141
+ # If project_dir is set, append it to the list of authorized paths
142
+ if current_user_settings.project_dir is not None:
143
+ authorized_paths.append(current_user_settings.project_dir)
144
+
145
+ # If auth scheme is "users-folders" and `slurm_user` is set,
146
+ # build and append the user folder
147
+ if (
148
+ settings.FRACTAL_VIEWER_AUTHORIZATION_SCHEME == "users-folders"
149
+ and current_user_settings.slurm_user is not None
150
+ ):
151
+ base_folder = settings.FRACTAL_VIEWER_BASE_FOLDER
152
+ user_folder = os.path.join(
153
+ base_folder, current_user_settings.slurm_user
154
+ )
155
+ authorized_paths.append(user_folder)
156
+
157
+ if settings.FRACTAL_VIEWER_AUTHORIZATION_SCHEME == "viewer-paths":
158
+ # Returns the union of `viewer_paths` for all user's groups
159
+ cmd = (
160
+ select(UserGroup.viewer_paths)
161
+ .join(LinkUserGroup)
162
+ .where(LinkUserGroup.group_id == UserGroup.id)
163
+ .where(LinkUserGroup.user_id == current_user.id)
164
+ )
165
+ res = await db.execute(cmd)
166
+ viewer_paths_nested = res.scalars().all()
167
+
168
+ # Flatten a nested object and make its elements unique
169
+ all_viewer_paths_set = set(
170
+ path
171
+ for _viewer_paths in viewer_paths_nested
172
+ for path in _viewer_paths
173
+ )
174
+
175
+ authorized_paths.extend(all_viewer_paths_set)
176
+
177
+ return authorized_paths
@@ -2,6 +2,7 @@
2
2
  Custom version of Python
3
3
  [ProcessPoolExecutor](https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor)).
4
4
  """
5
+ import multiprocessing as mp
5
6
  import threading
6
7
  import time
7
8
  from concurrent.futures import ProcessPoolExecutor
@@ -32,7 +33,7 @@ class FractalProcessPoolExecutor(ProcessPoolExecutor):
32
33
  def __init__(
33
34
  self, shutdown_file: Path, interval: float = 1.0, *args, **kwargs
34
35
  ):
35
- super().__init__(*args, **kwargs)
36
+ super().__init__(*args, **kwargs, mp_context=mp.get_context("spawn"))
36
37
  self.shutdown_file = Path(shutdown_file)
37
38
  self.interval = float(interval)
38
39
  logger.debug(
fractal_server/config.py CHANGED
@@ -87,7 +87,7 @@ class Settings(BaseSettings):
87
87
  """
88
88
  Contains all the configuration variables for Fractal Server
89
89
 
90
- The attributes of this class are set from the environtment.
90
+ The attributes of this class are set from the environment.
91
91
  """
92
92
 
93
93
  class Config:
@@ -383,7 +383,7 @@ class Settings(BaseSettings):
383
383
  @root_validator(pre=True)
384
384
  def check_tasks_python(cls, values) -> None:
385
385
  """
386
- Perform multiple checks of the Python-intepreter variables.
386
+ Perform multiple checks of the Python-interpreter variables.
387
387
 
388
388
  1. Each `FRACTAL_TASKS_PYTHON_X_Y` variable must be an absolute path,
389
389
  if set.
@@ -432,7 +432,7 @@ class Settings(BaseSettings):
432
432
  f"{current_version_dot}"
433
433
  )
434
434
 
435
- # Unset all existing intepreters variable
435
+ # Unset all existing interpreters variable
436
436
  for _version in ["3_9", "3_10", "3_11", "3_12"]:
437
437
  key = f"FRACTAL_TASKS_PYTHON_{_version}"
438
438
  if _version == current_version:
@@ -498,6 +498,36 @@ class Settings(BaseSettings):
498
498
  Maximum value at which to update `pip` before performing task collection.
499
499
  """
500
500
 
501
+ FRACTAL_VIEWER_AUTHORIZATION_SCHEME: Literal[
502
+ "viewer-paths", "users-folders", "none"
503
+ ] = "none"
504
+ """
505
+ Defines how the list of allowed viewer paths is built.
506
+
507
+ This variable affects the `GET /auth/current-user/allowed-viewer-paths/`
508
+ response, which is then consumed by
509
+ [fractal-vizarr-viewer](https://github.com/fractal-analytics-platform/fractal-vizarr-viewer).
510
+
511
+ Options:
512
+
513
+ - "viewer-paths": The list of allowed viewer paths will include the user's
514
+ `project_dir` along with any path defined in user groups' `viewer_paths`
515
+ attributes.
516
+ - "users-folders": The list will consist of the user's `project_dir` and a
517
+ user-specific folder. The user folder is constructed by concatenating
518
+ the base folder `FRACTAL_VIEWER_BASE_FOLDER` with the user's
519
+ `slurm_user`.
520
+ - "none": An empty list will be returned, indicating no access to
521
+ viewer paths. Useful when vizarr viewer is not used.
522
+ """
523
+
524
+ FRACTAL_VIEWER_BASE_FOLDER: Optional[str] = None
525
+ """
526
+ Base path to Zarr files that will be served by fractal-vizarr-viewer;
527
+ This variable is required and used only when
528
+ FRACTAL_VIEWER_AUTHORIZATION_SCHEME is set to "users-folders".
529
+ """
530
+
501
531
  ###########################################################################
502
532
  # BUSINESS LOGIC
503
533
  ###########################################################################
@@ -589,6 +619,23 @@ class Settings(BaseSettings):
589
619
  if not self.FRACTAL_TASKS_DIR:
590
620
  raise FractalConfigurationError("FRACTAL_TASKS_DIR cannot be None")
591
621
 
622
+ # FRACTAL_VIEWER_BASE_FOLDER is required when
623
+ # FRACTAL_VIEWER_AUTHORIZATION_SCHEME is set to "users-folders"
624
+ # and it must be an absolute path
625
+ if self.FRACTAL_VIEWER_AUTHORIZATION_SCHEME == "users-folders":
626
+ viewer_base_folder = self.FRACTAL_VIEWER_BASE_FOLDER
627
+ if viewer_base_folder is None:
628
+ raise FractalConfigurationError(
629
+ "FRACTAL_VIEWER_BASE_FOLDER is required when "
630
+ "FRACTAL_VIEWER_AUTHORIZATION_SCHEME is set to "
631
+ "users-folders"
632
+ )
633
+ if not Path(viewer_base_folder).is_absolute():
634
+ raise FractalConfigurationError(
635
+ f"Non-absolute value for "
636
+ f"FRACTAL_VIEWER_BASE_FOLDER={viewer_base_folder}"
637
+ )
638
+
592
639
  self.check_db()
593
640
  self.check_runner()
594
641
 
@@ -191,6 +191,13 @@ def deactivate_local(
191
191
 
192
192
  # We now have all required information for reactivating the
193
193
  # virtual environment at a later point
194
+
195
+ # Actually mark the task group as non-active
196
+ logger.info("Now setting `active=False`.")
197
+ task_group.active = False
198
+ task_group = add_commit_refresh(obj=task_group, db=db)
199
+
200
+ # Proceed with deactivation
194
201
  logger.info(f"Now removing {task_group.venv_path}.")
195
202
  shutil.rmtree(task_group.venv_path)
196
203
  logger.info(f"All good, {task_group.venv_path} removed.")
@@ -223,6 +223,13 @@ def deactivate_ssh(
223
223
 
224
224
  # We now have all required information for reactivating the
225
225
  # virtual environment at a later point
226
+
227
+ # Actually mark the task group as non-active
228
+ logger.info("Now setting `active=False`.")
229
+ task_group.active = False
230
+ task_group = add_commit_refresh(obj=task_group, db=db)
231
+
232
+ # Proceed with deactivation
226
233
  logger.info(f"Now removing {task_group.venv_path}.")
227
234
  fractal_ssh.remove_folder(
228
235
  folder=task_group.venv_path,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fractal-server
3
- Version: 2.9.0a7
3
+ Version: 2.9.0a9
4
4
  Summary: Server component of the Fractal analytics platform
5
5
  Home-page: https://github.com/fractal-analytics-platform/fractal-server
6
6
  License: BSD-3-Clause
@@ -1,4 +1,4 @@
1
- fractal_server/__init__.py,sha256=esHziqdyHPk7LvpkTjB8XnaVY58q7di9rAVAsBys0N0,24
1
+ fractal_server/__init__.py,sha256=AgkJcJmAplHlQOvkvgp6iM_-dHeN1ajiKqWDu3YtZwc,24
2
2
  fractal_server/__main__.py,sha256=dEkCfzLLQrIlxsGC-HBfoR-RBMWnJDgNrxYTyzmE9c0,6146
3
3
  fractal_server/alembic.ini,sha256=MWwi7GzjzawI9cCAK1LW7NxIBQDUqD12-ptJoq5JpP0,3153
4
4
  fractal_server/app/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -31,7 +31,7 @@ fractal_server/app/routes/admin/v2/job.py,sha256=cbkFIRIIXaWmNsUFI7RAu8HpQ0mWn_b
31
31
  fractal_server/app/routes/admin/v2/project.py,sha256=luy-yiGX1JYTdPm1hpIdDUUqPm8xHuipLy9k2X6zu74,1223
32
32
  fractal_server/app/routes/admin/v2/task.py,sha256=Y0eujBgGhVapNXfW9azDxw4EBzLmEmCdh70y1RNQcb0,3895
33
33
  fractal_server/app/routes/admin/v2/task_group.py,sha256=DncrOAB4q-v3BAmxg35m4EohleriW_FLGE5gpW_Or08,8120
34
- fractal_server/app/routes/admin/v2/task_group_lifecycle.py,sha256=bGD5cbZI7t6t-KQuY9YQ5iIksBT68Qbz2kMkVqrGaqc,9482
34
+ fractal_server/app/routes/admin/v2/task_group_lifecycle.py,sha256=0e0ZJ_k75TVHaT2o8Xk33DPDSgh-eBhZf-y4y7t-Adg,9429
35
35
  fractal_server/app/routes/api/__init__.py,sha256=2IDheFi0OFdsUg7nbUiyahqybvpgXqeHUXIL2QtWrQQ,641
36
36
  fractal_server/app/routes/api/v1/__init__.py,sha256=Y2HQdG197J0a7DyQEE2jn53IfxD0EHGhzK1I2JZuEck,958
37
37
  fractal_server/app/routes/api/v1/_aux_functions.py,sha256=P9Q48thGH95w0h5cacYoibxqgiiLW4oqZ8rNJ2LIISY,13219
@@ -62,7 +62,7 @@ fractal_server/app/routes/api/v2/workflow_import.py,sha256=WJST1AZypvOTGUrjhomYV
62
62
  fractal_server/app/routes/api/v2/workflowtask.py,sha256=ciHTwXXFiFnMF7ZpJ3Xs0q6YfuZrFvIjqndlzAEdZpo,6969
63
63
  fractal_server/app/routes/auth/__init__.py,sha256=fao6CS0WiAjHDTvBzgBVV_bSXFpEAeDBF6Z6q7rRkPc,1658
64
64
  fractal_server/app/routes/auth/_aux_auth.py,sha256=ifkNocTYatBSMYGwiR14qohmvR9SfMldceiEj6uJBrU,4783
65
- fractal_server/app/routes/auth/current_user.py,sha256=v767HGi8k076ZHoErlU4Vv0_c8HQqYmi8ncjzZZDaDE,4455
65
+ fractal_server/app/routes/auth/current_user.py,sha256=I3aVY5etWAJ_SH6t65Mj5TjvB2X8sAGuu1KG7FxLyPU,5883
66
66
  fractal_server/app/routes/auth/group.py,sha256=dSS7r8J2cejZ6sKnOWAPSDKynxD9VyBNtqDbFpySzIU,7489
67
67
  fractal_server/app/routes/auth/login.py,sha256=tSu6OBLOieoBtMZB4JkBAdEgH2Y8KqPGSbwy7NIypIo,566
68
68
  fractal_server/app/routes/auth/oauth.py,sha256=AnFHbjqL2AgBX3eksI931xD6RTtmbciHBEuGf9YJLjU,1895
@@ -118,7 +118,7 @@ fractal_server/app/runner/v2/_local/executor.py,sha256=QrJlD77G6q4WohoJQO7XXbvi2
118
118
  fractal_server/app/runner/v2/_local_experimental/__init__.py,sha256=53yS8a-l0dMTT_4oz7WVFbKJ3NRsycyutYkOuBTm6Ik,5694
119
119
  fractal_server/app/runner/v2/_local_experimental/_local_config.py,sha256=QiS5ODe-iGmUQdIT8QgpbyMc7-ZpIRv1V_f2q3qfPQ8,3211
120
120
  fractal_server/app/runner/v2/_local_experimental/_submit_setup.py,sha256=we7r-sQf0CJ9gxbfbgHcYdC6pKjx8eXweljIjthxkv8,1212
121
- fractal_server/app/runner/v2/_local_experimental/executor.py,sha256=vcBKjireIIyF5WgIQLatD6ojlWEydbTwyIG0bcpIjys,5438
121
+ fractal_server/app/runner/v2/_local_experimental/executor.py,sha256=plvEqqdcXOSohYsQoykYlyDwCING7OO5h-4XAZtwdPs,5503
122
122
  fractal_server/app/runner/v2/_slurm_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
123
123
  fractal_server/app/runner/v2/_slurm_common/get_slurm_config.py,sha256=UdkoFF0HF_TdKbay-d9bjkxT2ltcOE5i8H_FoOu64HU,6202
124
124
  fractal_server/app/runner/v2/_slurm_ssh/__init__.py,sha256=D0Dnbhnzw0BXwQmjqLmxqpE9oreAtasA-9aOzxC4l_I,4530
@@ -162,7 +162,7 @@ fractal_server/app/schemas/v2/workflow.py,sha256=-KWvXnbHBFA3pj5n7mfSyLKJQSqkJmo
162
162
  fractal_server/app/schemas/v2/workflowtask.py,sha256=vDdMktYbHeYBgB5OuWSv6wRPRXWqvetkeqQ7IC5YtfA,5751
163
163
  fractal_server/app/security/__init__.py,sha256=8Xd4GxumZgvxEH1Vli3ULehwdesEPiaAbtffJvAEgNo,12509
164
164
  fractal_server/app/user_settings.py,sha256=aZgQ3i0JkHfgwLGW1ee6Gzr1ae3IioFfJKKSsSS8Svk,1312
165
- fractal_server/config.py,sha256=1MmVIbnztrFA0w2gYIjgJXg0bqVDsSeSEsMFimb4y74,21153
165
+ fractal_server/config.py,sha256=Bk6EFKnU07sjgThf2NVEqrFAx9F4s0BfCvDKtWHzJTc,23217
166
166
  fractal_server/data_migrations/README.md,sha256=_3AEFvDg9YkybDqCLlFPdDmGJvr6Tw7HRI14aZ3LOIw,398
167
167
  fractal_server/data_migrations/tools.py,sha256=LeMeASwYGtEqd-3wOLle6WARdTGAimoyMmRbbJl-hAM,572
168
168
  fractal_server/gunicorn_fractal.py,sha256=u6U01TLGlXgq1v8QmEpLih3QnsInZD7CqphgJ_GrGzc,1230
@@ -217,12 +217,12 @@ fractal_server/tasks/v2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
217
217
  fractal_server/tasks/v2/local/__init__.py,sha256=9RVItnS7OyLsJOuJjWMCicaky4ASUPQEYD4SzDs0hOE,141
218
218
  fractal_server/tasks/v2/local/_utils.py,sha256=EvhmVwYjqaNyDCUMEsTWYOUXLgEwR1xr6bu32apCEI8,2491
219
219
  fractal_server/tasks/v2/local/collect.py,sha256=BbXSgxExPUxFxcmBs3ejwWzRae-sQgfbk3zZkAQg77Y,12190
220
- fractal_server/tasks/v2/local/deactivate.py,sha256=v00y9F7howS4csIAArUAbdiNzLEiMuXV2yL8OyGfEkA,8971
220
+ fractal_server/tasks/v2/local/deactivate.py,sha256=XR1nvJY3mKCRqwPwV79rVaQmtb3J83KdmJKjTOHD-cU,9250
221
221
  fractal_server/tasks/v2/local/reactivate.py,sha256=R3rArAzUpMGf6xa3dGVwwXHW9WVDi5ia28AFisZsqNc,6112
222
222
  fractal_server/tasks/v2/ssh/__init__.py,sha256=aSQbVi6Ummt9QzcSLWNmSqYjfdxrn9ROmqgH6bDpI7k,135
223
223
  fractal_server/tasks/v2/ssh/_utils.py,sha256=2E-F_862zM6FZA-im-E8t8kjptWRIhBj1IDHC6QD1H8,2818
224
224
  fractal_server/tasks/v2/ssh/collect.py,sha256=ZOpz-v2t2kOAbbpdlsH_P_XjNtEh2TaC1dIZ1bBHwxw,12941
225
- fractal_server/tasks/v2/ssh/deactivate.py,sha256=PvSz4Rj2pM0Z-m0uytvsaB3nNmhIjopr1bMpxGgBPvs,10337
225
+ fractal_server/tasks/v2/ssh/deactivate.py,sha256=Ffk_UuQSBUBNBCiviuKNhEUGyZPQa4_erJKFdwgMcE8,10616
226
226
  fractal_server/tasks/v2/ssh/reactivate.py,sha256=jdO8iyzavzSVPcOpIZrYSEkGPYTvz5XJ5h_5-nz9yzA,7896
227
227
  fractal_server/tasks/v2/templates/1_create_venv.sh,sha256=PK0jdHKtQpda1zULebBaVPORt4t6V17wa4N1ohcj5ac,548
228
228
  fractal_server/tasks/v2/templates/2_pip_install.sh,sha256=RDDfbFnGOK3aRuHyXqDOUNCGullzAr0zS7BFqG1CJeE,1720
@@ -238,8 +238,8 @@ fractal_server/tasks/v2/utils_templates.py,sha256=C5WLuY3uGG2s53OEL-__H35-fmSlgu
238
238
  fractal_server/urls.py,sha256=5o_qq7PzKKbwq12NHSQZDmDitn5RAOeQ4xufu-2v9Zk,448
239
239
  fractal_server/utils.py,sha256=utvmBx8K9I8hRWFquxna2pBaOqe0JifDL_NVPmihEJI,3525
240
240
  fractal_server/zip_tools.py,sha256=GjDgo_sf6V_DDg6wWeBlZu5zypIxycn_l257p_YVKGc,4876
241
- fractal_server-2.9.0a7.dist-info/LICENSE,sha256=QKAharUuhxL58kSoLizKJeZE3mTCBnX6ucmz8W0lxlk,1576
242
- fractal_server-2.9.0a7.dist-info/METADATA,sha256=SauipHw3VqYO_4pD1Lv2JiLkpYBI7AmSgzQFsDim8-Q,4585
243
- fractal_server-2.9.0a7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
244
- fractal_server-2.9.0a7.dist-info/entry_points.txt,sha256=8tV2kynvFkjnhbtDnxAqImL6HMVKsopgGfew0DOp5UY,58
245
- fractal_server-2.9.0a7.dist-info/RECORD,,
241
+ fractal_server-2.9.0a9.dist-info/LICENSE,sha256=QKAharUuhxL58kSoLizKJeZE3mTCBnX6ucmz8W0lxlk,1576
242
+ fractal_server-2.9.0a9.dist-info/METADATA,sha256=kVjqPsTd7RPiIlTSbj8CzDM6dZEKzvo23ofH6ylpl2E,4585
243
+ fractal_server-2.9.0a9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
244
+ fractal_server-2.9.0a9.dist-info/entry_points.txt,sha256=8tV2kynvFkjnhbtDnxAqImL6HMVKsopgGfew0DOp5UY,58
245
+ fractal_server-2.9.0a9.dist-info/RECORD,,