maidr 1.5.0__py3-none-any.whl → 1.6.0__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.
maidr/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "1.5.0"
1
+ __version__ = "1.6.0"
2
2
 
3
3
  from .api import close, render, save_html, show, stacked
4
4
  from .core import Maidr
maidr/core/maidr.py CHANGED
@@ -7,6 +7,8 @@ import os
7
7
  import tempfile
8
8
  import uuid
9
9
  import webbrowser
10
+ import subprocess
11
+ from pathlib import Path
10
12
  from typing import Any, Literal, cast
11
13
 
12
14
  import matplotlib.pyplot as plt
@@ -137,7 +139,48 @@ class Maidr:
137
139
  html_file_path = self.save_html(
138
140
  temp_file_path
139
141
  ) # This will use use_iframe=False
140
- webbrowser.open(f"file://{html_file_path}")
142
+ if Environment.is_wsl():
143
+ wsl_distro_name = Environment.get_wsl_distro_name()
144
+
145
+ # Validate that WSL distro name is available
146
+ if not wsl_distro_name:
147
+ raise ValueError(
148
+ "WSL_DISTRO_NAME environment variable is not set or is empty. "
149
+ "Cannot construct WSL file URL. Please ensure you are running in a WSL environment."
150
+ )
151
+
152
+ # Ensure html_file_path is an absolute POSIX path for proper WSL URL construction
153
+ html_file_path = Path(html_file_path).resolve().as_posix()
154
+
155
+ url = f"file://wsl$/{wsl_distro_name}{html_file_path}"
156
+
157
+ # Try to open the file in Windows using explorer.exe with robust path detection
158
+ explorer_path = Environment.find_explorer_path()
159
+ if explorer_path:
160
+ try:
161
+ result = subprocess.run(
162
+ [explorer_path, url],
163
+ capture_output=True,
164
+ text=True,
165
+ timeout=10
166
+ )
167
+
168
+ if result.returncode == 0:
169
+ return
170
+ else:
171
+ # Fall back to webbrowser.open() if explorer.exe fails
172
+ webbrowser.open(url)
173
+
174
+ except subprocess.TimeoutExpired:
175
+ webbrowser.open(url)
176
+ except Exception:
177
+ # Fall back to webbrowser.open() if explorer.exe fails
178
+ webbrowser.open(url)
179
+ else:
180
+ webbrowser.open(url)
181
+
182
+ else:
183
+ webbrowser.open(f"file://{html_file_path}")
141
184
 
142
185
  def _create_html_tag(self, use_iframe: bool = True) -> Tag:
143
186
  """Create the MAIDR HTML using HTML tags."""
maidr/util/environment.py CHANGED
@@ -1,6 +1,8 @@
1
1
  import json
2
2
  import os
3
+ import subprocess
3
4
  import sys
5
+ from typing import Union
4
6
 
5
7
 
6
8
  class Environment:
@@ -99,6 +101,93 @@ class Environment:
99
101
  return False
100
102
  except ImportError:
101
103
  return False
104
+ @staticmethod
105
+ def is_wsl() -> bool:
106
+ """
107
+ Check if the current environment is WSL (Windows Subsystem for Linux).
108
+
109
+ This method detects WSL environments by reading the `/proc/version` file
110
+ and checking for 'microsoft' or 'wsl' keywords in the version string.
111
+ WSL environments typically contain these identifiers in their kernel version.
112
+
113
+ Returns
114
+ -------
115
+ bool
116
+ True if the environment is WSL, False otherwise.
117
+
118
+ Examples
119
+ --------
120
+ >>> from maidr.util.environment import Environment
121
+ >>> Environment.is_wsl()
122
+ False # When not in WSL
123
+ """
124
+ try:
125
+ with open('/proc/version', 'r') as f:
126
+ version_info = f.read().lower()
127
+ if 'microsoft' in version_info or 'wsl' in version_info:
128
+ return True
129
+ except FileNotFoundError:
130
+ pass
131
+ return False
132
+
133
+ @staticmethod
134
+ def get_wsl_distro_name() -> str:
135
+ """
136
+ Get the WSL distribution name from environment variables.
137
+
138
+ This method retrieves the WSL distribution name from the `WSL_DISTRO_NAME`
139
+ environment variable, which is automatically set by WSL when running
140
+ in a WSL environment.
141
+
142
+ Returns
143
+ -------
144
+ str
145
+ The WSL distribution name (e.g., 'Ubuntu-20.04', 'Debian') if set,
146
+ otherwise an empty string.
147
+
148
+ Examples
149
+ --------
150
+ >>> from maidr.util.environment import Environment
151
+ >>> Environment.get_wsl_distro_name()
152
+ '' # When not in WSL or WSL_DISTRO_NAME not set
153
+ """
154
+ return os.environ.get('WSL_DISTRO_NAME', '')
155
+
156
+ @staticmethod
157
+ def find_explorer_path() -> Union[str, None]:
158
+ """
159
+ Find the correct path to explorer.exe in WSL environment.
160
+
161
+ This method checks if explorer.exe is available in the PATH
162
+ and returns the path if found.
163
+
164
+ Returns
165
+ -------
166
+ str | None
167
+ The path to explorer.exe if found, None otherwise.
168
+
169
+ Examples
170
+ --------
171
+ >>> from maidr.util.environment import Environment
172
+ >>> Environment.find_explorer_path()
173
+ '/mnt/c/Windows/explorer.exe' # When found
174
+ """
175
+ # Check if explorer.exe is in PATH
176
+ try:
177
+ result = subprocess.run(
178
+ ['which', 'explorer.exe'],
179
+ capture_output=True,
180
+ text=True,
181
+ timeout=5
182
+ )
183
+ if result.returncode == 0:
184
+ return result.stdout.strip()
185
+ except Exception:
186
+ pass
187
+
188
+ return None
189
+
190
+
102
191
 
