Created
February 7, 2025 20:53
-
-
Save kevinold/7bd187eba33daaadd949a10b894e28b1 to your computer and use it in GitHub Desktop.
create-crewai
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S uv run --script | |
# /// script | |
# requires-python = ">=3.11,<3.13" | |
# dependencies = [] | |
# /// | |
# -*- coding: python -*- | |
# cd work/crewai-giggs-experiments | |
# uvx crewai create crew <project-name> | |
# cd <project-name> | |
# uv venv --python 3.12 | |
# source .venv/bin/activate | |
# uvx crewai install | |
# git init . | |
# git add -A | |
# git ci -am 'initial commit' | |
import os | |
import subprocess | |
import sys | |
# Change the base directory to use the home directory | |
base_dir = os.path.join(os.path.expanduser("~"), "work/crewai-giggs-experiments") | |
def create_crewai_project(project_name, base_dir=base_dir): | |
"""Create a new CrewAI project with the specified name. | |
Args: | |
project_name (str): Name of the project to create | |
base_dir (str): Base directory where the project will be created | |
""" | |
try: | |
# Ensure base directory exists | |
os.makedirs(base_dir, exist_ok=True) | |
# Change to the base directory before creating the project | |
os.chdir(base_dir) | |
# Convert project name to underscore format as CrewAI does | |
normalized_project_name = project_name.replace("-", "_") | |
# Create new crew project | |
subprocess.run( | |
["uvx", "crewai", "create", "crew", "--skip_provider", project_name], | |
check=True, | |
) | |
# Now construct and verify project directory path using normalized name | |
project_dir = os.path.join(base_dir, normalized_project_name) | |
if not os.path.exists(project_dir): | |
print( | |
f"Error: Project directory was not created at {project_dir}", | |
file=sys.stderr, | |
) | |
sys.exit(1) | |
# Change to project directory | |
os.chdir(project_dir) | |
# Create virtual environment with Python 3.12 | |
subprocess.run(["uv", "venv", "--python", "3.12"], check=True) | |
# Activate virtual environment and install crewai | |
venv_path = os.path.abspath(".venv") | |
os.environ["VIRTUAL_ENV"] = venv_path | |
os.environ["PATH"] = f"{os.path.join(venv_path, 'bin')}:{os.environ['PATH']}" | |
# Install crewai | |
subprocess.run(["uvx", "crewai", "install"], check=True) | |
# Initialize git repository | |
subprocess.run(["git", "init", "."], check=True) | |
subprocess.run(["git", "add", "-A"], check=True) | |
subprocess.run(["git", "commit", "-m", "initial commit"], check=True) | |
print(f"Successfully created CrewAI project: {project_name} in {project_dir}") | |
except subprocess.CalledProcessError as e: | |
print(f"Error executing command: {e}", file=sys.stderr) | |
sys.exit(1) | |
except Exception as e: | |
print(f"An error occurred: {e}", file=sys.stderr) | |
sys.exit(1) | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("Usage: create-crewai <project-name> [base-dir]", file=sys.stderr) | |
sys.exit(1) | |
project_name = sys.argv[1] | |
base_dir = sys.argv[2] if len(sys.argv) > 2 else base_dir | |
create_crewai_project(project_name, base_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment