mrmd-python 0.3.0__tar.gz → 0.3.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mrmd-python
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Python runtime server implementing the MRMD Runtime Protocol (MRP)
5
5
  Author: mrmd contributors
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mrmd-python"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "Python runtime server implementing the MRMD Runtime Protocol (MRP)"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -95,6 +95,29 @@ class IPythonWorker:
95
95
  python_exe = venv_path / 'bin' / 'python'
96
96
  return str(python_exe) if python_exe.exists() else None
97
97
 
98
+ def _should_use_subprocess(self) -> bool:
99
+ """Check if we should use subprocess for execution (different venv).
100
+
101
+ Returns True if:
102
+ - A venv is configured
103
+ - The venv differs from the current Python's prefix
104
+ - The venv's Python executable exists
105
+ """
106
+ if not self.venv:
107
+ return False
108
+
109
+ # Compare venv path to current Python's prefix
110
+ # Use realpath to handle symlinks
111
+ current_prefix = os.path.realpath(sys.prefix)
112
+ target_venv = os.path.realpath(self.venv)
113
+
114
+ if current_prefix == target_venv:
115
+ return False
116
+
117
+ # Also verify the target Python exists
118
+ python_exe = self._get_venv_python()
119
+ return python_exe is not None
120
+
98
121
  def _ensure_initialized(self):
99
122
  """Lazy initialization of IPython shell."""
100
123
  if self._initialized:
@@ -788,6 +811,10 @@ except Exception as e:
788
811
  self, code: str, store_history: bool = True, exec_id: str | None = None
789
812
  ) -> ExecuteResult:
790
813
  """Execute code and return result (non-streaming)."""
814
+ # Use subprocess execution if venv differs from current Python
815
+ if self._should_use_subprocess():
816
+ return self._execute_subprocess(code, exec_id)
817
+
791
818
  self._ensure_initialized()
792
819
  self._captured_displays = []
793
820
  self._current_exec_id = exec_id
@@ -871,6 +898,10 @@ except Exception as e:
871
898
  Returns:
872
899
  ExecuteResult with final result
873
900
  """
901
+ # Use subprocess execution if venv differs from current Python
902
+ if self._should_use_subprocess():
903
+ return self._execute_subprocess_streaming(code, on_output, exec_id)
904
+
874
905
  self._ensure_initialized()
875
906
  self._captured_displays = []
876
907
  self._current_exec_id = exec_id
File without changes
File without changes
File without changes