mirror of
https://github.com/trycua/computer.git
synced 2026-01-05 21:09:58 -06:00
Merge pull request #460 from trycua/chore/refactor-build-uv-script
Switch to uv for package management
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
# Dev Container Setup
|
||||
|
||||
This repository includes a Dev Container configuration that simplifies the development setup to just 3 steps:
|
||||
|
||||
## Quick Start
|
||||
|
||||

|
||||
|
||||
1. **Install the Dev Containers extension ([VS Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) or [WindSurf](https://docs.windsurf.com/windsurf/advanced#dev-containers-beta))**
|
||||
2. **Open the repository in the Dev Container:**
|
||||
- Press `Ctrl+Shift+P` (or `⌘+Shift+P` on macOS)
|
||||
- Select `Dev Containers: Clone Repository in Container Volume...` and paste the repository URL: `https://github.com/trycua/cua.git` (if not cloned) or `Dev Containers: Open Folder in Container...` (if git cloned).
|
||||
> **Note**: On WindSurf, the post install hook might not run automatically. If so, run `/bin/bash .devcontainer/post-install.sh` manually.
|
||||
3. **Open the VS Code workspace:** Once the post-install.sh is done running, open the `.vscode/py.code-workspace` workspace and press 
|
||||
.
|
||||
4. **Run the Agent UI example:** Click 
|
||||
to start the Gradio UI. If prompted to install **debugpy (Python Debugger)** to enable remote debugging, select 'Yes' to proceed.
|
||||
5. **Access the Gradio UI:** The Gradio UI will be available at `http://localhost:7860` and will automatically forward to your host machine.
|
||||
|
||||
## What's Included
|
||||
|
||||
The dev container automatically:
|
||||
|
||||
- ✅ Sets up Python 3.11 environment
|
||||
- ✅ Installs all system dependencies (build tools, OpenGL, etc.)
|
||||
- ✅ Configures Python paths for all packages
|
||||
- ✅ Installs Python extensions (Black, Ruff, Pylance)
|
||||
- ✅ Forwards port 7860 for the Gradio web UI
|
||||
- ✅ Mounts your source code for live editing
|
||||
- ✅ Creates the required `.env.local` file
|
||||
|
||||
## Running Examples
|
||||
|
||||
After the container is built, you can run examples directly:
|
||||
|
||||
```bash
|
||||
# Run the agent UI (Gradio web interface)
|
||||
python examples/agent_ui_examples.py
|
||||
|
||||
# Run computer examples
|
||||
python examples/computer_examples.py
|
||||
|
||||
# Run computer UI examples
|
||||
python examples/computer_ui_examples.py
|
||||
```
|
||||
|
||||
The Gradio UI will be available at `http://localhost:7860` and will automatically forward to your host machine.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
You'll need to add your API keys to `.env.local`:
|
||||
|
||||
```bash
|
||||
# Required for Anthropic provider
|
||||
ANTHROPIC_API_KEY=your_anthropic_key_here
|
||||
|
||||
# Required for OpenAI provider
|
||||
OPENAI_API_KEY=your_openai_key_here
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- The container connects to `host.docker.internal:7777` for Lume server communication
|
||||
- All Python packages are pre-installed and configured
|
||||
- Source code changes are reflected immediately (no rebuild needed)
|
||||
- The container uses the same Dockerfile as the regular Docker development environment
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "Cua - OSS",
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile"
|
||||
},
|
||||
"containerEnv": {
|
||||
"DISPLAY": "",
|
||||
"PYLUME_HOST": "host.docker.internal"
|
||||
},
|
||||
"forwardPorts": [7860],
|
||||
"portsAttributes": {
|
||||
"7860": {
|
||||
"label": "Cua web client (Gradio)",
|
||||
"onAutoForward": "silent"
|
||||
}
|
||||
},
|
||||
"postCreateCommand": "/bin/bash .devcontainer/post-install.sh"
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
WORKSPACE="/workspaces/cua"
|
||||
|
||||
# Setup .env.local
|
||||
echo "PYTHON_BIN=python" > /workspaces/cua/.env.local
|
||||
|
||||
# Run /scripts/build.sh
|
||||
./scripts/build.sh
|
||||
|
||||
# ---
|
||||
# Build is complete. Show user a clear message to open the workspace manually.
|
||||
# ---
|
||||
|
||||
cat << 'EOM'
|
||||
|
||||
============================================
|
||||
🚀 Build complete!
|
||||
|
||||
👉 Next steps:
|
||||
|
||||
1. Open '.vscode/py.code-workspace'
|
||||
2. Press 'Open Workspace'
|
||||
|
||||
Happy coding!
|
||||
============================================
|
||||
|
||||
EOM
|
||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"python-envs.pythonProjects": []
|
||||
"python-envs.pythonProjects": [],
|
||||
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
|
||||
}
|
||||
@@ -35,12 +35,12 @@ We follow strict code formatting guidelines to ensure consistency across the cod
|
||||
3. **Run Formatting Tools**: Always run the formatting tools before submitting a PR:
|
||||
```bash
|
||||
# For Python code
|
||||
pdm run black .
|
||||
pdm run ruff check --fix .
|
||||
uv run black .
|
||||
uv run ruff check --fix .
|
||||
```
|
||||
4. **Validate Your Code**: Ensure your code passes all checks:
|
||||
```bash
|
||||
pdm run mypy .
|
||||
uv run mypy .
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
111
Development.md
111
Development.md
@@ -10,9 +10,8 @@ The project is organized as a monorepo with these main packages:
|
||||
- `libs/som/` - Set-of-Mark parser
|
||||
- `libs/computer-server/` - Server component for VM
|
||||
- `libs/lume/` - Lume CLI
|
||||
- `libs/pylume/` - Python bindings for Lume
|
||||
|
||||
Each package has its own virtual environment and dependencies, managed through PDM.
|
||||
These packages are part of a uv workspace which manages a shared virtual environment and dependencies.
|
||||
|
||||
## Local Development Setup
|
||||
|
||||
@@ -62,39 +61,33 @@ Refer to the [Lume README](./libs/lume/Development.md) for instructions on how t
|
||||
|
||||
## Python Development
|
||||
|
||||
There are two ways to install Lume:
|
||||
### Setup
|
||||
|
||||
### Run the build script
|
||||
|
||||
Run the build script to set up all packages:
|
||||
Install all of workspace dependencies with a single command:
|
||||
|
||||
```bash
|
||||
./scripts/build.sh
|
||||
uv sync
|
||||
```
|
||||
|
||||
The build script creates a shared virtual environment for all packages. The workspace configuration automatically handles import paths with the correct Python path settings.
|
||||
This installs all dependencies in the virtual environment `.venv`.
|
||||
|
||||
This will:
|
||||
Each Cua package is installed in editable mode, which means changes to the source code are immediately reflected in the installed package.
|
||||
|
||||
- Create a virtual environment for the project
|
||||
- Install all packages in development mode
|
||||
- Set up the correct Python path
|
||||
- Install development tools
|
||||
The `.venv` environment is also configured as the default VS Code Python interpreter in `.vscode/settings.json`.
|
||||
|
||||
### Install with PDM
|
||||
### Running Python Scripts
|
||||
|
||||
If PDM is not already installed, you can follow the installation instructions [here](https://pdm-project.org/en/latest/#installation).
|
||||
To run Python scripts in the workspace, use the `uv run` command:
|
||||
|
||||
To install with PDM, simply run:
|
||||
|
||||
```console
|
||||
pdm install -G:all
|
||||
```bash
|
||||
uv run python examples/agent_examples.py
|
||||
```
|
||||
|
||||
This installs all the dependencies for development, testing, and building the docs. If you'd only like development dependencies, you can run:
|
||||
Or activate the virtual environment manually:
|
||||
|
||||
```console
|
||||
pdm install -d
|
||||
```bash
|
||||
source .venv/bin/activate
|
||||
python examples/agent_examples.py
|
||||
```
|
||||
|
||||
## Running Examples
|
||||
@@ -114,68 +107,6 @@ The workspace also includes compound launch configurations:
|
||||
|
||||
- "Run Computer Examples + Server" - Runs both the Computer Examples and Server simultaneously
|
||||
|
||||
## Docker Development Environment
|
||||
|
||||
As an alternative to installing directly on your host machine, you can use Docker for development. This approach has several advantages:
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Docker installed on your machine
|
||||
- Lume server running on your host (port 7777): `lume serve`
|
||||
|
||||
### Setup and Usage
|
||||
|
||||
1. Build the development Docker image:
|
||||
|
||||
```bash
|
||||
./scripts/run-docker-dev.sh build
|
||||
```
|
||||
|
||||
2. Run an example in the container:
|
||||
|
||||
```bash
|
||||
./scripts/run-docker-dev.sh run computer_examples.py
|
||||
```
|
||||
|
||||
3. Get an interactive shell in the container:
|
||||
|
||||
```bash
|
||||
./scripts/run-docker-dev.sh run --interactive
|
||||
```
|
||||
|
||||
4. Stop any running containers:
|
||||
|
||||
```bash
|
||||
./scripts/run-docker-dev.sh stop
|
||||
```
|
||||
|
||||
### How it Works
|
||||
|
||||
The Docker development environment:
|
||||
|
||||
- Installs all required Python dependencies in the container
|
||||
- Mounts your source code from the host at runtime
|
||||
- Automatically configures the connection to use host.docker.internal:7777 for accessing the Lume server on your host machine
|
||||
- Preserves your code changes without requiring rebuilds (source code is mounted as a volume)
|
||||
|
||||
> **Note**: The Docker container doesn't include the macOS-specific Lume executable. Instead, it connects to the Lume server running on your host machine via host.docker.internal:7777. Make sure to start the Lume server on your host before running examples in the container.
|
||||
|
||||
## Cleanup and Reset
|
||||
|
||||
If you need to clean up the environment (non-docker) and start fresh:
|
||||
|
||||
```bash
|
||||
./scripts/cleanup.sh
|
||||
```
|
||||
|
||||
This will:
|
||||
|
||||
- Remove all virtual environments
|
||||
- Clean Python cache files and directories
|
||||
- Remove build artifacts
|
||||
- Clean PDM-related files
|
||||
- Reset environment configurations
|
||||
|
||||
## Code Formatting Standards
|
||||
|
||||
The Cua project follows strict code formatting standards to ensure consistency across all packages.
|
||||
@@ -256,13 +187,13 @@ To manually format code:
|
||||
|
||||
```bash
|
||||
# Format all Python files using Black
|
||||
pdm run black .
|
||||
uv run black .
|
||||
|
||||
# Run Ruff linter with auto-fix
|
||||
pdm run ruff check --fix .
|
||||
uv run ruff check --fix .
|
||||
|
||||
# Run type checking with MyPy
|
||||
pdm run mypy .
|
||||
uv run mypy .
|
||||
```
|
||||
|
||||
#### Pre-commit Validation
|
||||
@@ -271,9 +202,9 @@ Before submitting a pull request, ensure your code passes all formatting checks:
|
||||
|
||||
```bash
|
||||
# Run all checks
|
||||
pdm run black --check .
|
||||
pdm run ruff check .
|
||||
pdm run mypy .
|
||||
uv run black --check .
|
||||
uv run ruff check .
|
||||
uv run mypy .
|
||||
```
|
||||
|
||||
### Swift Code (Lume)
|
||||
|
||||
@@ -49,7 +49,7 @@ glm45v-hf = [
|
||||
opencua-hf = [
|
||||
"accelerate",
|
||||
"torch",
|
||||
"transformers==4.53.0",
|
||||
"transformers>=4.53.0",
|
||||
"tiktoken>=0.11.0",
|
||||
"blobfile>=3.0.0"
|
||||
]
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
[build-system]
|
||||
build-backend = "pdm.backend"
|
||||
requires = ["pdm-backend"]
|
||||
|
||||
[project]
|
||||
authors = [{ name = "TryCua", email = "gh@trycua.com" }]
|
||||
dependencies = [
|
||||
@@ -19,21 +15,13 @@ version = "0.1.0"
|
||||
repository = "https://github.com/trycua/cua"
|
||||
|
||||
[dependency-groups]
|
||||
dev = []
|
||||
examples = []
|
||||
|
||||
[tool.pdm]
|
||||
distribution = false
|
||||
|
||||
[tool.pdm.dev-dependencies]
|
||||
dev = [
|
||||
"-e core @ file:///${PROJECT_ROOT}/libs/python/core",
|
||||
"-e agent @ file:///${PROJECT_ROOT}/libs/python/agent",
|
||||
"-e computer @ file:///${PROJECT_ROOT}/libs/python/computer",
|
||||
"-e computer-server @ file:///${PROJECT_ROOT}/libs/python/computer-server",
|
||||
"-e cua-som @ file:///${PROJECT_ROOT}/libs/python/som",
|
||||
"-e mcp-server @ file:///${PROJECT_ROOT}/libs/python/mcp-server",
|
||||
"-e pylume @ file:///${PROJECT_ROOT}/libs/python/pylume",
|
||||
"cua-core",
|
||||
"cua-agent",
|
||||
"cua-computer",
|
||||
"cua-computer-server",
|
||||
"cua-som",
|
||||
"cua-mcp-server",
|
||||
"black>=23.0.0",
|
||||
"ipykernel>=6.29.5",
|
||||
"jedi>=0.19.2",
|
||||
@@ -41,9 +29,12 @@ dev = [
|
||||
"mypy>=1.10.0",
|
||||
"ruff>=0.9.2",
|
||||
"types-requests>=2.31.0",
|
||||
"hud-python[agent]==0.4.52"
|
||||
"hud-python[agent]==0.4.52",
|
||||
]
|
||||
docs = [
|
||||
"mkdocs-material>=9.2.0",
|
||||
"mkdocs>=1.5.0",
|
||||
]
|
||||
docs = ["mkdocs-material>=9.2.0", "mkdocs>=1.5.0"]
|
||||
test = [
|
||||
"aioresponses>=0.7.4",
|
||||
"pytest-asyncio>=0.21.1",
|
||||
@@ -52,9 +43,28 @@ test = [
|
||||
"pytest-xdist>=3.6.1",
|
||||
"pytest>=8.0.0",
|
||||
]
|
||||
examples = []
|
||||
|
||||
[tool.pdm.resolution]
|
||||
respect-source-order = true
|
||||
[tool.uv]
|
||||
package = false
|
||||
|
||||
[tool.uv.workspace]
|
||||
members = [
|
||||
"libs/python/agent",
|
||||
"libs/python/core",
|
||||
"libs/python/computer",
|
||||
"libs/python/computer-server",
|
||||
"libs/python/som",
|
||||
"libs/python/mcp-server",
|
||||
]
|
||||
|
||||
[tool.uv.sources]
|
||||
cua-agent = { workspace = true }
|
||||
cua-core = { workspace = true }
|
||||
cua-computer = { workspace = true }
|
||||
cua-computer-server = { workspace = true }
|
||||
cua-som = { workspace = true }
|
||||
cua-mcp-server = { workspace = true }
|
||||
|
||||
[tool.black]
|
||||
line-length = 100
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print step information
|
||||
print_step() {
|
||||
echo -e "${BLUE}==> $1${NC}"
|
||||
}
|
||||
|
||||
# Function to print success message
|
||||
print_success() {
|
||||
echo -e "${GREEN}==> Success: $1${NC}"
|
||||
}
|
||||
|
||||
# Function to print error message
|
||||
print_error() {
|
||||
echo -e "${RED}==> Error: $1${NC}" >&2
|
||||
}
|
||||
|
||||
# Function to print warning message
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}==> Warning: $1${NC}"
|
||||
}
|
||||
|
||||
# Function to check if UV is installed
|
||||
check_uv() {
|
||||
if command -v uv &> /dev/null; then
|
||||
print_success "UV is already installed"
|
||||
uv --version
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to install UV
|
||||
install_uv() {
|
||||
print_step "UV not found. Installing UV..."
|
||||
|
||||
# Detect OS
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
print_step "Installing UV for Unix-like system..."
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
|
||||
# Add UV to PATH for current session
|
||||
export PATH="$HOME/.cargo/bin:$PATH"
|
||||
|
||||
# Check if installation was successful
|
||||
if command -v uv &> /dev/null; then
|
||||
print_success "UV installed successfully"
|
||||
uv --version
|
||||
else
|
||||
print_error "UV installation failed"
|
||||
print_step "Please restart your terminal and try again, or install manually:"
|
||||
echo " curl -LsSf https://astral.sh/uv/install.sh | sh"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
|
||||
print_error "For Windows, please use PowerShell and run:"
|
||||
echo " powershell -ExecutionPolicy ByPass -c \"irm https://astral.sh/uv/install.ps1 | iex\""
|
||||
exit 1
|
||||
else
|
||||
print_error "Unsupported operating system: $OSTYPE"
|
||||
print_step "Please install UV manually from: https://docs.astral.sh/uv/getting-started/installation/"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Get the script's directory
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PROJECT_ROOT="$( cd "${SCRIPT_DIR}/.." && pwd )"
|
||||
|
||||
# Change to project root
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Check if UV is installed, install if not
|
||||
if ! check_uv; then
|
||||
install_uv
|
||||
fi
|
||||
|
||||
# Load environment variables from .env.local
|
||||
if [ -f .env.local ]; then
|
||||
print_step "Loading environment variables from .env.local..."
|
||||
set -a
|
||||
source .env.local
|
||||
set +a
|
||||
print_success "Environment variables loaded"
|
||||
else
|
||||
print_error ".env.local file not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clean up existing environments and cache
|
||||
print_step "Cleaning up existing environments..."
|
||||
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
||||
find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
|
||||
find . -type d -name "dist" -exec rm -rf {} + 2>/dev/null || true
|
||||
find . -type d -name ".venv" -exec rm -rf {} + 2>/dev/null || true
|
||||
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
|
||||
print_success "Environment cleanup complete"
|
||||
|
||||
# Install Python 3.12 using UV
|
||||
print_step "Installing Python 3.12 using UV..."
|
||||
uv python install 3.12
|
||||
print_success "Python 3.12 installed"
|
||||
|
||||
# Create virtual environment using UV
|
||||
print_step "Creating virtual environment with UV..."
|
||||
uv venv .venv --python 3.12
|
||||
print_success "Virtual environment created"
|
||||
|
||||
# Activate virtual environment
|
||||
print_step "Activating virtual environment..."
|
||||
source .venv/bin/activate
|
||||
print_success "Virtual environment activated"
|
||||
|
||||
# Function to install a package and its dependencies using UV
|
||||
install_package() {
|
||||
local package_dir=$1
|
||||
local package_name=$2
|
||||
local extras=$3
|
||||
print_step "Installing ${package_name} with UV..."
|
||||
cd "$package_dir"
|
||||
|
||||
if [ -f "pyproject.toml" ]; then
|
||||
if [ -n "$extras" ]; then
|
||||
uv pip install -e ".[${extras}]"
|
||||
else
|
||||
uv pip install -e .
|
||||
fi
|
||||
else
|
||||
print_error "No pyproject.toml found in ${package_dir}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
}
|
||||
|
||||
# Install packages in order of dependency
|
||||
print_step "Installing packages in development mode with UV..."
|
||||
|
||||
# Install core first (base package with telemetry support)
|
||||
install_package "libs/python/core" "core"
|
||||
|
||||
# Install pylume (base dependency)
|
||||
install_package "libs/python/pylume" "pylume"
|
||||
|
||||
# Install computer with all its dependencies and extras
|
||||
install_package "libs/python/computer" "computer" "all"
|
||||
|
||||
# Install omniparser
|
||||
install_package "libs/python/som" "som"
|
||||
|
||||
# Install agent with all its dependencies and extras
|
||||
install_package "libs/python/agent" "agent" "all"
|
||||
|
||||
# Install computer-server
|
||||
install_package "libs/python/computer-server" "computer-server"
|
||||
|
||||
# Install mcp-server
|
||||
install_package "libs/python/mcp-server" "mcp-server"
|
||||
|
||||
# Install development tools from root project
|
||||
print_step "Installing development dependencies with UV..."
|
||||
uv pip install -e ".[dev,test,docs]"
|
||||
|
||||
# Create a .env file for VS Code to use the virtual environment
|
||||
print_step "Creating .env file for VS Code..."
|
||||
echo "PYTHONPATH=${PROJECT_ROOT}/libs/python/core:${PROJECT_ROOT}/libs/python/computer:${PROJECT_ROOT}/libs/python/agent:${PROJECT_ROOT}/libs/python/som:${PROJECT_ROOT}/libs/python/pylume:${PROJECT_ROOT}/libs/python/computer-server:${PROJECT_ROOT}/libs/python/mcp-server" > .env
|
||||
|
||||
print_success "All packages installed successfully with UV!"
|
||||
print_step "Your virtual environment is ready. To activate it:"
|
||||
echo " source .venv/bin/activate"
|
||||
print_step "UV provides fast dependency resolution and installation."
|
||||
print_step "You can also use 'uv run' to run commands in the virtual environment without activation."
|
||||
@@ -1,157 +0,0 @@
|
||||
# PowerShell Build Script for CUA
|
||||
# Exit on error
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Colors for output
|
||||
$RED = "Red"
|
||||
$GREEN = "Green"
|
||||
$BLUE = "Blue"
|
||||
|
||||
# Function to print step information
|
||||
function Print-Step {
|
||||
param([string]$Message)
|
||||
Write-Host "==> $Message" -ForegroundColor $BLUE
|
||||
}
|
||||
|
||||
# Function to print success message
|
||||
function Print-Success {
|
||||
param([string]$Message)
|
||||
Write-Host "==> Success: $Message" -ForegroundColor $GREEN
|
||||
}
|
||||
|
||||
# Function to print error message
|
||||
function Print-Error {
|
||||
param([string]$Message)
|
||||
Write-Host "==> Error: $Message" -ForegroundColor $RED
|
||||
}
|
||||
|
||||
# Get the script's directory and project root
|
||||
$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$PROJECT_ROOT = Split-Path -Parent $SCRIPT_DIR
|
||||
|
||||
# Change to project root
|
||||
Set-Location $PROJECT_ROOT
|
||||
|
||||
# Load environment variables from .env.local
|
||||
if (Test-Path ".env.local") {
|
||||
Print-Step "Loading environment variables from .env.local..."
|
||||
Get-Content ".env.local" | ForEach-Object {
|
||||
if ($_ -match "^([^#][^=]*?)=(.*)$") {
|
||||
[Environment]::SetEnvironmentVariable($matches[1], $matches[2], "Process")
|
||||
}
|
||||
}
|
||||
Print-Success "Environment variables loaded"
|
||||
} else {
|
||||
Print-Error ".env.local file not found"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if conda is available
|
||||
try {
|
||||
conda --version | Out-Null
|
||||
Print-Success "Conda is available"
|
||||
} catch {
|
||||
Print-Error "Conda is not available. Please install Anaconda or Miniconda first."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Create or update conda environment
|
||||
Print-Step "Creating/updating conda environment 'cua' with Python 3.12..."
|
||||
try {
|
||||
# Check if environment exists
|
||||
$envExists = conda env list | Select-String "^cua\s"
|
||||
if ($envExists) {
|
||||
Print-Step "Environment 'cua' already exists. Updating..."
|
||||
conda env update -n cua -f environment.yml --prune
|
||||
} else {
|
||||
Print-Step "Creating new environment 'cua'..."
|
||||
conda create -n cua python=3.12 -y
|
||||
}
|
||||
Print-Success "Conda environment 'cua' ready"
|
||||
} catch {
|
||||
Print-Error "Failed to create/update conda environment"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Activate conda environment
|
||||
Print-Step "Activating conda environment 'cua'..."
|
||||
try {
|
||||
conda activate cua
|
||||
Print-Success "Environment activated"
|
||||
} catch {
|
||||
Print-Error "Failed to activate conda environment 'cua'"
|
||||
Print-Step "Please run: conda activate cua"
|
||||
Print-Step "Then re-run this script"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Clean up existing environments and cache
|
||||
Print-Step "Cleaning up existing environments..."
|
||||
Get-ChildItem -Path . -Recurse -Directory -Name "__pycache__" | ForEach-Object { Remove-Item -Path $_ -Recurse -Force }
|
||||
Get-ChildItem -Path . -Recurse -Directory -Name ".pytest_cache" | ForEach-Object { Remove-Item -Path $_ -Recurse -Force }
|
||||
Get-ChildItem -Path . -Recurse -Directory -Name "dist" | ForEach-Object { Remove-Item -Path $_ -Recurse -Force }
|
||||
Get-ChildItem -Path . -Recurse -Directory -Name "*.egg-info" | ForEach-Object { Remove-Item -Path $_ -Recurse -Force }
|
||||
|
||||
# Function to install a package and its dependencies
|
||||
function Install-Package {
|
||||
param(
|
||||
[string]$PackageDir,
|
||||
[string]$PackageName,
|
||||
[string]$Extras = ""
|
||||
)
|
||||
|
||||
Print-Step "Installing $PackageName..."
|
||||
Set-Location $PackageDir
|
||||
|
||||
if (Test-Path "pyproject.toml") {
|
||||
if ($Extras) {
|
||||
pip install -e ".[$Extras]"
|
||||
} else {
|
||||
pip install -e .
|
||||
}
|
||||
} else {
|
||||
Print-Error "No pyproject.toml found in $PackageDir"
|
||||
Set-Location $PROJECT_ROOT
|
||||
return $false
|
||||
}
|
||||
|
||||
Set-Location $PROJECT_ROOT
|
||||
return $true
|
||||
}
|
||||
|
||||
# Install packages in order of dependency
|
||||
Print-Step "Installing packages in development mode..."
|
||||
|
||||
# Install core first (base package with telemetry support)
|
||||
if (-not (Install-Package "libs/python/core" "core")) { exit 1 }
|
||||
|
||||
# Install pylume (base dependency)
|
||||
if (-not (Install-Package "libs/python/pylume" "pylume")) { exit 1 }
|
||||
|
||||
# Install computer with all its dependencies and extras
|
||||
if (-not (Install-Package "libs/python/computer" "computer" "all")) { exit 1 }
|
||||
|
||||
# Install omniparser
|
||||
if (-not (Install-Package "libs/python/som" "som")) { exit 1 }
|
||||
|
||||
# Install agent with all its dependencies and extras
|
||||
if (-not (Install-Package "libs/python/agent" "agent" "all")) { exit 1 }
|
||||
|
||||
# Install computer-server
|
||||
if (-not (Install-Package "libs/python/computer-server" "computer-server")) { exit 1 }
|
||||
|
||||
# Install mcp-server
|
||||
if (-not (Install-Package "libs/python/mcp-server" "mcp-server")) { exit 1 }
|
||||
|
||||
# Install development tools from root project
|
||||
Print-Step "Installing development dependencies..."
|
||||
pip install -e ".[dev,test,docs]"
|
||||
|
||||
# Create a .env file for VS Code to use the virtual environment
|
||||
Print-Step "Creating .env file for VS Code..."
|
||||
$pythonPath = "$PROJECT_ROOT/libs/python/core;$PROJECT_ROOT/libs/python/computer;$PROJECT_ROOT/libs/python/agent;$PROJECT_ROOT/libs/python/som;$PROJECT_ROOT/libs/python/pylume;$PROJECT_ROOT/libs/python/computer-server;$PROJECT_ROOT/libs/python/mcp-server"
|
||||
"PYTHONPATH=$pythonPath" | Out-File -FilePath ".env" -Encoding UTF8
|
||||
|
||||
Print-Success "All packages installed successfully!"
|
||||
Print-Step "Your conda environment 'cua' is ready. To activate it:"
|
||||
Write-Host " conda activate cua" -ForegroundColor Yellow
|
||||
120
scripts/build.sh
120
scripts/build.sh
@@ -1,120 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print step information
|
||||
print_step() {
|
||||
echo -e "${BLUE}==> $1${NC}"
|
||||
}
|
||||
|
||||
# Function to print success message
|
||||
print_success() {
|
||||
echo -e "${GREEN}==> Success: $1${NC}"
|
||||
}
|
||||
|
||||
# Function to print error message
|
||||
print_error() {
|
||||
echo -e "${RED}==> Error: $1${NC}" >&2
|
||||
}
|
||||
|
||||
# Get the script's directory
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PROJECT_ROOT="$( cd "${SCRIPT_DIR}/.." && pwd )"
|
||||
|
||||
# Change to project root
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Load environment variables from .env.local
|
||||
if [ -f .env.local ]; then
|
||||
print_step "Loading environment variables from .env.local..."
|
||||
set -a
|
||||
source .env.local
|
||||
set +a
|
||||
print_success "Environment variables loaded"
|
||||
else
|
||||
print_error ".env.local file not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clean up existing environments and cache
|
||||
print_step "Cleaning up existing environments..."
|
||||
find . -type d -name "__pycache__" -exec rm -rf {} +
|
||||
find . -type d -name ".pytest_cache" -exec rm -rf {} +
|
||||
find . -type d -name "dist" -exec rm -rf {} +
|
||||
find . -type d -name ".venv" -exec rm -rf {} +
|
||||
find . -type d -name "*.egg-info" -exec rm -rf {} +
|
||||
print_success "Environment cleanup complete"
|
||||
|
||||
# Create and activate virtual environment
|
||||
print_step "Creating virtual environment..."
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate
|
||||
|
||||
# Upgrade pip and install build tools
|
||||
print_step "Upgrading pip and installing build tools..."
|
||||
python -m pip install --upgrade pip setuptools wheel
|
||||
|
||||
# Function to install a package and its dependencies
|
||||
install_package() {
|
||||
local package_dir=$1
|
||||
local package_name=$2
|
||||
local extras=$3
|
||||
print_step "Installing ${package_name}..."
|
||||
cd "$package_dir"
|
||||
|
||||
if [ -f "pyproject.toml" ]; then
|
||||
if [ -n "$extras" ]; then
|
||||
pip install -e ".[${extras}]"
|
||||
else
|
||||
pip install -e .
|
||||
fi
|
||||
else
|
||||
print_error "No pyproject.toml found in ${package_dir}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
}
|
||||
|
||||
# Install packages in order of dependency
|
||||
print_step "Installing packages in development mode..."
|
||||
|
||||
# Install core first (base package with telemetry support)
|
||||
install_package "libs/python/core" "core"
|
||||
|
||||
# Install pylume (base dependency)
|
||||
install_package "libs/python/pylume" "pylume"
|
||||
|
||||
# Install computer with all its dependencies and extras
|
||||
install_package "libs/python/computer" "computer" "all"
|
||||
|
||||
# Install omniparser
|
||||
install_package "libs/python/som" "som"
|
||||
|
||||
# Install agent with all its dependencies and extras
|
||||
install_package "libs/python/agent" "agent" "all"
|
||||
|
||||
# Install computer-server
|
||||
install_package "libs/python/computer-server" "computer-server"
|
||||
|
||||
# Install mcp-server
|
||||
install_package "libs/python/mcp-server" "mcp-server"
|
||||
|
||||
# Install development tools from root project
|
||||
print_step "Installing development dependencies..."
|
||||
pip install -e ".[dev,test,docs]"
|
||||
|
||||
# Create a .env file for VS Code to use the virtual environment
|
||||
print_step "Creating .env file for VS Code..."
|
||||
echo "PYTHONPATH=${PROJECT_ROOT}/libs/python/core:${PROJECT_ROOT}/libs/python/computer:${PROJECT_ROOT}/libs/python/agent:${PROJECT_ROOT}/libs/python/som:${PROJECT_ROOT}/libs/python/pylume:${PROJECT_ROOT}/libs/python/computer-server:${PROJECT_ROOT}/libs/python/mcp-server" > .env
|
||||
|
||||
print_success "All packages installed successfully!"
|
||||
print_step "Your virtual environment is ready. To activate it:"
|
||||
echo " source .venv/bin/activate"
|
||||
@@ -1,90 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print step information
|
||||
print_step() {
|
||||
echo -e "${BLUE}==> $1${NC}"
|
||||
}
|
||||
|
||||
# Function to print success message
|
||||
print_success() {
|
||||
echo -e "${GREEN}==> Success: $1${NC}"
|
||||
}
|
||||
|
||||
# Function to print error message
|
||||
print_error() {
|
||||
echo -e "${RED}==> Error: $1${NC}" >&2
|
||||
}
|
||||
|
||||
# Get the script's directory
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PROJECT_ROOT="$SCRIPT_DIR/.."
|
||||
|
||||
# Change to project root
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
print_step "Starting cleanup of all caches and virtual environments..."
|
||||
|
||||
# Remove all virtual environments
|
||||
print_step "Removing virtual environments..."
|
||||
find . -type d -name ".venv" -exec rm -rf {} +
|
||||
print_success "Virtual environments removed"
|
||||
|
||||
# Remove all Python cache files and directories
|
||||
print_step "Removing Python cache files and directories..."
|
||||
find . -type d -name "__pycache__" -exec rm -rf {} +
|
||||
find . -type d -name ".pytest_cache" -exec rm -rf {} +
|
||||
find . -type d -name ".mypy_cache" -exec rm -rf {} +
|
||||
find . -type d -name ".ruff_cache" -exec rm -rf {} +
|
||||
find . -name "*.pyc" -delete
|
||||
find . -name "*.pyo" -delete
|
||||
find . -name "*.pyd" -delete
|
||||
print_success "Python cache files removed"
|
||||
|
||||
# Remove all build artifacts
|
||||
print_step "Removing build artifacts..."
|
||||
find . -type d -name "build" -exec rm -rf {} +
|
||||
find . -type d -name "dist" -exec rm -rf {} +
|
||||
find . -type d -name "*.egg-info" -exec rm -rf {} +
|
||||
find . -type d -name "*.egg" -exec rm -rf {} +
|
||||
print_success "Build artifacts removed"
|
||||
|
||||
# Remove PDM-related files and directories
|
||||
print_step "Removing PDM-related files and directories..."
|
||||
find . -name "pdm.lock" -delete
|
||||
find . -type d -name ".pdm-build" -exec rm -rf {} +
|
||||
find . -name ".pdm-python" -delete # .pdm-python is a file, not a directory
|
||||
print_success "PDM-related files removed"
|
||||
|
||||
# Remove MCP-related files
|
||||
print_step "Removing MCP-related files..."
|
||||
find . -name "mcp_server.log" -delete
|
||||
print_success "MCP-related files removed"
|
||||
|
||||
# Remove .env file
|
||||
print_step "Removing .env file..."
|
||||
rm -f .env
|
||||
print_success ".env file removed"
|
||||
|
||||
# Remove typings directory
|
||||
print_step "Removing typings directory..."
|
||||
rm -rf .vscode/typings
|
||||
print_success "Typings directory removed"
|
||||
|
||||
# Clean up any temporary files
|
||||
print_step "Removing temporary files..."
|
||||
find . -name "*.tmp" -delete
|
||||
find . -name "*.bak" -delete
|
||||
find . -name "*.swp" -delete
|
||||
print_success "Temporary files removed"
|
||||
|
||||
print_success "Cleanup complete! All caches and virtual environments have been removed."
|
||||
print_step "To rebuild the project, run: bash scripts/build.sh"
|
||||
Reference in New Issue
Block a user