Skip to content

Commit d38113c

Browse files
authored
Ad/fix pre commit (OpenHands#807)
* Fix pre-commit config and some mypy issues * remove hook of requirements.txt
1 parent 66cd9f9 commit d38113c

4 files changed

Lines changed: 37 additions & 33 deletions

File tree

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ build:
6060
@curl -sSL https://install.python-poetry.org | python3 -
6161
@poetry install --without evaluation
6262
@echo "$(GREEN)Activating Poetry shell...$(RESET)"
63-
@echo "$(GREEN)Installing pre-commit hooks...$(RESET)"
64-
@git config --unset-all core.hooksPath || true
65-
@poetry run pre-commit install --config $(PRECOMMIT_CONFIG_PATH)
6663
@echo "$(GREEN)Setting up frontend environment...$(RESET)"
6764
@echo "$(YELLOW)Detect Node.js version...$(RESET)"
6865
@cd frontend && node ./scripts/detect-node-version.js
@@ -71,6 +68,9 @@ build:
7168
rm -rf node_modules; \
7269
fi
7370
@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
71+
@echo "$(GREEN)Installing pre-commit hooks...$(RESET)"
72+
@git config --unset-all core.hooksPath || true
73+
@poetry run pre-commit install --config $(PRECOMMIT_CONFIG_PATH)
7474
@echo "$(GREEN)Build completed successfully.$(RESET)"
7575

7676
# Start backend
@@ -107,7 +107,7 @@ setup-config:
107107

108108
@read -p "Enter your LLM API key: " llm_api_key; \
109109
echo "LLM_API_KEY=\"$$llm_api_key\"" >> $(CONFIG_FILE).tmp
110-
110+
111111
@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; \
112112
if [[ ! -z "$$llm_base_url" ]]; then echo "LLM_BASE_URL=\"$$llm_base_url\"" >> $(CONFIG_FILE).tmp; fi
113113

@@ -148,4 +148,4 @@ help:
148148
@echo " $(GREEN)help$(RESET) - Display this help message, providing information on available targets."
149149

150150
# Phony targets
151-
.PHONY: build build-eval start-backend start-frontend run setup-config help
151+
.PHONY: build build-eval start-backend start-frontend run setup-config help

dev_config/python/.pre-commit-config.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ repos:
77
- id: check-yaml
88
- id: debug-statements
99
- id: double-quote-string-fixer
10-
- id: requirements-txt-fixer
1110

1211
- repo: https://github.com/hhatto/autopep8
1312
rev: v2.1.0
@@ -22,18 +21,24 @@ repos:
2221
pass_filenames: false
2322

2423
- repo: https://github.com/astral-sh/ruff-pre-commit
25-
rev: v0.3.3
24+
# Ruff version.
25+
rev: v0.3.5
2626
hooks:
27+
# Run the linter.
2728
- id: ruff
2829
entry: ruff check --config dev_config/python/ruff.toml opendevin/ agenthub/
29-
always_run: true
30-
pass_filenames: false
30+
types_or: [ python, pyi, jupyter ]
31+
args: [ --fix ]
32+
# Run the formatter.
33+
- id: ruff-format
34+
entry: ruff check --config dev_config/python/ruff.toml opendevin/ agenthub/
35+
types_or: [ python, pyi, jupyter ]
3136

3237
- repo: https://github.com/pre-commit/mirrors-mypy
3338
rev: v1.9.0
3439
hooks:
3540
- id: mypy
36-
additional_dependencies: [types-requests, types-setuptools]
41+
additional_dependencies: [types-requests, types-setuptools, types-pyyaml, types-toml]
3742
entry: mypy --config-file dev_config/python/mypy.ini opendevin/ agenthub/
3843
always_run: true
3944
pass_filenames: false

opendevin/config.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
11
import os
2-
import toml # type: ignore
2+
import toml
33

44
from dotenv import load_dotenv
55

66
load_dotenv()
77

88
DEFAULT_CONFIG = {
9-
"LLM_API_KEY": None,
10-
"LLM_BASE_URL": None,
11-
"WORKSPACE_DIR": os.path.join(os.getcwd(), "workspace"),
12-
"LLM_MODEL": "gpt-4-0125-preview",
13-
"SANDBOX_CONTAINER_IMAGE": "ghcr.io/opendevin/sandbox",
14-
"RUN_AS_DEVIN": "false",
15-
"LLM_EMBEDDING_MODEL": "local",
16-
"LLM_NUM_RETRIES": 6,
17-
"LLM_COOLDOWN_TIME" : 1,
18-
"DIRECTORY_REWRITE" : "",
19-
"PROMPT_DEBUG_DIR": "",
20-
"MAX_ITERATIONS": 100,
9+
'LLM_API_KEY': None,
10+
'LLM_BASE_URL': None,
11+
'WORKSPACE_DIR': os.path.join(os.getcwd(), 'workspace'),
12+
'LLM_MODEL': 'gpt-4-0125-preview',
13+
'SANDBOX_CONTAINER_IMAGE': 'ghcr.io/opendevin/sandbox',
14+
'RUN_AS_DEVIN': 'false',
15+
'LLM_EMBEDDING_MODEL': 'local',
16+
'LLM_NUM_RETRIES': 6,
17+
'LLM_COOLDOWN_TIME': 1,
18+
'DIRECTORY_REWRITE': '',
19+
'PROMPT_DEBUG_DIR': '',
20+
'MAX_ITERATIONS': 100,
2121
}
2222

23-
config_str = ""
24-
if os.path.exists("config.toml"):
25-
with open("config.toml", "rb") as f:
26-
config_str = f.read().decode("utf-8")
23+
config_str = ''
24+
if os.path.exists('config.toml'):
25+
with open('config.toml', 'rb') as f:
26+
config_str = f.read().decode('utf-8')
2727

2828
tomlConfig = toml.loads(config_str)
2929
config = DEFAULT_CONFIG.copy()
3030
for key, value in config.items():
31-
if key in os.environ:
32-
config[key] = os.environ[key]
33-
elif key in tomlConfig:
34-
config[key] = tomlConfig[key]
35-
31+
if key in os.environ:
32+
config[key] = os.environ[key]
33+
elif key in tomlConfig:
34+
config[key] = tomlConfig[key]
3635

3736

3837
def _get(key: str, default):
@@ -65,6 +64,7 @@ def get_or_none(key: str):
6564
"""
6665
return _get(key, None)
6766

67+
6868
def get(key: str):
6969
"""
7070
Get a key from the config, please make sure it exists.

tests/test_action_serialization.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from opendevin.action import (
32
action_from_dict,
43
Action,

0 commit comments

Comments
 (0)