plexora 0.0.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.
Files changed (248) hide show
  1. plexora/__init__.py +129 -0
  2. plexora/__main__.py +15 -0
  3. plexora/_url.py +105 -0
  4. plexora/api/__init__.py +55 -0
  5. plexora/api/dataset.py +398 -0
  6. plexora/api/http.py +19 -0
  7. plexora/api/plugin.py +541 -0
  8. plexora/api/store.py +221 -0
  9. plexora/cli.py +777 -0
  10. plexora/client/dist/354_bundle.js +2 -0
  11. plexora/client/dist/354_bundle.js.LICENSE.txt +20 -0
  12. plexora/client/dist/418_bundle.js +2 -0
  13. plexora/client/dist/418_bundle.js.LICENSE.txt +1 -0
  14. plexora/client/dist/693b935cb1f907814be9c6199a68c217.svg +19 -0
  15. plexora/client/dist/713c134ff47cd328a5b711526f151082.svg +18 -0
  16. plexora/client/dist/770_bundle.js +1 -0
  17. plexora/client/dist/ff743f408972e0e96ca9153ed5ae4c83.svg +23 -0
  18. plexora/client/dist/vendor_bundle.js +2 -0
  19. plexora/client/dist/vendor_bundle.js.LICENSE.txt +308 -0
  20. plexora/client/external/openseadragon-bin-2.4.0/LICENSE.txt +28 -0
  21. plexora/client/external/openseadragon-bin-2.4.0/canvas-overlay-hd.js +140 -0
  22. plexora/client/external/openseadragon-bin-2.4.0/changelog.txt +501 -0
  23. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/.gitattributes +17 -0
  24. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/LICENSE.txt +116 -0
  25. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/Toolbar.png +0 -0
  26. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/fullpage.psd +0 -0
  27. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/home.psd +0 -0
  28. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/next.psd +0 -0
  29. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/previous.psd +0 -0
  30. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/rotateleft.psd +0 -0
  31. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/rotateright.psd +0 -0
  32. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/zoom.psd +0 -0
  33. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/README.md +9 -0
  34. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/fullpage_grouphover.png +0 -0
  35. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/fullpage_hover.png +0 -0
  36. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/fullpage_pressed.png +0 -0
  37. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/fullpage_rest.png +0 -0
  38. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/home_grouphover.png +0 -0
  39. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/home_hover.png +0 -0
  40. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/home_pressed.png +0 -0
  41. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/home_rest.png +0 -0
  42. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/next_grouphover.png +0 -0
  43. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/next_hover.png +0 -0
  44. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/next_pressed.png +0 -0
  45. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/next_rest.png +0 -0
  46. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/previous_grouphover.png +0 -0
  47. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/previous_hover.png +0 -0
  48. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/previous_pressed.png +0 -0
  49. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/previous_rest.png +0 -0
  50. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateleft_grouphover.png +0 -0
  51. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateleft_hover.png +0 -0
  52. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateleft_pressed.png +0 -0
  53. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateleft_rest.png +0 -0
  54. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateright_grouphover.png +0 -0
  55. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateright_hover.png +0 -0
  56. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateright_pressed.png +0 -0
  57. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateright_rest.png +0 -0
  58. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomin_grouphover.png +0 -0
  59. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomin_hover.png +0 -0
  60. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomin_pressed.png +0 -0
  61. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomin_rest.png +0 -0
  62. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomout_grouphover.png +0 -0
  63. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomout_hover.png +0 -0
  64. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomout_pressed.png +0 -0
  65. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomout_rest.png +0 -0
  66. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-scalebar.js +562 -0
  67. plexora/client/src/css/import.css +474 -0
  68. plexora/client/src/css/main.css +903 -0
  69. plexora/client/src/css/openProject.css +363 -0
  70. plexora/client/src/css/quickView.css +166 -0
  71. plexora/client/src/css/tokens.css +51 -0
  72. plexora/client/src/css/viewer.css +1655 -0
  73. plexora/client/src/img/apple-touch-icon.png +0 -0
  74. plexora/client/src/img/favicon.ico +0 -0
  75. plexora/client/src/img/logo.ai +8892 -33
  76. plexora/client/src/img/logo.svg +1 -0
  77. plexora/client/src/img/logo_with_text.ai +9011 -34
  78. plexora/client/src/img/logo_with_text.svg +1 -0
  79. plexora/client/src/js/main.js +704 -0
  80. plexora/client/src/js/pluginRegistry.js +108 -0
  81. plexora/client/src/js/services/appStatus.js +286 -0
  82. plexora/client/src/js/services/browsePicker.js +73 -0
  83. plexora/client/src/js/services/dataLayer.js +400 -0
  84. plexora/client/src/js/services/datasetContext.js +143 -0
  85. plexora/client/src/js/services/glRenderer.js +143 -0
  86. plexora/client/src/js/services/importFormValidation.js +257 -0
  87. plexora/client/src/js/services/numericData.js +100 -0
  88. plexora/client/src/js/services/passVariablesToFrontend.js +20 -0
  89. plexora/client/src/js/services/simpleEventHandler.js +25 -0
  90. plexora/client/src/js/vendor.js +29 -0
  91. plexora/client/src/js/views/channelList.js +663 -0
  92. plexora/client/src/js/views/colorSwatchPicker.js +202 -0
  93. plexora/client/src/js/views/columnClassifier.js +146 -0
  94. plexora/client/src/js/views/coordinateField.js +133 -0
  95. plexora/client/src/js/views/dataSourceField.js +276 -0
  96. plexora/client/src/js/views/imageViewer.js +3306 -0
  97. plexora/client/src/js/views/miniMap.js +787 -0
  98. plexora/client/src/js/views/navbarControls.js +178 -0
  99. plexora/client/src/js/views/openProjectPage.js +239 -0
  100. plexora/client/src/js/views/projectEdit.js +335 -0
  101. plexora/client/src/js/views/quickViewLanding.js +136 -0
  102. plexora/client/src/js/views/rainbow.js +326 -0
  103. plexora/client/src/js/views/requirementsModal.js +572 -0
  104. plexora/client/src/js/views/rgbImageViewer.js +115 -0
  105. plexora/client/src/js/views/searchableSelect.js +411 -0
  106. plexora/client/src/js/views/segmentationProgress.js +122 -0
  107. plexora/client/src/js/views/toolLoader.js +747 -0
  108. plexora/client/src/js/views/viewerControls.js +689 -0
  109. plexora/client/src/js/views/viewerManager.js +434 -0
  110. plexora/client/src/js/views/viewerSidebar.js +1117 -0
  111. plexora/client/src/js/workers/tileDecoder.js +130 -0
  112. plexora/client/src/shaders/frag.glsl +528 -0
  113. plexora/client/src/shaders/vert.glsl +12 -0
  114. plexora/client/templates/base.html +212 -0
  115. plexora/client/templates/index.html +238 -0
  116. plexora/client/templates/open_project.html +96 -0
  117. plexora/client/templates/project_columns.html +86 -0
  118. plexora/client/templates/project_edit.html +196 -0
  119. plexora/client/templates/upload.html +118 -0
  120. plexora/connect.py +528 -0
  121. plexora/datasource.py +782 -0
  122. plexora/jupyter.py +406 -0
  123. plexora/notebook_env.py +232 -0
  124. plexora/paths.py +486 -0
  125. plexora/plugins/__init__.py +12 -0
  126. plexora/plugins/cell_explorer/__init__.py +100 -0
  127. plexora/plugins/cell_explorer/server/__init__.py +11 -0
  128. plexora/plugins/cell_explorer/server/routes.py +167 -0
  129. plexora/plugins/cell_explorer/server/state.py +281 -0
  130. plexora/plugins/cell_explorer/server/values.py +145 -0
  131. plexora/plugins/cell_explorer/server/variables.py +367 -0
  132. plexora/plugins/cell_explorer/static/cellExplorerApi.js +158 -0
  133. plexora/plugins/cell_explorer/static/cellExplorerColors.js +316 -0
  134. plexora/plugins/cell_explorer/static/cellExplorerContinuous.js +403 -0
  135. plexora/plugins/cell_explorer/static/cellExplorerFigureBridge.js +133 -0
  136. plexora/plugins/cell_explorer/static/cellExplorerLegend.js +188 -0
  137. plexora/plugins/cell_explorer/static/cellExplorerRoiBridge.js +822 -0
  138. plexora/plugins/cell_explorer/static/cellExplorerSidebarController.js +826 -0
  139. plexora/plugins/cell_explorer/static/cellExplorerState.js +372 -0
  140. plexora/plugins/cell_explorer/static/cell_explorer.css +752 -0
  141. plexora/plugins/cell_explorer/templates/cell_explorer/panel.html +137 -0
  142. plexora/plugins/figure_builder/__init__.py +125 -0
  143. plexora/plugins/figure_builder/server/__init__.py +7 -0
  144. plexora/plugins/figure_builder/server/compose.py +365 -0
  145. plexora/plugins/figure_builder/server/export.py +784 -0
  146. plexora/plugins/figure_builder/server/export_jobs.py +148 -0
  147. plexora/plugins/figure_builder/server/operations.py +556 -0
  148. plexora/plugins/figure_builder/server/pixels.py +142 -0
  149. plexora/plugins/figure_builder/server/provenance.py +174 -0
  150. plexora/plugins/figure_builder/server/render.py +278 -0
  151. plexora/plugins/figure_builder/server/repository.py +701 -0
  152. plexora/plugins/figure_builder/server/routes.py +594 -0
  153. plexora/plugins/figure_builder/server/schema.py +1023 -0
  154. plexora/plugins/figure_builder/server/sources.py +120 -0
  155. plexora/plugins/figure_builder/server/textmetrics.py +155 -0
  156. plexora/plugins/figure_builder/static/figureActions.js +363 -0
  157. plexora/plugins/figure_builder/static/figureBuilderApi.js +255 -0
  158. plexora/plugins/figure_builder/static/figureCanvas.js +2362 -0
  159. plexora/plugins/figure_builder/static/figureCaptureBoxes.js +369 -0
  160. plexora/plugins/figure_builder/static/figureCaptureDock.js +466 -0
  161. plexora/plugins/figure_builder/static/figureCaptureTool.js +1034 -0
  162. plexora/plugins/figure_builder/static/figureConfirm.js +136 -0
  163. plexora/plugins/figure_builder/static/figureContextBar.js +1193 -0
  164. plexora/plugins/figure_builder/static/figureContextMenu.js +253 -0
  165. plexora/plugins/figure_builder/static/figureDocumentState.js +275 -0
  166. plexora/plugins/figure_builder/static/figureExportUi.js +174 -0
  167. plexora/plugins/figure_builder/static/figureLibrary.js +247 -0
  168. plexora/plugins/figure_builder/static/figureQuickEdit.js +628 -0
  169. plexora/plugins/figure_builder/static/figureRichText.js +634 -0
  170. plexora/plugins/figure_builder/static/figureSceneSnapshot.js +361 -0
  171. plexora/plugins/figure_builder/static/figureSchema.js +218 -0
  172. plexora/plugins/figure_builder/static/figureSidebarController.js +1159 -0
  173. plexora/plugins/figure_builder/static/figureTextEditor.js +503 -0
  174. plexora/plugins/figure_builder/static/figureTextPanel.js +491 -0
  175. plexora/plugins/figure_builder/static/figureViewOptions.js +273 -0
  176. plexora/plugins/figure_builder/static/figureWorkspace.js +2030 -0
  177. plexora/plugins/figure_builder/static/figure_builder.css +3292 -0
  178. plexora/plugins/figure_builder/templates/figure_builder/library.html +74 -0
  179. plexora/plugins/figure_builder/templates/figure_builder/workspace.html +27 -0
  180. plexora/plugins/figure_builder/templates/figure_builder/workspace_body.html +458 -0
  181. plexora/plugins/gating/__init__.py +76 -0
  182. plexora/plugins/gating/server/__init__.py +0 -0
  183. plexora/plugins/gating/server/anndata_gates.py +367 -0
  184. plexora/plugins/gating/server/database.py +16 -0
  185. plexora/plugins/gating/server/model.py +320 -0
  186. plexora/plugins/gating/server/routes.py +235 -0
  187. plexora/plugins/gating/static/csvGatingList.js +947 -0
  188. plexora/plugins/gating/static/gating.css +289 -0
  189. plexora/plugins/gating/static/gatingApi.js +221 -0
  190. plexora/plugins/gating/static/gatingSidebarController.js +513 -0
  191. plexora/plugins/gating/templates/gating/legacy.html +26 -0
  192. plexora/plugins/gating/templates/gating/panel.html +69 -0
  193. plexora/plugins/roi/__init__.py +95 -0
  194. plexora/plugins/roi/server/__init__.py +8 -0
  195. plexora/plugins/roi/server/adapters.py +655 -0
  196. plexora/plugins/roi/server/geojson.py +267 -0
  197. plexora/plugins/roi/server/geometry.py +181 -0
  198. plexora/plugins/roi/server/mapping.py +169 -0
  199. plexora/plugins/roi/server/operations.py +293 -0
  200. plexora/plugins/roi/server/repository.py +215 -0
  201. plexora/plugins/roi/server/routes.py +409 -0
  202. plexora/plugins/roi/server/schema.py +323 -0
  203. plexora/plugins/roi/static/roi.css +583 -0
  204. plexora/plugins/roi/static/roiApi.js +177 -0
  205. plexora/plugins/roi/static/roiFigureBridge.js +107 -0
  206. plexora/plugins/roi/static/roiGeometry.js +350 -0
  207. plexora/plugins/roi/static/roiRenderer.js +278 -0
  208. plexora/plugins/roi/static/roiSidebarController.js +1038 -0
  209. plexora/plugins/roi/static/roiState.js +518 -0
  210. plexora/plugins/roi/static/roiTools.js +993 -0
  211. plexora/plugins/roi/templates/roi/panel.html +240 -0
  212. plexora/proxy.py +57 -0
  213. plexora/server/models/adapters/__init__.py +94 -0
  214. plexora/server/models/adapters/anndata_adapter.py +388 -0
  215. plexora/server/models/adapters/base.py +93 -0
  216. plexora/server/models/adapters/classify.py +192 -0
  217. plexora/server/models/adapters/csv_adapter.py +105 -0
  218. plexora/server/models/adapters/inspection.py +265 -0
  219. plexora/server/models/adapters/spatialdata_adapter.py +248 -0
  220. plexora/server/models/centroid_tiles.py +305 -0
  221. plexora/server/models/data_model.py +1659 -0
  222. plexora/server/models/database_model.py +169 -0
  223. plexora/server/models/project.py +1270 -0
  224. plexora/server/plugins.py +199 -0
  225. plexora/server/routes/browse_routes.py +41 -0
  226. plexora/server/routes/data_routes.py +294 -0
  227. plexora/server/routes/import_routes.py +603 -0
  228. plexora/server/routes/page_routes.py +139 -0
  229. plexora/server/routes/project_routes.py +438 -0
  230. plexora/server/routes/quick_view_routes.py +62 -0
  231. plexora/server/routes/system_routes.py +39 -0
  232. plexora/server/routes/tool_routes.py +418 -0
  233. plexora/server/utils/addHEColumns.py +11 -0
  234. plexora/server/utils/fast_png.py +97 -0
  235. plexora/server/utils/fullConversion.py +50 -0
  236. plexora/server/utils/native_dialog.py +168 -0
  237. plexora/server/utils/pre_normalization.py +47 -0
  238. plexora/server/utils/segmentation_pyramid.py +598 -0
  239. plexora/server/utils/smallestenclosingcircle.py +126 -0
  240. plexora/server/utils/tiffsurgeon.py +372 -0
  241. plexora/server_cli.py +48 -0
  242. plexora/test.py +0 -0
  243. plexora-0.0.1.dist-info/METADATA +341 -0
  244. plexora-0.0.1.dist-info/RECORD +248 -0
  245. plexora-0.0.1.dist-info/WHEEL +5 -0
  246. plexora-0.0.1.dist-info/entry_points.txt +12 -0
  247. plexora-0.0.1.dist-info/licenses/LICENSE +207 -0
  248. plexora-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,199 @@