103
192
  @staticmethod
104
193
  def get_renderer() -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maidr
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: Multimodal Access and Interactive Data Representations
5
5
  Project-URL: Homepage, https://xability.github.io/py-maidr
6
6
  Project-URL: Repository, https://github.com/xability/py-maidr
@@ -1,9 +1,9 @@
1
- maidr/__init__.py,sha256=8Klcr4EJvP1oYVdBry2bxII4HA4tbuzlTlb5x_295H4,415
1
+ maidr/__init__.py,sha256=bvyrTCLC6rRb_Iu5wCMtnDYCY0tbaZ--c21hFuNMICE,415
2
2
  maidr/api.py,sha256=gRNLXqUWpFGdD-I7Nu6J0_LeEni9KRAr0TBHwHaDAsc,1928
3
3
  maidr/core/__init__.py,sha256=WgxLpSEYMc4k3OyEOf1shOxfEq0ASzppEIZYmE91ThQ,25
4
4
  maidr/core/context_manager.py,sha256=6cT7ZGOApSpC-SLD2XZWWU_H08i-nfv-JUlzXOtvWYw,3374
5
5
  maidr/core/figure_manager.py,sha256=jXs-Prkeru1Pahj21hjh8BAwXM9ZFUZ3GFfKUfIRX_M,4117
6
- maidr/core/maidr.py,sha256=xy-Re6PjzotjSv1J6L2jT5IjsAm3XQo9OJl9xICAuRA,14115
6
+ maidr/core/maidr.py,sha256=1f3H6E2gXTWTdO_vNmiGmPq1dDn-Q96wjirkosxIgPg,15802
7
7
  maidr/core/enum/__init__.py,sha256=9ee78L0dlxEx4ulUGVlD-J23UcUZmrGu0rXms54up3c,93
8
8
  maidr/core/enum/library.py,sha256=e8ujT_L-McJWfoVJd1ty9K_2bwITnf1j0GPLsnAcHes,104
9
9
  maidr/core/enum/maidr_key.py,sha256=ljG0omqzd8K8Yk213N7i7PXGvG-IOlnE5v7o6RoGJzc,795
@@ -41,7 +41,7 @@ maidr/patch/regplot.py,sha256=k86ekd0E4XJ_L1u85zObuDnxuXlM83z7tKtyXRTj2rI,3240
41
41
  maidr/patch/scatterplot.py,sha256=kln6zZwjVsdQzICalo-RnBOJrx1BnIB2xYUwItHvSNY,525
42
42
  maidr/util/__init__.py,sha256=eRJZfRpDX-n7UoV3JXw_9Lbfu_qNl_D0W1UTvLL-Iv4,81
43
43
  maidr/util/dedup_utils.py,sha256=RpgPL5p-3oULUHaTCZJaQKhPHfyPkvBLHMt8lAGpJ5A,438
44
- maidr/util/environment.py,sha256=ZPoXXZsqiDY9jdnxPhgP2KTSTUkoGWek0UJ8uR6F7RQ,6747
44
+ maidr/util/environment.py,sha256=SSfxzjmY2ZVA98B-IVql8n9AX3d6h2f7_R4t3_53dYI,9452
45
45
  maidr/util/mplfinance_utils.py,sha256=aWNRkNS2IAF4YYEF9w7CcmcKWMGg3KkYJAv0xL8KcyY,14417
46
46
  maidr/util/plot_detection.py,sha256=bgLHoDcHSRwOiyKzUK3EqGwdAIhF44ocHW5ox6xYGZw,3883
47
47
  maidr/util/regression_line_utils.py,sha256=yFKr-H0whT_su2YVZwNksBLp5EC5s77sr6HUFgNcsyY,2329
@@ -51,7 +51,7 @@ maidr/util/mixin/extractor_mixin.py,sha256=oHtwpmS5kARvaLrSO3DKTPQxyFUw9nOcKN7rz
51
51
  maidr/util/mixin/merger_mixin.py,sha256=V0qLw_6DUB7X6CQ3BCMpsCQX_ZuwAhoSTm_E4xAJFKM,712
52
52
  maidr/widget/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
53
  maidr/widget/shiny.py,sha256=wrrw2KAIpE_A6CNQGBtNHauR1DjenA_n47qlFXX9_rk,745
54
- maidr-1.5.0.dist-info/METADATA,sha256=JoS1wyXJ3T7pl0YebNOqQ_N1PbLgpzqDeDUyGJiqYz8,3193
55
- maidr-1.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
56
- maidr-1.5.0.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
57
- maidr-1.5.0.dist-info/RECORD,,
54
+ maidr-1.6.0.dist-info/METADATA,sha256=e3l2lyk61dpyniYkOGEIO2Ycyt10LWgPfM-z6OR8fYU,3193
55
+ maidr-1.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
56
+ maidr-1.6.0.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
57
+ maidr-1.6.0.dist-info/RECORD,,
File without changes