From 0f121ba5f20eb1487fd94eb69d3c7e9397d59cd6 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 20 Mar 2025 02:42:09 +0000 Subject: [PATCH] Enhance PR #2409 fix based on review feedback: improve docs, test isolation, and error messages Co-Authored-By: Joe Moura --- README.md | 3 +- pyproject.toml | 3 +- .../test_dependency_compatibility.py | 76 ++++++++++++++----- 3 files changed, 61 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 7dc641961..920bcf8a8 100644 --- a/README.md +++ b/README.md @@ -153,9 +153,10 @@ If you encounter issues during installation or usage, here are some common solut - If issues persist, use a pre-built wheel: `pip install tiktoken --prefer-binary` 3. **ModuleNotFoundError: No module named 'packaging.licenses'** - - This error occurs when installing with `uv` due to newer setuptools versions + - This error occurs when installing with `uv` (v0.1.0 and above) due to newer `setuptools` versions - Fix by downgrading setuptools: `pip install setuptools<=65.5.0` - Then install CrewAI: `uv pip install crewai` + - Note: This is a temporary workaround until compatibility with `setuptools` is resolved ### 2. Setting Up Your Crew with the YAML Configuration diff --git a/pyproject.toml b/pyproject.toml index 436d69554..0867d988a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,5 +96,6 @@ exclude = ["cli/templates"] exclude_dirs = ["src/crewai/cli/templates"] [build-system] -requires = ["hatchling", "setuptools<=65.5.0"] +# Pin setuptools version to avoid packaging.licenses dependency issues with UV package manager +requires = ["hatchling", "setuptools>=64.0.0,<=65.5.0"] # Explicit version range for compatibility build-backend = "hatchling.build" diff --git a/tests/installation/test_dependency_compatibility.py b/tests/installation/test_dependency_compatibility.py index 94887f2d4..8462397f2 100644 --- a/tests/installation/test_dependency_compatibility.py +++ b/tests/installation/test_dependency_compatibility.py @@ -1,42 +1,80 @@ +""" +Test module for verifying dependency compatibility with different package managers. +These tests ensure that critical dependencies can be installed without conflicts. +""" + +import contextlib import os import shutil import subprocess import sys +import tempfile import pytest +@contextlib.contextmanager +def temporary_package_environment(): + """Create an isolated environment for package testing. + + This context manager creates a temporary directory where package installations + can be tested in isolation, then cleans up afterward. + """ + temp_dir = tempfile.mkdtemp() + old_cwd = os.getcwd() + try: + os.chdir(temp_dir) + yield temp_dir + finally: + os.chdir(old_cwd) + shutil.rmtree(temp_dir, ignore_errors=True) + + def test_pypika_installation(): - """Test that pypika can be installed without packaging.licenses errors.""" + """Test that pypika can be installed without packaging.licenses errors. + + This test verifies that pypika 0.48.9 (a dependency of chromadb, which is a + dependency of CrewAI) can be installed without errors related to the + packaging.licenses module when using the UV package manager. + """ # Check if uv is available uv_path = shutil.which("uv") if not uv_path: - pytest.skip("UV not available, skipping test") + pytest.skip("UV package manager not available, skipping test") - # Install pypika using uv - result = subprocess.run( - ["uv", "pip", "install", "pypika==0.48.9", "--no-deps"], - capture_output=True, - text=True, - ) - assert result.returncode == 0, f"Failed to install pypika: {result.stderr}" + # Use isolated environment for testing + with temporary_package_environment(): + # Install pypika using uv + result = subprocess.run( + ["uv", "pip", "install", "pypika==0.48.9", "--no-deps"], + capture_output=True, + text=True, + ) + assert result.returncode == 0, f"Failed to install pypika: {result.stderr}\nCommand output: {result.stdout}" def test_chromadb_installation(): - """Test that chromadb can be installed without packaging.licenses errors.""" + """Test that chromadb can be installed without packaging.licenses errors. + + This test verifies that chromadb (a direct dependency of CrewAI) can be + installed without errors related to the packaging.licenses module when + using the UV package manager. + """ # Skip this test if running in CI/CD to avoid long test times if "CI" in os.environ: - pytest.skip("Skipping in CI environment") + pytest.skip("Skipping in CI environment to reduce test time") # Check if uv is available uv_path = shutil.which("uv") if not uv_path: - pytest.skip("UV not available, skipping test") + pytest.skip("UV package manager not available, skipping test") - # Install chromadb using uv - result = subprocess.run( - ["uv", "pip", "install", "chromadb>=0.5.23", "--no-deps"], - capture_output=True, - text=True, - ) - assert result.returncode == 0, f"Failed to install chromadb: {result.stderr}" + # Use isolated environment for testing + with temporary_package_environment(): + # Install chromadb using uv + result = subprocess.run( + ["uv", "pip", "install", "chromadb>=0.5.23", "--no-deps"], + capture_output=True, + text=True, + ) + assert result.returncode == 0, f"Failed to install chromadb: {result.stderr}\nCommand output: {result.stdout}"