From d38113ceadcc58bbe85a2aa92afa18a0850100b7 Mon Sep 17 00:00:00 2001 From: Anas DORBANI <95044293+dorbanianas@users.noreply.github.com> Date: Sat, 6 Apr 2024 03:48:30 +0000 Subject: [PATCH] Ad/fix pre commit (#807) * Fix pre-commit config and some mypy issues * remove hook of requirements.txt --- Makefile | 10 +++--- dev_config/python/.pre-commit-config.yaml | 15 +++++--- opendevin/config.py | 44 +++++++++++------------ tests/test_action_serialization.py | 1 - 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 50225adfbd..d658a261c8 100644 --- a/Makefile +++ b/Makefile @@ -60,9 +60,6 @@ build: @curl -sSL https://install.python-poetry.org | python3 - @poetry install --without evaluation @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 "$(GREEN)Setting up frontend environment...$(RESET)" @echo "$(YELLOW)Detect Node.js version...$(RESET)" @cd frontend && node ./scripts/detect-node-version.js @@ -71,6 +68,9 @@ build: rm -rf node_modules; \ fi @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)Installing pre-commit hooks...$(RESET)" + @git config --unset-all core.hooksPath || true + @poetry run pre-commit install --config $(PRECOMMIT_CONFIG_PATH) @echo "$(GREEN)Build completed successfully.$(RESET)" # Start backend @@ -107,7 +107,7 @@ setup-config: @read -p "Enter your LLM API key: " llm_api_key; \ echo "LLM_API_KEY=\"$$llm_api_key\"" >> $(CONFIG_FILE).tmp - + @read -p "Enter your LLM Base URL [mostly used for local LLMs, leave blank if not needed - example: http://localhost:5001/v1/]: " llm_base_url; \ if [[ ! -z "$$llm_base_url" ]]; then echo "LLM_BASE_URL=\"$$llm_base_url\"" >> $(CONFIG_FILE).tmp; fi @@ -148,4 +148,4 @@ help: @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 \ No newline at end of file +.PHONY: build build-eval start-backend start-frontend run setup-config help diff --git a/dev_config/python/.pre-commit-config.yaml b/dev_config/python/.pre-commit-config.yaml index eccbe9a3ca..29f50941b6 100644 --- a/dev_config/python/.pre-commit-config.yaml +++ b/dev_config/python/.pre-commit-config.yaml @@ -7,7 +7,6 @@ repos: - id: check-yaml - id: debug-statements - id: double-quote-string-fixer - - id: requirements-txt-fixer - repo: https://github.com/hhatto/autopep8 rev: v2.1.0 @@ -22,18 +21,24 @@ repos: pass_filenames: false - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.3 + # Ruff version. + rev: v0.3.5 hooks: + # Run the linter. - id: ruff entry: ruff check --config dev_config/python/ruff.toml opendevin/ agenthub/ - always_run: true - pass_filenames: false + types_or: [ python, pyi, jupyter ] + args: [ --fix ] + # Run the formatter. + - id: ruff-format + entry: ruff check --config dev_config/python/ruff.toml opendevin/ agenthub/ + types_or: [ python, pyi, jupyter ] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.9.0 hooks: - id: mypy - additional_dependencies: [types-requests, types-setuptools] + additional_dependencies: [types-requests, types-setuptools, types-pyyaml, types-toml] entry: mypy --config-file dev_config/python/mypy.ini opendevin/ agenthub/ always_run: true pass_filenames: false diff --git a/opendevin/config.py b/opendevin/config.py index 765dc1e146..3e61096bb6 100644 --- a/opendevin/config.py +++ b/opendevin/config.py @@ -1,38 +1,37 @@ import os -import toml # type: ignore +import toml from dotenv import load_dotenv load_dotenv() DEFAULT_CONFIG = { - "LLM_API_KEY": None, - "LLM_BASE_URL": None, - "WORKSPACE_DIR": os.path.join(os.getcwd(), "workspace"), - "LLM_MODEL": "gpt-4-0125-preview", - "SANDBOX_CONTAINER_IMAGE": "ghcr.io/opendevin/sandbox", - "RUN_AS_DEVIN": "false", - "LLM_EMBEDDING_MODEL": "local", - "LLM_NUM_RETRIES": 6, - "LLM_COOLDOWN_TIME" : 1, - "DIRECTORY_REWRITE" : "", - "PROMPT_DEBUG_DIR": "", - "MAX_ITERATIONS": 100, + 'LLM_API_KEY': None, + 'LLM_BASE_URL': None, + 'WORKSPACE_DIR': os.path.join(os.getcwd(), 'workspace'), + 'LLM_MODEL': 'gpt-4-0125-preview', + 'SANDBOX_CONTAINER_IMAGE': 'ghcr.io/opendevin/sandbox', + 'RUN_AS_DEVIN': 'false', + 'LLM_EMBEDDING_MODEL': 'local', + 'LLM_NUM_RETRIES': 6, + 'LLM_COOLDOWN_TIME': 1, + 'DIRECTORY_REWRITE': '', + 'PROMPT_DEBUG_DIR': '', + 'MAX_ITERATIONS': 100, } -config_str = "" -if os.path.exists("config.toml"): - with open("config.toml", "rb") as f: - config_str = f.read().decode("utf-8") +config_str = '' +if os.path.exists('config.toml'): + with open('config.toml', 'rb') as f: + config_str = f.read().decode('utf-8') tomlConfig = toml.loads(config_str) config = DEFAULT_CONFIG.copy() for key, value in config.items(): - if key in os.environ: - config[key] = os.environ[key] - elif key in tomlConfig: - config[key] = tomlConfig[key] - + if key in os.environ: + config[key] = os.environ[key] + elif key in tomlConfig: + config[key] = tomlConfig[key] def _get(key: str, default): @@ -65,6 +64,7 @@ def get_or_none(key: str): """ return _get(key, None) + def get(key: str): """ Get a key from the config, please make sure it exists. diff --git a/tests/test_action_serialization.py b/tests/test_action_serialization.py index d58ac78199..ba7e9202c2 100644 --- a/tests/test_action_serialization.py +++ b/tests/test_action_serialization.py @@ -1,4 +1,3 @@ -import pytest from opendevin.action import ( action_from_dict, Action,