1
+ """Finding, installing and querying plugins.
2
+
3
+ Two discovery paths, both producing `plexora.api.Plugin` descriptors:
4
+
5
+ - the `plexora.plugins` entry point group, which is how a third-party
6
+ distribution advertises itself;
7
+ - a scan of the bundled plugins package, which is how the plugins shipped in
8
+ this repository advertise themselves.
9
+
10
+ Both exist on purpose. Entry points are the real extension mechanism, but they
11
+ only appear once package metadata has been regenerated, so relying on them
12
+ alone would put `pip install -e .` between editing a bundled plugin and being
13
+ able to run it. The scan keeps working-from-source honest. Names are
14
+ deduplicated, so declaring a bundled plugin in pyproject.toml as well is
15
+ harmless.
16
+
17
+ **Discovery never imports a plugin it was not asked for.** Names come from
18
+ directory entries and entry-point metadata, both of which are readable without
19
+ executing the plugin's code; only the chosen ones are then imported. This is
20
+ what keeps a core-only build free of an addon's dependencies -- importing
21
+ gating's descriptor would drag in anndata and h5py, which is precisely the cost
22
+ the boundary exists to avoid. A plugin's package name must therefore match its
23
+ declared `PLUGIN.name`, since the name is known before the descriptor is.
24
+
25
+ Which plugins are active is controlled by PLEXORA_PLUGINS:
26
+
27
+ unset every discovered plugin (installing one is what enables it)
28
+ "" none -- a core-only build
29
+ "a,b" exactly those, in that order
30
+
31
+ Any number can be active at once. Only the cell-layer claim is exclusive, and
32
+ that is arbitrated client-side.
33
+ """
34
+
35
+ from __future__ import annotations
36
+
37
+ import importlib
38
+ import os
39
+ import pkgutil
40
+
41
+ from plexora.api.plugin import Plugin
42
+
43
+ ENTRY_POINT_GROUP = "plexora.plugins"
44
+
45
+ ENV_VAR = "PLEXORA_PLUGINS"
46
+
47
+ #: Package scanned for bundled plugins. Each subpackage exposing a module-level
48
+ #: PLUGIN is one.
49
+ BUNDLED_PACKAGE = "plexora.plugins"
50
+
51
+ #: Where install() records what it mounted, for later lookup by the routes.
52
+ _CONFIG_KEY = "PLEXORA_INSTALLED_PLUGINS"
53
+
54
+
55
+ def _bundled_names() -> list[str]:
56
+ """Subpackage names under BUNDLED_PACKAGE, without importing any of them.
57
+
58
+ Scans `__path__` rather than a filesystem path built from `__file__`. The
59
+ two are the same thing when running from source, but only `__path__` goes
60
+ through the importer that actually loaded the package -- which is what makes
61
+ this work in a PyInstaller build, where the submodules live in the archive
62
+ and the directory `__file__` points at holds no .py files at all.
63
+ """
64
+ try:
65
+ package = importlib.import_module(BUNDLED_PACKAGE)
66
+ except ImportError:
67
+ return []
68
+ search_path = list(getattr(package, "__path__", []))
69
+ return [info.name for info in pkgutil.iter_modules(search_path) if info.ispkg]
70
+
71
+
72
+ def _entry_points_by_name() -> dict:
73
+ from importlib.metadata import entry_points
74
+
75
+ return {ep.name: ep for ep in entry_points(group=ENTRY_POINT_GROUP)}
76
+
77
+
78
+ def available_names() -> list[str]:
79
+ """Every plugin name visible to this process. Imports nothing."""
80
+ names = list(_bundled_names())
81
+ for name in _entry_points_by_name():
82
+ if name not in names:
83
+ names.append(name)
84
+ return names
85
+
86
+
87
+ def load(name: str) -> Plugin | None:
88
+ """Import one plugin and return its descriptor, or None if unusable.
89
+
90
+ A plugin that fails to import is reported and skipped: a broken or
91
+ half-installed third-party package must not make the app unstartable.
92
+ """
93
+ try:
94
+ if name in _bundled_names():
95
+ module = importlib.import_module(f"{BUNDLED_PACKAGE}.{name}")
96
+ plugin = getattr(module, "PLUGIN", None)
97
+ else:
98
+ entry_point = _entry_points_by_name().get(name)
99
+ plugin = entry_point.load() if entry_point is not None else None
100
+ except Exception as exc:
101
+ print(f"WARNING: plugin {name!r} failed to load: {exc}")
102
+ return None
103
+
104
+ if not isinstance(plugin, Plugin):
105
+ print(f"WARNING: plugin {name!r} exposes no PLUGIN descriptor; ignoring")
106
+ return None
107
+ if plugin.name != name:
108
+ print(
109
+ f"WARNING: plugin package {name!r} declares PLUGIN.name={plugin.name!r}; "
110
+ "they must match, ignoring"
111
+ )
112
+ return None
113
+ return plugin
114
+
115
+
116
+ def requested(env=None) -> list[str] | None:
117
+ """Plugin names PLEXORA_PLUGINS asks for; None means "everything found".
118
+
119
+ An empty string is distinct from unset: it means a deliberate core-only
120
+ build and must not fall through to the default.
121
+ """
122
+ env = os.environ if env is None else env
123
+ raw = env.get(ENV_VAR)
124
+ if raw is None:
125
+ return None
126
+ return [name.strip() for name in raw.split(",") if name.strip()]
127
+
128
+
129
+ def install(app, names=None) -> list[Plugin]:
130
+ """Mount the requested plugins on `app` and record them."""
131
+ if names is None:
132
+ names = requested()
133
+
134
+ available = available_names()
135
+ if names is None:
136
+ wanted = available
137
+ else:
138
+ wanted = [name for name in names if name in available]
139
+ for missing in [name for name in names if name not in available]:
140
+ print(f"WARNING: {ENV_VAR} names unknown plugin {missing!r}; ignoring")
141
+
142
+ chosen = []
143
+ for name in wanted:
144
+ plugin = load(name)
145
+ if plugin is None:
146
+ continue
147
+ blueprint = plugin.load_blueprint()
148
+ if blueprint is not None:
149
+ app.register_blueprint(blueprint, url_prefix=plugin.url_prefix)
150
+ chosen.append(plugin)
151
+
152
+ app.config[_CONFIG_KEY] = chosen
153
+ return chosen
154
+
155
+
156
+ def installed(app) -> list[Plugin]:
157
+ return app.config.get(_CONFIG_KEY, [])
158
+
159
+
160
+ def find(app, name) -> Plugin | None:
161
+ return next((p for p in installed(app) if p.name == name), None)
162
+
163
+
164
+ def nav_items(app, base_url="") -> list[dict]:
165
+ """Every installed plugin's core-menu entries, in a stable order.
166
+
167
+ Sorted rather than left in discovery order: which plugins are found first
168
+ depends on entry-point metadata and directory listing, and a File menu whose
169
+ items move between machines is a File menu nobody can be told how to use.
170
+
171
+ Independent of any datasource, unlike `tools_for`. These entries lead to
172
+ pages that are not about one project -- Figure Builder's library spans them
173
+ -- so gating them on the current project would hide the way in from the
174
+ state the user is most often in when they want it, which is having nothing
175
+ open.
176
+ """
177
+ items = []
178
+ for plugin in installed(app):
179
+ items.extend(plugin.describe_nav(base_url))
180
+ items.sort(key=lambda item: (item["menu"], item["order"], item["label"]))
181
+ return items
182
+
183
+
184
+ def tools_for(app, project) -> list[Plugin]:
185
+ """Installed plugins compatible with this datasource -- what the Tools menu
186
+ offers.
187
+
188
+ Deliberately compatibility, not readiness. A plugin whose feature table the
189
+ project has not got yet still belongs in the menu: opening it is how the
190
+ user gets asked for one. Filtering these out here hid the tool AND the only
191
+ route to making it work.
192
+ """
193
+ return [p for p in installed(app) if p.requires.applies_to(project)]
194
+
195
+
196
+ def ready_tools(app, project) -> list[Plugin]:
197
+ """Installed plugins this datasource can open right now -- everything in
198
+ tools_for() that is not still missing an input."""
199
+ return [p for p in installed(app) if p.requires.satisfied_by(project)]
@@ -0,0 +1,41 @@
1
+ # Backs the "Browse..." buttons that open a native OS file/folder picker
2
+ # server-side (see server/utils/native_dialog.py for why this has to be a
3
+ # subprocess). Returns a path only -- never file bytes.
4
+
5
+ from flask import jsonify, request
6
+
7
+ from plexora import app
8
+ from plexora.server.utils.native_dialog import FILTER_NAMES, browse_for_path
9
+
10
+
11
+ @app.route('/browse_path', methods=['POST'])
12
+ def browse_path():
13
+ # A native file dialog opens on the machine running the SERVER, which in
14
+ # notebook and hosted mode is not the machine with the user's screen -- and
15
+ # frequently has no display at all. What that produced was not an error but
16
+ # a hang: the osascript/tkinter subprocess waits for input from a desktop
17
+ # nobody can see, holding a waitress thread until it is killed.
18
+ if app.config.get('PLEXORA_NOTEBOOK_MODE'):
19
+ return jsonify(
20
+ error="Native file dialogs are unavailable in notebook/hosted mode; "
21
+ "type the path instead."
22
+ ), 400
23
+
24
+ payload = request.get_json(silent=True) or {}
25
+ mode = payload.get('mode') or 'file'
26
+ if mode not in ('file', 'directory'):
27
+ return jsonify(error="Invalid mode."), 400
28
+
29
+ # Validated against the dialog module's own table, not a copy: a filter it
30
+ # knows about but this list did not made the button dead rather than
31
+ # unfiltered, and silently -- attachBrowseButton had nowhere to show a 400.
32
+ file_filter = payload.get('filter') or 'any'
33
+ if file_filter not in FILTER_NAMES:
34
+ return jsonify(error=f"Unknown file filter: {file_filter}"), 400
35
+
36
+ try:
37
+ path = browse_for_path(mode=mode, file_filter=file_filter)
38
+ except RuntimeError as exc:
39
+ return jsonify(error=str(exc)), 500
40
+
41
+ return jsonify(path=path)
@@ -0,0 +1,294 @@
1
+ from plexora import app
2
+ from flask import make_response, render_template, request, Response, jsonify, abort, send_file
3
+ import csv
4
+ import io
5
+ from plexora import get_config
6
+ from plexora.datasource import rename_channels
7
+ from plexora.server.models import data_model
8
+ import gzip
9
+ import json
10
+ import orjson
11
+ import threading
12
+ from collections import OrderedDict
13
+ from os import walk
14
+
15
+
16
+ @app.route('/init_database', methods=['GET'])
17
+ def init_database():
18
+ datasource = request.args.get('datasource')
19
+ data_model.init(datasource)
20
+ resp = jsonify(success=True)
21
+ return resp
22
+
23
+
24
+ @app.route('/config')
25
+ def serve_config():
26
+ return get_config()
27
+
28
+
29
+ @app.route('/get_nearest_cell', methods=['GET'])
30
+ def get_nearest_cell():
31
+ x = float(request.args.get('point_x'))
32
+ y = float(request.args.get('point_y'))
33
+ datasource = request.args.get('datasource')
34
+ resp = data_model.query_for_closest_cell(x, y, datasource)
35
+ return serialize_and_submit_json(resp)
36
+
37
+
38
+ # Gets a row based on the index
39
+ @app.route('/get_database_row', methods=['GET'])
40
+ def get_database_row():
41
+ datasource = request.args.get('datasource')
42
+ row = int(request.args.get('row'))
43
+ resp = data_model.get_row(row, datasource)
44
+ return serialize_and_submit_json(resp)
45
+
46
+
47
+ @app.route('/get_channel_names', methods=['GET'])
48
+ def get_channel_names():
49
+ datasource = request.args.get('datasource')
50
+ shortnames = bool(request.args.get('shortNames'))
51
+ resp = data_model.get_channel_names(datasource, shortnames)
52
+ return serialize_and_submit_json(resp)
53
+
54
+
55
+ @app.route('/get_all_cells/<dtype>/', methods=['GET'])
56
+ def get_all_cells(dtype):
57
+ datasource = request.args.get('datasource')
58
+ data_type = int if 'integer' == dtype else float
59
+ start_keys = list(request.args.get('start_keys').split(','))
60
+ resp = data_model.get_all_cells(datasource, start_keys, data_type)
61
+ content = gzip.compress(resp.tobytes('C'))
62
+ response = make_response(content)
63
+ response.headers.set('Content-Type', 'application/octet-stream')
64
+ response.headers['Content-length'] = len(content)
65
+ response.headers['Content-Encoding'] = 'gzip'
66
+ return response
67
+
68
+
69
+ @app.route('/get_centroid_manifest', methods=['GET'])
70
+ def get_centroid_manifest():
71
+ datasource = request.args.get('datasource')
72
+ resp = data_model.get_centroid_manifest(datasource)
73
+ return serialize_and_submit_json(resp)
74
+
75
+
76
+ @app.route('/get_centroid_tiles', methods=['POST'])
77
+ def get_centroid_tiles():
78
+ post_data = json.loads(request.data)
79
+ datasource = post_data['datasource']
80
+ level = int(post_data.get('level', 0))
81
+ tiles = post_data.get('tiles', [])
82
+ filter = post_data.get('filter', {})
83
+ max_points = post_data.get('max_points')
84
+ resp = data_model.get_centroid_tiles(datasource, level, tiles, filter, max_points)
85
+ content = gzip.compress(resp.tobytes('C'))
86
+ response = make_response(content)
87
+ response.headers.set('Content-Type', 'application/octet-stream')
88
+ response.headers['Content-length'] = len(content)
89
+ response.headers['Content-Encoding'] = 'gzip'
90
+ response.headers['X-Centroid-Record-Count'] = len(resp)
91
+ return response
92
+
93
+
94
+ @app.route('/get_channel_cell_ids', methods=['GET'])
95
+ def get_channel_cell_ids():
96
+ datasource = request.args.get('datasource')
97
+ filter = json.loads(request.args.get('filter'))
98
+ resp = data_model.get_channel_cells(datasource, filter)
99
+ return serialize_and_submit_json(resp)
100
+
101
+
102
+ @app.route('/get_database_description', methods=['GET'])
103
+ def get_database_description():
104
+ datasource = request.args.get('datasource')
105
+ resp = data_model.get_datasource_description(datasource)
106
+ return serialize_and_submit_json(resp)
107
+
108
+
109
+ @app.route('/get_channel_gmm', methods=['GET'])
110
+ def get_channel_gmm():
111
+ channel = request.args.get('channel')
112
+ datasource = request.args.get('datasource')
113
+ resp = data_model.get_channel_gmm(channel, datasource)
114
+ return serialize_and_submit_json(resp)
115
+
116
+
117
+ @app.route('/get_image_channel_stats', methods=['GET'])
118
+ def get_image_channel_stats():
119
+ channel = request.args.get('channel')
120
+ datasource = request.args.get('datasource')
121
+ resp = data_model.get_image_channel_stats(channel, datasource)
122
+ return serialize_and_submit_json(resp)
123
+
124
+
125
+ @app.route('/get_segmentation_status', methods=['GET'])
126
+ def get_segmentation_status():
127
+ datasource = request.args.get('datasource')
128
+ return jsonify(data_model.get_segmentation_job_status(datasource))
129
+
130
+ @app.route('/upload_channels', methods=['POST'])
131
+ def upload_channels():
132
+ """Rename an already-registered datasource's image channels from an
133
+ uploaded single-column CSV (one name per row, in channel order) -- lets
134
+ users fix gating/channel auto-matching without re-registering the whole
135
+ datasource. If the row count is exactly one more than the channel count,
136
+ the first row is assumed to be a header and dropped.
137
+ """
138
+ file = request.files['file']
139
+ if file.filename.endswith('.csv') == False:
140
+ abort(422)
141
+ datasource = request.form['datasource']
142
+ config = get_config()
143
+ if datasource not in config:
144
+ abort(422)
145
+
146
+ n_channels = sum(1 for c in config[datasource]['imageData'] if c['name'] != 'Area')
147
+
148
+ text = file.read().decode('utf-8-sig', errors='replace')
149
+ names = []
150
+ for row in csv.reader(io.StringIO(text)):
151
+ cells = [cell.strip() for cell in row if cell.strip()]
152
+ if cells:
153
+ names.append(cells[0])
154
+ if len(names) == n_channels + 1:
155
+ names = names[1:]
156
+
157
+ try:
158
+ rename_channels(datasource, names)
159
+ except ValueError as exc:
160
+ return jsonify(success=False, error=str(exc)), 400
161
+
162
+ data_model.load_datasource(datasource, reload=True)
163
+ return jsonify(success=True)
164
+
165
+ @app.route('/get_ome_metadata', methods=['GET'])
166
+ def get_ome_metadata():
167
+ datasource = request.args.get('datasource')
168
+ resp = data_model.get_ome_metadata(datasource)
169
+ if hasattr(resp, "model_dump"):
170
+ resp = resp.model_dump(mode="json")
171
+ elif hasattr(resp, "dict"):
172
+ resp = resp.dict()
173
+ elif not resp:
174
+ resp = {}
175
+ # OME-Types handles jsonify itself, so skip the orjson conversion
176
+ response = app.response_class(
177
+ response=json.dumps(resp),
178
+ mimetype='application/json'
179
+ )
180
+ return response
181
+
182
+
183
+ @app.route('/save_channel_list', methods=['POST'])
184
+ def save_channel_list():
185
+ post_data = json.loads(request.data)
186
+
187
+ datasource = post_data['datasource']
188
+ map_channels = post_data['map_channels']
189
+ active_channels = post_data['active_channels']
190
+ list_colors = post_data['list_colors']
191
+ list_ranges = post_data['list_ranges']
192
+ list_channels = post_data['list_channels']
193
+
194
+ data_model.save_channel_list(datasource, map_channels, active_channels, list_colors, list_ranges, list_channels)
195
+
196
+ resp = jsonify(success=True)
197
+ return resp
198
+
199
+ @app.route('/get_saved_channel_list', methods=['GET'])
200
+ def get_saved_channel_list():
201
+ datasource = request.args.get('datasource')
202
+ resp = data_model.get_saved_channel_list(datasource)
203
+ return serialize_and_submit_json(resp)
204
+
205
+ _tile_png_cache = OrderedDict()
206
+ _tile_png_cache_lock = threading.Lock()
207
+ _TILE_PNG_CACHE_MAX = 1500
208
+
209
+
210
+ def _get_tile_png_bytes(datasource, channel, level, tile, quality):
211
+ # ensure_loaded() must run BEFORE sampling load_generation: loading is what
212
+ # bumps the generation, so sampling first would file the encoded bytes under
213
+ # the pre-load generation and every later request would miss. Keying on the
214
+ # generation means a datasource reload (which may regenerate segmentation,
215
+ # per refresh_segmentation_mapping) naturally invalidates cached tiles
216
+ # without cross-module cache access. `quality` is part of the key so
217
+ # default/hd/legacy variants of the same tile don't collide.
218
+ generation = data_model.ensure_loaded(datasource)
219
+ key = (generation, datasource, channel, level, tile, quality)
220
+ with _tile_png_cache_lock:
221
+ cached = _tile_png_cache.get(key)
222
+ if cached is not None:
223
+ _tile_png_cache.move_to_end(key)
224
+ return cached
225
+
226
+ encoded, mimetype = data_model.encode_tile(datasource, channel, level, tile, quality)
227
+
228
+ with _tile_png_cache_lock:
229
+ _tile_png_cache[key] = (encoded, mimetype)
230
+ _tile_png_cache.move_to_end(key)
231
+ while len(_tile_png_cache) > _TILE_PNG_CACHE_MAX:
232
+ _tile_png_cache.popitem(last=False)
233
+ return encoded, mimetype
234
+
235
+
236
+ # E.G /generated/data/melanoma/channel_00_files/13/16_18.png
237
+ # ?q=hd requests the full-precision 16-bit path for channel tiles; anything
238
+ # else (including the param being absent) uses the fast default WebP path.
239
+ # Segmentation tiles ignore `q` entirely -- see data_model.encode_tile.
240
+ @app.route('/generated/data/<string:datasource>/<string:channel>/<string:level>/<string:tile>')
241
+ def generate_png(datasource, channel, level, tile):
242
+ # Frontend can now decode WebP (createImageBitmap-based u8 path, verified
243
+ # against real data) -- an absent `q` is the true default: fast/small
244
+ # WebP. `q=legacy` is kept as an explicit escape hatch back to the
245
+ # original uncompressed PNG behavior if ever needed.
246
+ quality = request.args.get('q', 'webp')
247
+ encoded, mimetype = _get_tile_png_bytes(datasource, channel, level, tile, quality)
248
+
249
+ # Tile bytes are immutable for a given load_generation, so let the browser
250
+ # keep them: without this Flask's send_file() emits `Cache-Control:
251
+ # no-cache` and every pan back over visited ground is a fresh round trip
252
+ # through the (globally serialized) zarr/tifffile reader. The generation is
253
+ # in the ETag rather than the URL so a reload invalidates without the
254
+ # frontend having to rewrite tile URLs -- a stale conditional request gets
255
+ # a 200 with fresh bytes instead of a wrong 304.
256
+ etag = f'"{data_model.load_generation}-{datasource}-{channel}-{level}-{tile}-{quality}"'
257
+ if request.headers.get('If-None-Match') == etag:
258
+ response = app.response_class(status=304)
259
+ else:
260
+ response = send_file(io.BytesIO(encoded), mimetype=mimetype)
261
+ response.headers['ETag'] = etag
262
+ response.headers['Cache-Control'] = 'private, max-age=31536000'
263
+ return response
264
+
265
+ # The viewer mini-map's source: one channel's whole tissue, ~200-400 px, in the
266
+ # same [0, 255] domain as the WebP tiles. Separate from the tile route on
267
+ # purpose -- see data_model.generate_channel_overview for why no tile level is
268
+ # reliably a single whole-image tile.
269
+ @app.route('/generated/overview/<string:datasource>/<string:channel>')
270
+ def generate_overview(datasource, channel):
271
+ # Before sampling load_generation, for the same reason as the tile path:
272
+ # loading is what bumps the generation.
273
+ generation = data_model.ensure_loaded(datasource)
274
+
275
+ etag = f'"{generation}-overview-{datasource}-{channel}"'
276
+ if request.headers.get('If-None-Match') == etag:
277
+ response = app.response_class(status=304)
278
+ else:
279
+ encoded = data_model.generate_channel_overview(datasource, channel)
280
+ if encoded is None:
281
+ abort(404)
282
+ response = send_file(io.BytesIO(encoded), mimetype='image/webp')
283
+ response.headers['ETag'] = etag
284
+ response.headers['Cache-Control'] = 'private, max-age=31536000'
285
+ return response
286
+
287
+
288
+ def serialize_and_submit_json(data):
289
+ response = app.response_class(
290
+ response=orjson.dumps(data, option=orjson.OPT_SERIALIZE_NUMPY),
291
+ mimetype='application/json'
292
+ )
293
+ return response
294
+