From 4102f9aeca08c0f7a8c8243fc9bb092e6fd8083f Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Tue, 29 Jul 2025 14:41:39 -0400 Subject: [PATCH] uv migration --- .devcontainer/devcontainer.json | 2 +- AGENTS.md | 45 ++++++++++++++-------------- Dockerfile | 18 ++++++----- Makefile | 27 +++++------------ README.md | 6 ++-- docker-compose.override.yml | 6 ++-- docker-compose.yml | 4 +-- docs/contributing.md | 28 +++++++---------- docs/setup.md | 22 ++++++-------- docs/testing.md | 28 ++++++++--------- tests/README.md | 53 ++++++++++++++++----------------- 11 files changed, 107 insertions(+), 132 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ac61b0c..2a0faf3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,7 @@ "name": "Temporal AI Agentic Demo", "features": { "ghcr.io/devcontainers/features/node:1": {}, - "ghcr.io/devcontainers-extra/features/poetry:2": {}, + "ghcr.io/va-h/devcontainers-features/uv:1": {}, "ghcr.io/devcontainers/features/python:1": {}, "ghcr.io/devcontainers-extra/features/temporal-cli:1": {}, "ghcr.io/mrsimonemms/devcontainers/tcld:1": {} diff --git a/AGENTS.md b/AGENTS.md index 281634a..7a5eb5c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -34,11 +34,10 @@ Default URLs: 1. **Prerequisites:** ```bash - # Install Poetry for Python dependency management - curl -sSL https://install.python-poetry.org | python3 - - - # Start Temporal server (Mac) + # Install uv and Temporal server (MacOS) + brew install uv brew install temporal + temporal server start-dev ``` @@ -50,9 +49,9 @@ Default URLs: make run-api # Starts the API server # Or manually: - poetry install - poetry run python scripts/run_worker.py # In one terminal - poetry run uvicorn api.main:app --reload # In another terminal + uv sync + uv run python scripts/run_worker.py # In one terminal + uv run uvicorn api.main:app --reload # In another terminal ``` 3. **Frontend (React):** @@ -102,20 +101,20 @@ The project includes comprehensive tests using Temporal's testing framework: ```bash # Install test dependencies -poetry install --with dev +uv sync # Run all tests -poetry run pytest +uv run pytest # Run with time-skipping for faster execution -poetry run pytest --workflow-environment=time-skipping +uv run pytest --workflow-environment=time-skipping # Run specific test categories -poetry run pytest tests/test_tool_activities.py -v # Activity tests -poetry run pytest tests/test_agent_goal_workflow.py -v # Workflow tests +uv run pytest tests/test_tool_activities.py -v # Activity tests +uv run pytest tests/test_agent_goal_workflow.py -v # Workflow tests # Run with coverage -poetry run pytest --cov=workflows --cov=activities +uv run pytest --cov=workflows --cov=activities ``` **Test Coverage:** @@ -130,15 +129,17 @@ poetry run pytest --cov=workflows --cov=activities ## Linting and Code Quality ```bash -# Using Poetry tasks -poetry run poe format # Format code with black and isort -poetry run poe lint # Check code style and types -poetry run poe test # Run test suite +# Format code +uv run black . +uv run isort . -# Manual commands -poetry run black . -poetry run isort . -poetry run mypy --check-untyped-defs --namespace-packages . +# Check code style and types +uv run black --check . +uv run isort --check-only . +uv run mypy --check-untyped-defs --namespace-packages . + +# Run test suite +uv run pytest ``` ## Agent Customization @@ -192,7 +193,7 @@ For detailed architecture information, see [architecture.md](docs/architecture.m - Use clear commit messages describing the change purpose - Reference specific files and line numbers when relevant (e.g., `workflows/agent_goal_workflow.py:125`) - Open PRs describing **what changed** and **why** -- Ensure tests pass before submitting: `poetry run pytest --workflow-environment=time-skipping` +- Ensure tests pass before submitting: `uv run pytest --workflow-environment=time-skipping` ## Additional Resources - **Setup Guide**: [setup.md](docs/setup.md) - Detailed configuration instructions diff --git a/Dockerfile b/Dockerfile index 0666e24..2e39870 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,17 +4,19 @@ WORKDIR /app # Install system dependencies RUN apt-get update && \ - apt-get install -y --no-install-recommends gcc build-essential && \ + apt-get install -y --no-install-recommends gcc build-essential curl && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -# Copy requirements first for better caching -RUN pip install --no-cache-dir poetry +# Install uv +RUN curl -LsSf https://astral.sh/uv/install.sh | sh +ENV PATH="$PATH:/root/.local/bin" -# Install Python dependencies without creating a virtualenv -COPY pyproject.toml poetry.lock ./ -RUN poetry config virtualenvs.create false \ - && poetry install --without dev --no-interaction --no-ansi --no-root +# Copy dependency files and README (needed for package build) +COPY pyproject.toml uv.lock README.md ./ + +# Install dependencies and create virtual environment +RUN uv sync --frozen # Copy application code COPY . . @@ -27,4 +29,4 @@ ENV PYTHONPATH=/app EXPOSE 8000 # Default to running only the API server; worker and train-api are separate Compose services -CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"] +CMD ["uv", "run", "uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/Makefile b/Makefile index fab1a46..13ffe9d 100644 --- a/Makefile +++ b/Makefile @@ -1,35 +1,24 @@ .PHONY: setup install run-worker run-api run-frontend run-train-api run-legacy-worker run-enterprise setup-venv check-python run-dev -# Setup commands -setup: check-python setup-venv install - -check-python: - @which python3 >/dev/null 2>&1 || (echo "Python 3 is required. Please install it first." && exit 1) - @which poetry >/dev/null 2>&1 || (echo "Poetry is required. Please install it first." && exit 1) - -setup-venv: - python3 -m venv venv - @echo "Virtual environment created. Don't forget to activate it with 'source venv/bin/activate'" - -install: - poetry install +setup: + uv sync cd frontend && npm install # Run commands run-worker: - poetry run python scripts/run_worker.py + uv run python scripts/run_worker.py run-api: - poetry run uvicorn api.main:app --reload + uv run uvicorn api.main:app --reload run-frontend: cd frontend && npx vite run-train-api: - poetry run python thirdparty/train_api.py + uv run python thirdparty/train_api.py run-legacy-worker: - poetry run python scripts/run_legacy_worker.py + uv run python scripts/run_legacy_worker.py run-enterprise: cd enterprise && dotnet build && dotnet run @@ -50,9 +39,7 @@ run-dev: # Help command help: @echo "Available commands:" - @echo " make setup - Create virtual environment and install dependencies" - @echo " make setup-venv - Create virtual environment only" - @echo " make install - Install all dependencies" + @echo " make setup - Install all dependencies" @echo " make run-worker - Start the Temporal worker" @echo " make run-api - Start the API server" @echo " make run-frontend - Start the frontend development server" diff --git a/README.md b/README.md index e6ad23f..904b8b6 100644 --- a/README.md +++ b/README.md @@ -65,13 +65,13 @@ The project includes comprehensive tests for workflows and activities using Temp ```bash # Install dependencies including test dependencies -poetry install --with dev +uv sync # Run all tests -poetry run pytest +uv run pytest # Run with time-skipping for faster execution -poetry run pytest --workflow-environment=time-skipping +uv run pytest --workflow-environment=time-skipping ``` **Test Coverage:** diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 2a14573..c13fa1b 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -2,17 +2,17 @@ services: api: volumes: - ./:/app:cached - command: uvicorn api.main:app --host 0.0.0.0 --port 8000 --reload + command: uv run uvicorn api.main:app --host 0.0.0.0 --port 8000 --reload worker: volumes: - ./:/app:cached - command: python scripts/run_worker.py + command: uv run python scripts/run_worker.py train-api: volumes: - ./:/app:cached - command: python thirdparty/train_api.py + command: uv run python thirdparty/train_api.py frontend: volumes: diff --git a/docker-compose.yml b/docker-compose.yml index e3b20eb..522e722 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -79,7 +79,7 @@ services: - .env environment: - TEMPORAL_ADDRESS=temporal:7233 - command: python scripts/run_worker.py + command: uv run python scripts/run_worker.py networks: - temporal-network @@ -94,7 +94,7 @@ services: - .env environment: - TEMPORAL_ADDRESS=temporal:7233 - command: python thirdparty/train_api.py + command: uv run python thirdparty/train_api.py networks: - temporal-network diff --git a/docs/contributing.md b/docs/contributing.md index 8fed1a8..5e19019 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -8,40 +8,32 @@ This document provides guidelines for contributing to `temporal-ai-agent`. All s We use `black` for code formatting and `isort` for import sorting to maintain a consistent codebase. - **Format code:** ```bash - poetry run poe format - ``` - Or manually: - ```bash - poetry run black . - poetry run isort . + uv run black . + uv run isort . ``` Please format your code before committing. ### Linting & Type Checking -We use `mypy` for static type checking and other linters configured via `poe the poet`. -- **Run linters and type checks:** +We use `mypy` for static type checking. +- **Run type checks:** ```bash - poetry run poe lint - ``` - Or manually for type checking: - ```bash - poetry run mypy --check-untyped-defs --namespace-packages . + uv run mypy --check-untyped-defs --namespace-packages . ``` Ensure all linting and type checks pass before submitting a pull request. ## Testing Comprehensive testing is crucial for this project. We use `pytest` and Temporal's testing framework. -- **Install test dependencies** (if not already done with `poetry install --with dev`): +- **Install test dependencies:** ```bash - poetry install --with dev + uv sync ``` - **Run all tests:** ```bash - poetry run pytest + uv run pytest ``` - **Run tests with time-skipping (recommended for faster execution, especially in CI):** ```bash - poetry run pytest --workflow-environment=time-skipping + uv run pytest --workflow-environment=time-skipping ``` For detailed information on test categories, running specific tests, test environments, coverage, and troubleshooting, please refer to: @@ -73,7 +65,7 @@ When you're ready to submit your changes: 1. Push your branch to the remote repository. 2. Open a Pull Request (PR) against the `main` branch. 3. **Describe your changes:** Clearly explain what you changed and why. Reference any related issues. -4. **Ensure tests pass:** All CI checks, including tests and linters, must pass. The command `poetry run pytest --workflow-environment=time-skipping` is a good one to run locally. +4. **Ensure tests pass:** All CI checks, including tests and linters, must pass. The command `uv run pytest --workflow-environment=time-skipping` is a good one to run locally. 5. **Request review:** Request a review from one or more maintainers. ## Reporting Bugs diff --git a/docs/setup.md b/docs/setup.md index 3c88d05..0520df3 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -22,8 +22,6 @@ We've provided a Makefile to simplify the setup and running of the application. ```bash # Initial setup make setup # Creates virtual environment and installs dependencies -make setup-venv # Creates virtual environment only -make install # Installs all dependencies # Running the application make run-worker # Starts the Temporal worker @@ -159,24 +157,22 @@ Default urls: **Python Backend** -Requires [Poetry](https://python-poetry.org/) to manage dependencies. +Requires [`uv`](https://docs.astral.sh/uv/) to manage dependencies. -1. `python -m venv venv` +1. Install uv: `curl -LsSf https://astral.sh/uv/install.sh | sh` -2. `source venv/bin/activate` - -3. `poetry install` +2. `uv sync` Run the following commands in separate terminal windows: 1. Start the Temporal worker: ```bash -poetry run python scripts/run_worker.py +uv run python scripts/run_worker.py ``` 2. Start the API server: ```bash -poetry run uvicorn api.main:app --reload +uv run uvicorn api.main:app --reload ``` Access the API at `/docs` to see the available endpoints. @@ -261,7 +257,7 @@ NOTE: This goal was developed for an on-stage demo and has failure (and its reso Required to search and book trains! ```bash -poetry run python thirdparty/train_api.py +uv run python thirdparty/train_api.py # example url # http://localhost:8080/api/search?from=london&to=liverpool&outbound_time=2025-04-18T09:00:00&inbound_time=2025-04-20T09:00:00 @@ -273,7 +269,7 @@ poetry run python thirdparty/train_api.py These are Python activities that fail (raise NotImplemented) to show how Temporal handles a failure. You can run these activities with. ```bash - poetry run python scripts/run_legacy_worker.py + uv run python scripts/run_legacy_worker.py ``` The activity will fail and be retried infinitely. To rescue the activity (and its corresponding workflows), kill the worker and run the .NET one in the section below. @@ -328,8 +324,8 @@ For more details, check out [adding goals and tools guide](./adding-goals-and-to [ ] Select an LLM and add your API key to `.env`
[ ] (Optional) set your starting goal and goal category in `.env`
[ ] (Optional) configure your Temporal Cloud settings in `.env`
-[ ] `poetry run python scripts/run_worker.py`
-[ ] `poetry run uvicorn api.main:app --reload`
+[ ] `uv run python scripts/run_worker.py`
+[ ] `uv run uvicorn api.main:app --reload`
[ ] `cd frontend`, `npm install`, `npx vite`
[ ] Access the UI at `http://localhost:5173`
diff --git a/docs/testing.md b/docs/testing.md index 734435b..6a68054 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -6,17 +6,17 @@ This guide provides instructions for running the comprehensive test suite for th 1. **Install dependencies**: ```bash - poetry install --with dev + uv sync ``` 2. **Run all tests**: ```bash - poetry run pytest + uv run pytest ``` 3. **Run with time-skipping for faster execution**: ```bash - poetry run pytest --workflow-environment=time-skipping + uv run pytest --workflow-environment=time-skipping ``` ## Test Categories @@ -39,33 +39,33 @@ This guide provides instructions for running the comprehensive test suite for th ```bash # Run only activity tests -poetry run pytest tests/test_tool_activities.py -v +uv run pytest tests/test_tool_activities.py -v # Run only workflow tests -poetry run pytest tests/test_agent_goal_workflow.py -v +uv run pytest tests/test_agent_goal_workflow.py -v # Run a specific test -poetry run pytest tests/test_tool_activities.py::TestToolActivities::test_sanitize_json_response -v +uv run pytest tests/test_tool_activities.py::TestToolActivities::test_sanitize_json_response -v # Run tests matching a pattern -poetry run pytest -k "validation" -v +uv run pytest -k "validation" -v ``` ## Test Environment Options ### Local Environment (Default) ```bash -poetry run pytest --workflow-environment=local +uv run pytest --workflow-environment=local ``` ### Time-Skipping Environment (Recommended for CI) ```bash -poetry run pytest --workflow-environment=time-skipping +uv run pytest --workflow-environment=time-skipping ``` ### External Temporal Server ```bash -poetry run pytest --workflow-environment=localhost:7233 +uv run pytest --workflow-environment=localhost:7233 ``` ## Environment Variables @@ -122,7 +122,7 @@ tests/test_tool_activities.py::TestToolActivities::test_get_wf_env_vars_default_ ### Common Issues -1. **Module not found errors**: Run `poetry install --with dev` +1. **Module not found errors**: Run `uv sync` 2. **Async warnings**: These are expected with pytest-asyncio and can be ignored 3. **Test timeouts**: Use `--workflow-environment=time-skipping` for faster execution 4. **Import errors**: Check that you're running tests from the project root directory @@ -131,19 +131,19 @@ tests/test_tool_activities.py::TestToolActivities::test_get_wf_env_vars_default_ Enable verbose logging: ```bash -poetry run pytest --log-cli-level=DEBUG -s +uv run pytest --log-cli-level=DEBUG -s ``` Run with coverage: ```bash -poetry run pytest --cov=workflows --cov=activities +uv run pytest --cov=workflows --cov=activities ``` ## Continuous Integration For CI environments, use: ```bash -poetry run pytest --workflow-environment=time-skipping --tb=short +uv run pytest --workflow-environment=time-skipping --tb=short ``` ## Additional Resources diff --git a/tests/README.md b/tests/README.md index 1a420d4..95599ce 100644 --- a/tests/README.md +++ b/tests/README.md @@ -53,31 +53,31 @@ Provides shared test fixtures and configuration: Ensure you have the required dependencies installed: ```bash -poetry install --with dev +uv sync ``` ### Basic Test Execution Run all tests: ```bash -poetry run pytest +uv run pytest ``` Run specific test files: ```bash # Workflow tests only -poetry run pytest tests/test_agent_goal_workflow.py +uv run pytest tests/test_agent_goal_workflow.py # Activity tests only -poetry run pytest tests/test_tool_activities.py +uv run pytest tests/test_tool_activities.py # Legacy tests -poetry run pytest tests/workflowtests/ +uv run pytest tests/workflowtests/ ``` Run with verbose output: ```bash -poetry run pytest -v +uv run pytest -v ``` ### Test Environment Options @@ -87,34 +87,34 @@ The tests support different Temporal environments via the `--workflow-environmen #### Local Environment (Default) Uses a local Temporal test server: ```bash -poetry run pytest --workflow-environment=local +uv run pytest --workflow-environment=local ``` #### Time-Skipping Environment Uses Temporal's time-skipping test environment for faster execution: ```bash -poetry run pytest --workflow-environment=time-skipping +uv run pytest --workflow-environment=time-skipping ``` #### External Server Connect to an existing Temporal server: ```bash -poetry run pytest --workflow-environment=localhost:7233 +uv run pytest --workflow-environment=localhost:7233 ``` #### Setup Script for AI Agent environments such as OpenAI Codex ```bash export SHELL=/bin/bash -curl -sSL https://install.python-poetry.org | python3 - +curl -LsSf https://astral.sh/uv/install.sh | sh export PATH="$HOME/.local/bin:$PATH" ls -poetry install --with dev +uv sync cd frontend npm install cd .. # Pre-download the temporal test server binary -poetry run python3 -c " +uv run python -c " import asyncio import sys from temporalio.testing import WorkflowEnvironment @@ -139,22 +139,22 @@ asyncio.run(predownload()) Run tests by pattern: ```bash # Run only validation tests -poetry run pytest -k "validation" +uv run pytest -k "validation" # Run only workflow tests -poetry run pytest -k "workflow" +uv run pytest -k "workflow" # Run only activity tests -poetry run pytest -k "activity" +uv run pytest -k "activity" ``` Run tests by marker (if you add custom markers): ```bash # Run only integration tests -poetry run pytest -m integration +uv run pytest -m integration # Skip slow tests -poetry run pytest -m "not slow" +uv run pytest -m "not slow" ``` ## Test Configuration @@ -276,7 +276,7 @@ The `sample_combined_input` fixture provides: Enable detailed logging: ```bash -poetry run pytest --log-cli-level=DEBUG -s +uv run pytest --log-cli-level=DEBUG -s ``` ### Temporal Web UI @@ -301,21 +301,18 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - run: pip install poetry - - run: poetry install --with dev - - run: poetry run pytest --workflow-environment=time-skipping + - uses: actions/checkout@v4 + - uses: astral-sh/setup-uv@v5 + - run: uv sync + - run: uv run pytest --workflow-environment=time-skipping ``` ### Test Coverage Generate coverage reports: ```bash -poetry add --group dev pytest-cov -poetry run pytest --cov=workflows --cov=activities --cov-report=html +uv add --group dev pytest-cov +uv run pytest --cov=workflows --cov=activities --cov-report=html ``` ## Best Practices @@ -342,7 +339,7 @@ poetry run pytest --cov=workflows --cov=activities --cov-report=html - Check Temporal Python SDK documentation - Review existing test patterns in the codebase -- Use `poetry run pytest --collect-only` to verify test discovery +- Use `uv run pytest --collect-only` to verify test discovery - Run with `-v` flag for detailed output ## Legacy Tests