cubevis 1.0.21__py3-none-any.whl → 1.0.26__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.
cubevis/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = '1.0.21'
1
+ __version__ = '1.0.26'
cubevis/bokeh/__init__.py CHANGED
@@ -30,6 +30,7 @@ provided by Bokeh'''
30
30
 
31
31
  from .state import order_bokeh_js as _order_bokeh_js
32
32
  from .state import register_model as _register_model
33
+ from .state._initialize import get_bokeh_js_paths
33
34
  from .state import set_cubevis_lib
34
35
 
35
36
  class BokehInit:
@@ -5,6 +5,7 @@ from bokeh.core.properties import Instance, String
5
5
 
6
6
  from bokeh.io import curdoc
7
7
  from .. import BokehInit
8
+ from ...utils import is_colab
8
9
 
9
10
  logger = logging.getLogger(__name__)
10
11
 
@@ -272,8 +273,11 @@ class Showable(LayoutDOM,BokehInit):
272
273
  Common logic for generating HTML in notebook environments.
273
274
  Returns the HTML string to display, or None if not in a notebook.
274
275
  """
275
- from bokeh.embed import components
276
+ from bokeh.embed import components, json_item
276
277
  from bokeh.io.state import curstate
278
+ from bokeh.resources import CDN
279
+ import sys
280
+ import json as json_lib
277
281
 
278
282
  state = curstate()
279
283
 
@@ -284,31 +288,92 @@ class Showable(LayoutDOM,BokehInit):
284
288
  return '<div style="color: red; padding: 10px; border: 1px solid red;">Showable object with no UI set</div>'
285
289
 
286
290
  if self._display_context:
287
- self._display_context.on_show( )
291
+ self._display_context.on_show()
288
292
 
289
293
  if self._notebook_rendering:
290
294
  # Return a lightweight reference instead of re-rendering the full GUI
291
295
  return f'''
292
296
  <div style="padding: 10px; background: #f0f8f0; border-left: 4px solid #4CAF50; margin: 5px 0;">
293
- <strong>↑ iclean GUI active above</strong>
297
+ <strong>→ iclean GUI active above</strong>
294
298
  <small style="color: #666; display: block; margin-top: 5px;">
295
299
  Showable ID: {self.id[-8:]} | Backend: Running
296
300
  </small>
297
301
  </div>
