cua-computer 0.4.6__py3-none-any.whl → 0.4.7__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.
computer/computer.py CHANGED
@@ -794,19 +794,33 @@ class Computer:
794
794
  Tuple of (stdout, stderr) from the installation command
795
795
  """
796
796
  requirements = requirements or []
797
-
798
- # Create virtual environment if it doesn't exist
799
- venv_path = f"~/.venvs/{venv_name}"
800
- create_cmd = f"mkdir -p ~/.venvs && python3 -m venv {venv_path}"
801
-
802
- # Check if venv exists, if not create it
803
- check_cmd = f"test -d {venv_path} || ({create_cmd})"
804
- _ = await self.interface.run_command(check_cmd)
805
-
806
- # Install packages
807
- requirements_str = " ".join(requirements)
808
- install_cmd = f". {venv_path}/bin/activate && pip install {requirements_str}"
809
- return await self.interface.run_command(install_cmd)
797
+ # Windows vs POSIX handling
798
+ if self.os_type == "windows":
799
+ # Use %USERPROFILE% for home directory and cmd.exe semantics
800
+ venv_path = f"%USERPROFILE%\\.venvs\\{venv_name}"
801
+ ensure_dir_cmd = "if not exist \"%USERPROFILE%\\.venvs\" mkdir \"%USERPROFILE%\\.venvs\""
802
+ create_cmd = f"if not exist \"{venv_path}\" python -m venv \"{venv_path}\""
803
+ requirements_str = " ".join(requirements)
804
+ # Activate via activate.bat and install
805
+ install_cmd = f"call \"{venv_path}\\Scripts\\activate.bat\" && pip install {requirements_str}" if requirements_str else f"echo No requirements to install"
806
+ await self.interface.run_command(ensure_dir_cmd)
807
+ await self.interface.run_command(create_cmd)
808
+ return await self.interface.run_command(install_cmd)
809
+ else:
810
+ # POSIX (macOS/Linux)
811
+ venv_path = f"$HOME/.venvs/{venv_name}"
812
+ create_cmd = f"mkdir -p \"$HOME/.venvs\" && python3 -m venv \"{venv_path}\""
813
+ # Check if venv exists, if not create it
814
+ check_cmd = f"test -d \"{venv_path}\" || ({create_cmd})"
815
+ _ = await self.interface.run_command(check_cmd)
816
+ # Install packages
817
+ requirements_str = " ".join(requirements)
818
+ install_cmd = (
819
+ f". \"{venv_path}/bin/activate\" && pip install {requirements_str}"
820
+ if requirements_str
821
+ else "echo No requirements to install"
822
+ )
823
+ return await self.interface.run_command(install_cmd)
810
824
 
811
825
  async def venv_cmd(self, venv_name: str, command: str):
812
826
  """Execute a shell command in a virtual environment.
@@ -818,18 +832,30 @@ class Computer:
818
832
  Returns:
819
833
  Tuple of (stdout, stderr) from the command execution
