mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Check python npm pnpm docker (#800)
This commit is contained in:
parent
7d3cd06ef5
commit
66cd9f9bd9
95
Makefile
95
Makefile
@ -10,54 +10,97 @@ DEFAULT_MODEL = "gpt-4-0125-preview"
|
||||
CONFIG_FILE = config.toml
|
||||
PRECOMMIT_CONFIG_PATH = "./dev_config/python/.pre-commit-config.yaml"
|
||||
|
||||
# ANSI color codes
|
||||
GREEN=\033[0;32m
|
||||
YELLOW=\033[0;33m
|
||||
RED=\033[0;31m
|
||||
BLUE=\033[0;34m
|
||||
RESET=\033[0m
|
||||
|
||||
# Build
|
||||
build:
|
||||
@echo "Building project..."
|
||||
@echo "Pulling Docker image..."
|
||||
@echo "$(GREEN)Building project...$(RESET)"
|
||||
@echo "$(YELLOW)Checking Python installation...$(RESET)"
|
||||
@if command -v python3 > /dev/null; then \
|
||||
PYTHON_VERSION=$(shell python3 --version 2>&1 | cut -d ' ' -f 2); \
|
||||
echo "$(BLUE)Python 3 is already installed. Version: $${PYTHON_VERSION}$(RESET)"; \
|
||||
else \
|
||||
echo "$(RED)Python 3 is not installed. Please install Python 3 to continue.$(RESET)"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@echo "$(YELLOW)Checking npm installation...$(RESET)"
|
||||
@if command -v npm > /dev/null; then \
|
||||
NPM_VERSION=$(shell npm --version); \
|
||||
echo "$(BLUE)npm is already installed. Version: $${NPM_VERSION}$(RESET)"; \
|
||||
else \
|
||||
echo "$(RED)npm is not installed. Please install Node.js to continue.$(RESET)"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@echo "$(YELLOW)Checking pnpm installation...$(RESET)"
|
||||
@if command -v pnpm > /dev/null; then \
|
||||
PNPM_VERSION=$(shell pnpm --version); \
|
||||
echo "$(BLUE)pnpm is already installed. Version: $${PNPM_VERSION}$(RESET)"; \
|
||||
else \
|
||||
echo "$(YELLOW)pnpm is not installed. Installing corepack to enable pnpm...$(RESET)"; \
|
||||
npm install -g corepack; \
|
||||
corepack enable; \
|
||||
echo "$(BLUE)pnpm installed and enabled.$(RESET)"; \
|
||||
fi
|
||||
@echo "$(YELLOW)Checking Docker installation...$(RESET)"
|
||||
@if command -v docker > /dev/null; then \
|
||||
DOCKER_VERSION=$(shell docker --version | awk '{print $$3}'); \
|
||||
echo "$(BLUE)Docker is already installed. Version: $${DOCKER_VERSION}$(RESET)"; \
|
||||
else \
|
||||
echo "$(RED)Docker is not installed. Please install Docker to continue.$(RESET)"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@echo "$(GREEN)Pulling Docker image...$(RESET)"
|
||||
@docker pull $(DOCKER_IMAGE)
|
||||
@echo "Installing Python dependencies..."
|
||||
@echo "$(GREEN)Installing Python dependencies...$(RESET)"
|
||||
@curl -sSL https://install.python-poetry.org | python3 -
|
||||
@poetry install --without evaluation
|
||||
@echo "Activating Poetry shell..."
|
||||
@echo "Installing pre-commit hooks..."
|
||||
@echo "$(GREEN)Activating Poetry shell...$(RESET)"
|
||||
@echo "$(GREEN)Installing pre-commit hooks...$(RESET)"
|
||||
@git config --unset-all core.hooksPath || true
|
||||
@poetry run pre-commit install --config $(PRECOMMIT_CONFIG_PATH)
|
||||
@echo "Setting up frontend environment..."
|
||||
@echo "Detect Node.js version..."
|
||||
@echo "$(GREEN)Setting up frontend environment...$(RESET)"
|
||||
@echo "$(YELLOW)Detect Node.js version...$(RESET)"
|
||||
@cd frontend && node ./scripts/detect-node-version.js
|
||||
@cd frontend && if [ -f node_modules/.package-lock.json ]; then \
|
||||
echo "This project currently uses \"pnpm\" for dependency management. It has detected that dependencies were previously installed using \"npm\" and has automatically deleted the \"node_modules\" directory to prevent unnecessary conflicts."; \
|
||||
echo "$(YELLOW)This project currently uses \"pnpm\" for dependency management. It has detected that dependencies were previously installed using \"npm\" and has automatically deleted the \"node_modules\" directory to prevent unnecessary conflicts.$(RESET)"; \
|
||||
rm -rf node_modules; \
|
||||
fi
|
||||
@which corepack > /dev/null || (echo "Installing corepack..." && npm install -g corepack)
|
||||
@cd frontend && corepack enable && pnpm install && pnpm run make-i18n
|
||||
@cd frontend && echo "$(BLUE)Enabling pnpm...$(RESET)" && corepack enable && echo "$(BLUE)Installing frontend dependencies with pnpm...$(RESET)" && pnpm install && echo "$(BLUE)Running make-i18n with pnpm...$(RESET)" && pnpm run make-i18n
|
||||
@echo "$(GREEN)Build completed successfully.$(RESET)"
|
||||
|
||||
# Start backend
|
||||
start-backend:
|
||||
@echo "Starting backend..."
|
||||
@echo "$(GREEN)Starting backend...$(RESET)"
|
||||
@poetry run uvicorn opendevin.server.listen:app --port $(BACKEND_PORT)
|
||||
|
||||
# Start frontend
|
||||
start-frontend:
|
||||
@echo "Starting frontend..."
|
||||
@echo "$(GREEN)Starting frontend...$(RESET)"
|
||||
@cd frontend && BACKEND_HOST=$(BACKEND_HOST) FRONTEND_PORT=$(FRONTEND_PORT) pnpm run start
|
||||
|
||||
# Run the app
|
||||
run:
|
||||
@echo "Running the app..."
|
||||
@echo "$(GREEN)Running the app...$(RESET)"
|
||||
@if [ "$(OS)" = "Windows_NT" ]; then \
|
||||
echo "`make run` is not supported on Windows. Please run `make start-frontend` and `make start-backend` separately."; \
|
||||
echo "$(RED)`make run` is not supported on Windows. Please run `make start-frontend` and `make start-backend` separately.$(RESET)"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@mkdir -p logs
|
||||
@poetry run nohup uvicorn opendevin.server.listen:app --port $(BACKEND_PORT) > logs/backend_$(shell date +'%Y%m%d_%H%M%S').log 2>&1 &
|
||||
@echo "Waiting for the backend to start..."
|
||||
@echo "$(YELLOW)Waiting for the backend to start...$(RESET)"
|
||||
@until nc -z localhost $(BACKEND_PORT); do sleep 0.1; done
|
||||
@cd frontend && pnpm run start -- --port $(FRONTEND_PORT)
|
||||
@echo "$(GREEN)Backend started successfully.$(RESET)"
|
||||
@cd frontend && echo "$(BLUE)Starting frontend with pnpm...$(RESET)" && pnpm run start -- --port $(FRONTEND_PORT)
|
||||
@echo "$(GREEN)Application started successfully.$(RESET)"
|
||||
|
||||
# Setup config.toml
|
||||
setup-config:
|
||||
@echo "Setting up config.toml..."
|
||||
@echo "$(GREEN)Setting up config.toml...$(RESET)"
|
||||
@read -p "Enter your LLM Model name (see https://docs.litellm.ai/docs/providers for full list) [default: $(DEFAULT_MODEL)]: " llm_model; \
|
||||
llm_model=$${llm_model:-$(DEFAULT_MODEL)}; \
|
||||
echo "LLM_MODEL=\"$$llm_model\"" > $(CONFIG_FILE).tmp
|
||||
@ -88,19 +131,21 @@ setup-config:
|
||||
echo "WORKSPACE_DIR=\"$$workspace_dir\"" >> $(CONFIG_FILE).tmp
|
||||
|
||||
@mv $(CONFIG_FILE).tmp $(CONFIG_FILE)
|
||||
@echo "$(GREEN)Config.toml setup completed.$(RESET)"
|
||||
|
||||
# Help
|
||||
help:
|
||||
@echo "Usage: make [target]"
|
||||
@echo "$(BLUE)Usage: make [target]$(RESET)"
|
||||
@echo "Targets:"
|
||||
@echo " build - Build project, including environment setup and dependencies."
|
||||
@echo " build-eval - Build project evaluation pipeline, including environment setup and dependencies."
|
||||
@echo " start-backend - Start the backend server for the OpenDevin project."
|
||||
@echo " start-frontend - Start the frontend server for the OpenDevin project."
|
||||
@echo " run - Run the OpenDevin application, starting both backend and frontend servers."
|
||||
@echo " $(GREEN)build$(RESET) - Build project, including environment setup and dependencies."
|
||||
@echo " $(GREEN)build-eval$(RESET) - Build project evaluation pipeline, including environment setup and dependencies."
|
||||
@echo " $(GREEN)start-backend$(RESET) - Start the backend server for the OpenDevin project."
|
||||
@echo " $(GREEN)start-frontend$(RESET) - Start the frontend server for the OpenDevin project."
|
||||
@echo " $(GREEN)run$(RESET) - Run the OpenDevin application, starting both backend and frontend servers."
|
||||
@echo " Backend Log file will be stored in the 'logs' directory."
|
||||
@echo " setup-config - Setup the configuration for OpenDevin by providing LLM API key, LLM Model name, and workspace directory."
|
||||
@echo " help - Display this help message, providing information on available targets."
|
||||
@echo " $(GREEN)setup-config$(RESET) - Setup the configuration for OpenDevin by providing LLM API key,"
|
||||
@echo " LLM Model name, and workspace directory."
|
||||
@echo " $(GREEN)help$(RESET) - Display this help message, providing information on available targets."
|
||||
|
||||
# Phony targets
|
||||
.PHONY: build build-eval start-backend start-frontend run setup-config help
|
||||
Loading…
x
Reference in New Issue
Block a user