Browse Source

Ad/fix pre commit (#807)

* Fix pre-commit config and some mypy issues

* remove hook of requirements.txt
Anas DORBANI 1 year ago
parent
commit
d38113cead
4 changed files with 37 additions and 33 deletions
  1. 5 5
      Makefile
  2. 10 5
      dev_config/python/.pre-commit-config.yaml
  3. 22 22
      opendevin/config.py
  4. 0 1
      tests/test_action_serialization.py

+ 5 - 5
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
+.PHONY: build build-eval start-backend start-frontend run setup-config help

+ 10 - 5
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

+ 22 - 22
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.

+ 0 - 1
tests/test_action_serialization.py

@@ -1,4 +1,3 @@
-import pytest
 from opendevin.action import (
     action_from_dict,
     Action,