298
302
  '''
299
303
 
300
- # Apply notebook sizing for Jupyter context
301
- ###if self._notebook_sizing == 'fixed':
302
- ### self.sizing_mode = None
303
- ### self.width = self._notebook_width
304
- ### self.height = self._notebook_height
304
+ if is_colab( ):
305
+ # Get all JS paths from the existing function
306
+ # This returns paths in the correct order:
307
+ # [casalib, bokeh-core, bokeh-widgets, bokeh-tables, cubevisjs]
308
+ from cubevis.bokeh import get_bokeh_js_paths
309
+ js_paths = get_bokeh_js_paths( )
310
+
311
+ # Build script tags for all libraries in order
312
+ all_scripts = '\n'.join([
313
+ f'<script type="text/javascript" src="{url}"></script>'
314
+ for url in js_paths
315
+ ])
316
+
317
+ # Use json_item approach which is more reliable in iframes
318
+ item = json_item(self, target=f"bokeh-{self.id}")
319
+ item_json = json_lib.dumps(item)
320
+
321
+ # Build complete HTML with proper loading sequence
322
+ # get_bokeh_js_paths() already returns libs in the correct order:
323
+ # 1. casalib (third-party libs for CustomJS)
324
+ # 2. bokeh-core
325
+ # 3. bokeh-widgets
326
+ # 4. bokeh-tables
327
+ # 5. cubevisjs (custom Bokeh models)
328
+ html = f'''
329
+ {f'<link href="{CDN.css_files[0]}" rel="stylesheet" type="text/css">' if CDN.css_files else ""}
330
+ <div id="bokeh-{self.id}" class="bk-root"></div>
331
+ {all_scripts}
332
+ <script type="text/javascript">
333
+ (function() {{
334
+ var item = {item_json};
335
+
336
+ function embedWhenReady() {{
337
+ // Check if all required libraries are loaded
338
+ if (typeof Bokeh !== 'undefined' && Bokeh.embed) {{
339
+ var target = document.getElementById("bokeh-{self.id}");
340
+ if (target) {{
341
+ try {{
342
+ Bokeh.embed.embed_item(item);
343
+ console.log("Bokeh plot embedded successfully");
344
+ }} catch(e) {{
345
+ console.error("Error embedding Bokeh plot:", e);
346
+ }}
347
+ }} else {{
348
+ console.error("Target element not found");
349
+ setTimeout(embedWhenReady, 50);
350
+ }}
351
+ }} else {{
352
+ setTimeout(embedWhenReady, 50);
353
+ }}
354
+ }}
355
+
356
+ if (document.readyState === 'loading') {{
357
+ document.addEventListener('DOMContentLoaded', embedWhenReady);
358
+ }} else {{
359
+ embedWhenReady();
360
+ }}
361
+ }})();
362
+ </script>
363
+ '''
305
364
 
306
- script, div = components(self)
307
- if start_backend:
308
- self._start_backend()
365
+ if start_backend:
366
+ self._start_backend()
309
367
 
310
- self._notebook_rendering = f'{script}\n{div}'
311
- return self._notebook_rendering
368
+ self._notebook_rendering = html
369
+ return html
370
+ else:
371
+ # In Jupyter Lab/Classic, use components() as before
372
+ script, div = components(self)
373
+ if start_backend:
374
+ self._start_backend()
375
+ self._notebook_rendering = f'{script}\n{div}'
376
+ return self._notebook_rendering
312
377
 
313
378
  def _repr_mimebundle_(self, include=None, exclude=None):
314
379
  """
@@ -321,6 +321,13 @@ def order_bokeh_js():
321
321
  resources.Resources.js_files = property(js_files)
322
322
  return
323
323
 
324
+ #def get_bokeh_js_paths( ):
325
+ # modes = ['cdn','inline','server','server-dev','relative','relative-dev','absolute','absolute-dev']
326
+ # return { 'new': { mode: resources.Resources(mode=mode).js_files for mode in modes },
327
+ # 'old': { mode: resources.Resources(mode=mode)._old_js_files for mode in modes } }
328
+ def get_bokeh_js_paths( ):
329
+ return resources.Resources(mode='cdn').js_files
330
+
324
331
  def get_jupyter_state( ):
325
332
  """Get the package-level Jupyter state"""
326
333
  return _JUPYTER_STATE
cubevis/toolbox/_cube.py CHANGED
@@ -1082,7 +1082,7 @@ class CubeMask:
1082
1082
  ### Firefox incorrectly sizes the colormap histogram plot resulting in the right
1083
1083
  ### side being outside of the browser window... this may have to be tweaked again
1084
1084
  ### when Jupyter notebooks are supported...
1085
- ( [ Spacer( width=120 ) ] if have_firefox( ) else [ ] ), sizing_mode='stretch_both' ),
1085
+ ( [ Spacer( width=120 ) ] if not is_interactive_jupyter( ) and have_firefox( ) else [ ] ), sizing_mode='stretch_both' ),
1086
1086
  row( Tip( self._cm_adjust['min input'],
1087
1087
  tooltip=Tooltip( content=HTML("set minimum clip here or drag the left red line above"),
1088
1088
  position="top" ) ),
cubevis/utils/__init__.py CHANGED
@@ -43,7 +43,7 @@ from ._regions import polygon_indexes
43
43
  from ._docenum import DocEnum
44
44
  from ._copydoc import copydoc
45
45
  from ._pkgs import find_pkg, load_pkg
46
- from ._jupyter import is_interactive_jupyter
46
+ from ._jupyter import is_interactive_jupyter, is_colab
47
47
  from ._browser import have_firefox
48
48
  from ._git import max_git_version
49
49
 
cubevis/utils/_jupyter.py CHANGED
@@ -1,3 +1,5 @@
1
+ import os
2
+ import sys
1
3
  import logging
2
4
 
3
5
  logger = logging.getLogger(__name__)
@@ -17,6 +19,15 @@ logger = logging.getLogger(__name__)
17
19
  # except NameError:
18
20
  # return False
19
21
 
22
+ def is_colab():
23
+ """
24
+ Detects if the current environment is Google Colab.
25
+ Combines module check (process-level) and env-var check (VM-level).
26
+ """
27
+ # 1. Check for the Colab-specific environment variable (VM level)
28
+ # 2. Check for the google.colab module (Python process level)
29
+ return os.getenv("COLAB_RELEASE_TAG") is not None or 'google.colab' in sys.modules
30
+
20
31
  def is_interactive_jupyter( ) -> bool:
21
32
  """
22
33
  Detect if running in an interactive Jupyter notebook with frontend connection.
@@ -25,6 +36,7 @@ def is_interactive_jupyter( ) -> bool:
25
36
  - Interactive Jupyter notebook/lab with frontend (returns True)
26
37
  - Standalone Jupyter kernel without frontend (returns False)
27
38
  - Regular Python interpreter (returns False)
39
+ - Support Google Colab and legacy Jupyter versions.
28
40
 
29
41
  Returns:
30
42
  bool: True if running in interactive Jupyter with frontend, False otherwise
@@ -37,12 +49,21 @@ def is_interactive_jupyter( ) -> bool:
37
49
  logger.debug(f"\tis_interactive_jupyter<1>: False")
38
50
  return False
39
51
 
40
- # Check if we're in a ZMQ-based shell (kernel)
41
- if ipython.__class__.__name__ != 'ZMQInteractiveShell':
52
+ # Allow Colab's 'Shell' class in addition to standard 'ZMQInteractiveShell'
53
+ shell_class = ipython.__class__.__name__
54
+ is_colab = 'google.colab' in sys.modules
55
+
56
+ # Check if we're in a ZMQ-based shell (kernel) or Colab's 'Shell'
57
+ if shell_class not in ['ZMQInteractiveShell', 'Shell'] and not is_colab:
42
58
  logger.debug(f"\tis_interactive_jupyter<2>: False")
43
59
  return False
44
60
 
45
- # Check for active frontend connection
61
+ # If we are in Colab, the existence of the shell itself implies
62
+ # an interactive frontend, as Colab sessions are inherently interactive.
63
+ if is_colab:
64
+ return True
65
+
66
+ # Check for active frontend connection (Standard Jupyter/Legacy)
46
67
  if hasattr(ipython, 'kernel') and ipython.kernel is not None:
47
68
  kernel = ipython.kernel
48
69
 
@@ -51,14 +72,15 @@ def is_interactive_jupyter( ) -> bool:
51
72
  # For newer Jupyter versions, check connection count
52
73
  if hasattr(kernel, 'connection_count'):
53
74
  logger.debug(f"\tis_interactive_jupyter<3>: {kernel.connection_count > 0}")
54
- return kernel.connection_count > 0
75
+ if kernel.connection_count > 0:
76
+ return True
55
77
 
56
78
  # For older versions, check if socket is connected
57
79
  try:
58
80
  # Try to get socket state - if it fails, likely no frontend
59
- socket_state = kernel.shell_socket.closed
60
81
  logger.debug(f"\tis_interactive_jupyter<4>: {not socket_state}")
61
- return not socket_state
82
+ if not kernel.shell_socket.closed:
83
+ return True
62
84
  except AttributeError:
63
85
  pass
64
86
 
@@ -68,7 +90,8 @@ def is_interactive_jupyter( ) -> bool:
68
90
  parent = kernel.get_parent()
69
91
  # If there's a parent message, we're likely in interactive mode
70
92
  logger.debug(f"\tis_interactive_jupyter<5>: {parent is not None and len(parent) > 0}")
71
- return parent is not None and len(parent) > 0
93
+ if parent is not None and len(parent) > 0:
94
+ return True
72
95
  except Exception:
73
96
  pass
74
97
 
@@ -77,12 +100,12 @@ def is_interactive_jupyter( ) -> bool:
77
100
  logger.debug(f"\tis_interactive_jupyter<6>: True")
78
101
  return True
79
102
 
80
- # Fallback: Check for common Jupyter notebook environment indicators
81
- # This catches cases where kernel introspection doesn't work
82
- import os
103
+ # Fallback: Check for environment indicators (Legacy/Containerized Jupyter)
83
104
  jupyter_indicators = [
84
- 'JPY_PARENT_PID', # JupyterLab/Notebook sets this
105
+ 'JPY_PARENT_PID', # JupyterLab/Notebook sets this
85
106
  'JUPYTER_RUNTIME_DIR',
107
+ 'COLAB_RELEASE_DEVICE', # Additional Colab-specific env check
108
+ 'COLAB_GPU' # Additional Colab-specific env check
86
109
  ]
87
110
 
88
111
  for indicator in jupyter_indicators:
@@ -99,6 +122,6 @@ def is_interactive_jupyter( ) -> bool:
99
122
  logger.debug(f"\tis_interactive_jupyter<8>: False")
100
123
  return False
101
124
 
102
- except ImportError:
125
+ except (ImportError, Exception):
103
126
  logger.debug(f"\tis_interactive_jupyter<9>: False")
104
127
  return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cubevis
3
- Version: 1.0.21
3
+ Version: 1.0.26
4
4
  Summary: visualization toolkit and apps for casa
5
5
  License: LGPL
6
6
  Author-email: Darrell Schiebel <darrell@schiebel.us>,Pam Harris <pharris@nrao.edu>
@@ -34,7 +34,7 @@ cubevis/__js__/bokeh-3.6/cubevisjs.min.js,sha256=bZ8IjciHZwcUMrrc_6a3n965WlPCMeQ
34
34
  cubevis/__js__/bokeh-3.7/cubevisjs.min.js,sha256=bZ8IjciHZwcUMrrc_6a3n965WlPCMeQedZjb4-0Ln34,42526
35
35
  cubevis/__js__/bokeh-3.8/cubevisjs.min.js,sha256=bZ8IjciHZwcUMrrc_6a3n965WlPCMeQedZjb4-0Ln34,42526
36
36
  cubevis/__js__/casalib.min.js,sha256=J9Uvlat_Vf6cjcvftOG5COk3YH6A371MJ7s5u_ZS2_4,91133
37
- cubevis/bokeh/__init__.py,sha256=b2Vgszi7sQPFyu2b4fnQzVXk5uX4B9vb59CilQpP31I,1835
37
+ cubevis/bokeh/__init__.py,sha256=dDIV8jBZji-bD8TQQKBMaF5UuabaJ5NICWn6g_QHxvs,1885
38
38
  cubevis/bokeh/annotations/__init__.py,sha256=tjDIPKbg-rh7Iu3coFWvmX-j2yNj9KuKmRp1aTo71ww,50
39
39
  cubevis/bokeh/annotations/_ev_poly_annotation.py,sha256=RzP4E1_rII9z37uHX2nUnXhzfPSvw0noYpcjE7M0YCk,208
40
40
  cubevis/bokeh/components/__init__.py,sha256=BQOqgBtlDpu6ENrY42nYeS73n2ZSMogJgM2LtJibfVM,1314
@@ -46,7 +46,7 @@ cubevis/bokeh/models/_bokeh_app_context.py,sha256=iHCFAJzFinX8I6ty3Vdw6w0Za-5qpo
46
46
  cubevis/bokeh/models/_edit_span.py,sha256=7o59ZS0bF_Q_WtstvViWXP-2PiY_F7_zCecTqKcmz0E,196
47
47
  cubevis/bokeh/models/_ev_text_input.py,sha256=SGtefXkWK6jHEk4EneZ_hEUGwoIWwVGjwqLjGsAXMpY,158
48
48
  cubevis/bokeh/models/_shared_dict.py,sha256=AWjLMOKVAXWHSF4gcK2RbxF442QlzQ7hMR0oaODCqB0,901
49
- cubevis/bokeh/models/_showable.py,sha256=-X63iKaQgAI37cTB_23dvBgVPUrAq9KfLiKcxB-KCXo,15723
49
+ cubevis/bokeh/models/_showable.py,sha256=uzLf8hhITweJnBB5Sm-XjLb1H-RGYfrSSuWVI1UekUc,18474
50
50
  cubevis/bokeh/models/_tip.py,sha256=yNoUWods0xxva1WOfh5It_Y8hbpVy8RVXUmm8p7a58M,1431
51
51
  cubevis/bokeh/models/_tip_button.py,sha256=mwk1C7BMVlZrAAyQLn45S4Q9GEQfU_wU2MWpO0Gwzj4,1610
52
52
  cubevis/bokeh/sources/__init__.py,sha256=4FsudFuVU4o7VG5OG3K1tiMoxIXcJWNz_K9yzMDE8ls,1581
@@ -57,7 +57,7 @@ cubevis/bokeh/sources/_spectra_data_source.py,sha256=qL1IOjSefWlycaqS4Pz5EHwg-1E
57
57
  cubevis/bokeh/sources/_updatable_data_source.py,sha256=Kib2DPPIA0abqOywzdme98GxI8KBukszbSC5K65wxv0,10961
58
58
  cubevis/bokeh/state/__init__.py,sha256=PZ2-7I5XHkMTc-vguYarYCYSJ1pKyEYnSAFa-n8AuTE,1826
59
59
  cubevis/bokeh/state/_current.py,sha256=owPMQTme5SBYvIVP3Q4y9hpWHPmyhLHsS2O0sCAAqqo,967
60
- cubevis/bokeh/state/_initialize.py,sha256=rdIP8wMHd3RtvnVNKbfpkybUl5ZLKqSyxUiOhq7a7Ss,12483
60
+ cubevis/bokeh/state/_initialize.py,sha256=eX06VU1KyTEyoFiAdPBA_XucCKFEgNImv1qVXfXaIkE,12881
61
61
  cubevis/bokeh/state/_javascript.py,sha256=0n-kVFOpmo11fuOhASh71JAttwOzm9T2vm8KC5m6h1Y,5390
62
62
  cubevis/bokeh/state/_palette.py,sha256=lPLgpKvc23mpNcaVu5nBAGdA_WBUK1HcxFJLu3CTvtg,2463
63
63
  cubevis/bokeh/state/_session.py,sha256=5TK6pyQOUPZNwnyjd_XmkqE_qPNkQyXIKjpFsliBvgk,1761
@@ -106,13 +106,13 @@ cubevis/remote/_local.py,sha256=PcPCFcwttTFZd3O33-5pqDuGKQKK6CA0gz1MTIkTiNI,1032
106
106
  cubevis/remote/_remote_kernel.py,sha256=wfu7ZzKn-oCxZxzDIkC5puBvGf8WbCLYL3CzM56_FNc,2652
107
107
  cubevis/toolbox/__init__.py,sha256=sEN80BX91q_Z2zImDlT8oZ-0o8sE-iH7n3i4S1lmRLo,1450
108
108
  cubevis/toolbox/_app_context.py,sha256=rkjddiE4Ynf2HeyI0Hf8DOUt89bF67-2IlgD1uKSdOI,2908
109
- cubevis/toolbox/_cube.py,sha256=yNVeRFU3ZIM3FeOG4gsy2l6u7gnyqnFlQ6GzQ1fqIg4,308223
109
+ cubevis/toolbox/_cube.py,sha256=ZqprhC7Ps9hGGcd3BLK3zp5wySy2QhnqyAXBkeMxtzY,308257
110
110
  cubevis/toolbox/_interactive_clean_ui.mustache,sha256=IVTcqkxIyw7SzfU92_70dG7bF9UapromDdmeukQ90cg,114113
111
111
  cubevis/toolbox/_interactive_clean_ui.py,sha256=98KnLZnDXqO5xl7Ie7WpirogtKL0a5myHejsC89CVSU,114024
112
112
  cubevis/toolbox/_interactiveclean_wrappers.py,sha256=XqyCGz33CMDhszTxnwZ_3-64GszUK1XYnGKUOxl9sas,5071
113
113
  cubevis/toolbox/_region_list.py,sha256=_1RvnXwqMoaAq8CPy-6IyhabLi_snXqO566onehI2y0,8957
114
114
  cubevis/utils/_ResourceManager.py,sha256=SaaR29etabRiKxmUK-aWvAm4v_OPFJH8CX7bNFm0Lgo,3410
115
- cubevis/utils/__init__.py,sha256=6u9bbkK_KY98qa6VJOGzjz0mwtKblbK63pxZ34OJ4mg,28048
115
+ cubevis/utils/__init__.py,sha256=Xd5GYSBw_hsONqJaXIwi1TZ0hJQ8WsjwWX6Q9V8S4AU,28058
116
116
  cubevis/utils/_browser.py,sha256=rmJ8_wq6XqhXZmVdmWI4t736qB-zd7ZbzfjVdVz40eY,261
117
117
  cubevis/utils/_contextmgrchain.py,sha256=r5SrCBdgQIVH7zXKOmq5oWhDUSeHaZpgsIfWFHvb3cQ,2859
118
118
  cubevis/utils/_conversion.py,sha256=SziCU8sOGtG7djlY766-MeOvnQgvT9C737FEfJ4aYsE,3262
@@ -120,15 +120,15 @@ cubevis/utils/_copydoc.py,sha256=SI9DOUoTNg9M-Y4J1oci2Ba1jebGHsx_pFX24RSNg3o,191
120
120
  cubevis/utils/_docenum.py,sha256=D79BvxwW18DPUlIhBx5DnpZh76pDURC1Hqt1DfS7kG0,877
121
121
  cubevis/utils/_git.py,sha256=fLrwN40zm6fv3SKz3MSwj-wtUa9AslpwPPIYJNLzXik,1120
122
122
  cubevis/utils/_import_protected_module.py,sha256=AIISHPdiSzwgVzLXqHSWSHT-L7lcMWbYrsMlGlTFafE,1482
123
- cubevis/utils/_jupyter.py,sha256=37aNCGO52sOyklBQAR5eaAHkv-5NpmzCXPuTT7Euk0o,4214
123
+ cubevis/utils/_jupyter.py,sha256=7itryScSkcej9ISvgItWaXhBRxCSaZagQYPvWYX_VAg,5256
124
124
  cubevis/utils/_logging.py,sha256=HqyoTib7QSuAUbzicPVMdhFtxWKo-Dv4GgD0AYDDXIY,2348
125
125
  cubevis/utils/_mutual_exclusion.py,sha256=fkVsHPrFfeXdLSoZGw49ObxsTfwAeeJQTAcOCM2LvC8,3879
126
126
  cubevis/utils/_pkgs.py,sha256=mu2CCzndmJZYP81UkFhxveW_CisWLUvagJVolHOEVgM,2294
127
127
  cubevis/utils/_regions.py,sha256=TdAg4ZUUyhg3nFmX9_KLboqmc0LkyOdEW8M1WDR5Udk,1669
128
128
  cubevis/utils/_static.py,sha256=rN-sqXNqQ5R2M3wmPHU1GPP5OTyyWQlUPRuimCrht-g,2347
129
129
  cubevis/utils/_tiles.py,sha256=A9W1X61VOhBMTOKXVajzOIoiV2FBdO5N2SFB9SUpDOo,7336
130
- cubevis/__version__.py,sha256=V8mcjgjAaALTQgu46QC6JsqtVhIuwUw8ouH3h3lkBi8,22
131
- cubevis-1.0.21.dist-info/WHEEL,sha256=B19PGBCYhWaz2p_UjAoRVh767nYQfk14Sn4TpIZ-nfU,87
132
- cubevis-1.0.21.dist-info/METADATA,sha256=CocE5gz6awIhYzmwtQys8x8sn1qM4Wg05D_fAuHELJQ,2632
133
- cubevis-1.0.21.dist-info/licenses/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
134
- cubevis-1.0.21.dist-info/RECORD,,
130
+ cubevis/__version__.py,sha256=ipKUrUZQTYULPss2w4_lq_zOzzw-qCGgjOtgkLfSDAM,22
131
+ cubevis-1.0.26.dist-info/WHEEL,sha256=B19PGBCYhWaz2p_UjAoRVh767nYQfk14Sn4TpIZ-nfU,87
132
+ cubevis-1.0.26.dist-info/METADATA,sha256=M-Nz1skw2jnDx84DLs5rY_tjgQdJHiZuJrNW3xmV9d0,2632
133
+ cubevis-1.0.26.dist-info/licenses/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
134
+ cubevis-1.0.26.dist-info/RECORD,,