820
834
  """
821
- venv_path = f"~/.venvs/{venv_name}"
822
-
823
- # Check if virtual environment exists
824
- check_cmd = f"test -d {venv_path}"
825
- result = await self.interface.run_command(check_cmd)
826
-
827
- if result.stderr or "test:" in result.stdout: # venv doesn't exist
828
- return "", f"Virtual environment '{venv_name}' does not exist. Create it first using venv_install."
829
-
830
- # Activate virtual environment and run command
831
- full_command = f". {venv_path}/bin/activate && {command}"
832
- return await self.interface.run_command(full_command)
835
+ if self.os_type == "windows":
836
+ # Windows (cmd.exe)
837
+ venv_path = f"%USERPROFILE%\\.venvs\\{venv_name}"
838
+ # Check existence and signal if missing
839
+ check_cmd = f"if not exist \"{venv_path}\" (echo VENV_NOT_FOUND) else (echo VENV_FOUND)"
840
+ result = await self.interface.run_command(check_cmd)
841
+ if "VENV_NOT_FOUND" in getattr(result, "stdout", ""):
842
+ # Auto-create the venv with no requirements
843
+ await self.venv_install(venv_name, [])
844
+ # Activate and run the command
845
+ full_command = f"call \"{venv_path}\\Scripts\\activate.bat\" && {command}"
846
+ return await self.interface.run_command(full_command)
847
+ else:
848
+ # POSIX (macOS/Linux)
849
+ venv_path = f"$HOME/.venvs/{venv_name}"
850
+ # Check if virtual environment exists
851
+ check_cmd = f"test -d \"{venv_path}\""
852
+ result = await self.interface.run_command(check_cmd)
853
+ if result.stderr or "test:" in result.stdout: # venv doesn't exist
854
+ # Auto-create the venv with no requirements
855
+ await self.venv_install(venv_name, [])
856
+ # Activate virtual environment and run command
857
+ full_command = f". \"{venv_path}/bin/activate\" && {command}"
858
+ return await self.interface.run_command(full_command)
833
859
 
834
860
  async def venv_exec(self, venv_name: str, python_func, *args, **kwargs):
835
861
  """Execute Python function in a virtual environment using source code extraction.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cua-computer
3
- Version: 0.4.6
3
+ Version: 0.4.7
4
4
  Summary: Computer-Use Interface (CUI) framework powering Cua
5
5
  Author-Email: TryCua <gh@trycua.com>
6
6
  Requires-Python: >=3.11
@@ -1,5 +1,5 @@
1
1
  computer/__init__.py,sha256=HG8dhCmSPjuQ4G-NGAoiXEhzhO37kwrHHmyboNhGWOA,1159
2
- computer/computer.py,sha256=TBryDea-XM76PdVv4DH85MTSaOOTYHC8BOPrqeKRkeY,42630
2
+ computer/computer.py,sha256=SG75oF1jiTt7Kkaf60t2uzx1hOc6hour28CyydQ-01E,44435
3
3
  computer/diorama_computer.py,sha256=3JaXKpcSi_OAVXtwlmNwQgrcnvqP1AxdlKEQ0XRJ0aQ,8569
4
4
  computer/helpers.py,sha256=iHkO2WhuCLc15g67kfMnpQWxfNRlz2YeJNEvYaL9jlM,1826
5
5
  computer/interface/__init__.py,sha256=xQvYjq5PMn9ZJOmRR5mWtONTl_0HVd8ACvW6AQnzDdw,262
@@ -32,7 +32,7 @@ computer/ui/__main__.py,sha256=Jwy2oC_mGZLN0fX7WLqpjaQkbXMeM3ISrUc8WSRUG0c,284
32
32
  computer/ui/gradio/__init__.py,sha256=5_KimixM48-X74FCsLw7LbSt39MQfUMEL8-M9amK3Cw,117
33
33
  computer/ui/gradio/app.py,sha256=_V6FI-g0GJGMEk-C2iPFtxPO1Gn0juCaeCrWsBtjC4E,70395
34
34
  computer/utils.py,sha256=zY50NXB7r51GNLQ6l7lhG_qv0_ufpQ8n0-SDhCei8m4,2838
35
- cua_computer-0.4.6.dist-info/METADATA,sha256=MUzK45YA8YvzCdfDOgIt8Ko0qYAp7_uPYxz19N2hB2s,3776
36
- cua_computer-0.4.6.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
37
- cua_computer-0.4.6.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
38
- cua_computer-0.4.6.dist-info/RECORD,,
35
+ cua_computer-0.4.7.dist-info/METADATA,sha256=SWQCKzu495JnTmbXHCk_cvktFnYfP2touK6ZPSw7YmQ,3776
36
+ cua_computer-0.4.7.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
37
+ cua_computer-0.4.7.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
38
+ cua_computer-0.4.7.dist-info/RECORD,,