Skip to content

Commit 0356df8

Browse files
authored
Add async ruff linting and remove flake8 dependency (All-Hands-AI#7539)
1 parent 2d66939 commit 0356df8

File tree

7 files changed

+99
-99
lines changed

7 files changed

+99
-99
lines changed

dev_config/python/ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ select = [
66
"I",
77
"Q",
88
"B",
9+
"ASYNC",
910
]
1011

1112
ignore = [

openhands/core/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def on_event(event: Event):
211211
file_path = config.save_trajectory_path
212212
os.makedirs(os.path.dirname(file_path), exist_ok=True)
213213
histories = controller.get_trajectory(config.save_screenshots_in_trajectory)
214-
with open(file_path, 'w') as f:
214+
with open(file_path, 'w') as f: # noqa: ASYNC101
215215
json.dump(histories, f, indent=4)
216216

217217
return state

openhands/resolver/resolve_all_issues.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async def resolve_issues(
111111
# checkout the repo
112112
repo_dir = os.path.join(output_dir, 'repo')
113113
if not os.path.exists(repo_dir):
114-
checkout_output = subprocess.check_output(
114+
checkout_output = subprocess.check_output( # noqa: ASYNC101
115115
[
116116
'git',
117117
'clone',
@@ -124,7 +124,7 @@ async def resolve_issues(
124124

125125
# get the commit id of current repo for reproducibility
126126
base_commit = (
127-
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir)
127+
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir) # noqa: ASYNC101
128128
.decode('utf-8')
129129
.strip()
130130
)
@@ -134,22 +134,22 @@ async def resolve_issues(
134134
# Check for .openhands_instructions file in the workspace directory
135135
openhands_instructions_path = os.path.join(repo_dir, '.openhands_instructions')
136136
if os.path.exists(openhands_instructions_path):
137-
with open(openhands_instructions_path, 'r') as f:
137+
with open(openhands_instructions_path, 'r') as f: # noqa: ASYNC101
138138
repo_instruction = f.read()
139139

140140
# OUTPUT FILE
141141
output_file = os.path.join(output_dir, 'output.jsonl')
142142
logger.info(f'Writing output to {output_file}')
143143
finished_numbers = set()
144144
if os.path.exists(output_file):
145-
with open(output_file, 'r') as f:
145+
with open(output_file, 'r') as f: # noqa: ASYNC101
146146
for line in f:
147147
data = ResolverOutput.model_validate_json(line)
148148
finished_numbers.add(data.issue.number)
149149
logger.warning(
150150
f'Output file {output_file} already exists. Loaded {len(finished_numbers)} finished issues.'
151151
)
152-
output_fp = open(output_file, 'a')
152+
output_fp = open(output_file, 'a') # noqa: ASYNC101
153153

154154
logger.info(
155155
f'Resolving issues with model {model_name}, max iterations {max_iterations}.'
@@ -182,13 +182,13 @@ async def resolve_issues(
182182
f'Checking out to PR branch {issue.head_branch} for issue {issue.number}'
183183
)
184184

185-
subprocess.check_output(
185+
subprocess.check_output( # noqa: ASYNC101
186186
['git', 'checkout', f'{issue.head_branch}'],
187187
cwd=repo_dir,
188188
)
189189

190190
base_commit = (
191-
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir)
191+
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir) # noqa: ASYNC101
192192
.decode('utf-8')
193193
.strip()
194194
)

openhands/resolver/resolve_issue.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ async def resolve_issue(
429429
# checkout the repo
430430
repo_dir = os.path.join(output_dir, 'repo')
431431
if not os.path.exists(repo_dir):
432-
checkout_output = subprocess.check_output(
432+
checkout_output = subprocess.check_output( # noqa: ASYNC101
433433
[
434434
'git',
435435
'clone',
@@ -442,7 +442,7 @@ async def resolve_issue(
442442

443443
# get the commit id of current repo for reproducibility
444444
base_commit = (
445-
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir)
445+
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir) # noqa: ASYNC101
446446
.decode('utf-8')
447447
.strip()
448448
)
@@ -452,7 +452,7 @@ async def resolve_issue(
452452
# Check for .openhands_instructions file in the workspace directory
453453
openhands_instructions_path = os.path.join(repo_dir, '.openhands_instructions')
454454
if os.path.exists(openhands_instructions_path):
455-
with open(openhands_instructions_path, 'r') as f:
455+
with open(openhands_instructions_path, 'r') as f: # noqa: ASYNC101
456456
repo_instruction = f.read()
457457

458458
# OUTPUT FILE
@@ -461,7 +461,7 @@ async def resolve_issue(
461461

462462
# Check if this issue was already processed
463463
if os.path.exists(output_file):
464-
with open(output_file, 'r') as f:
464+
with open(output_file, 'r') as f: # noqa: ASYNC101
465465
for line in f:
466466
data = ResolverOutput.model_validate_json(line)
467467
if data.issue.number == issue_number:
@@ -470,7 +470,7 @@ async def resolve_issue(
470470
)
471471
return
472472

473-
output_fp = open(output_file, 'a')
473+
output_fp = open(output_file, 'a') # noqa: ASYNC101
474474

475475
logger.info(
476476
f'Resolving issue {issue_number} with Agent {AGENT_CLASS}, model {model_name}, max iterations {max_iterations}.'
@@ -489,20 +489,20 @@ async def resolve_issue(
489489

490490
# Fetch the branch first to ensure it exists locally
491491
fetch_cmd = ['git', 'fetch', 'origin', branch_to_use]
492-
subprocess.check_output(
492+
subprocess.check_output( # noqa: ASYNC101
493493
fetch_cmd,
494494
cwd=repo_dir,
495495
)
496496

497497
# Checkout the branch
498498
checkout_cmd = ['git', 'checkout', branch_to_use]
499-
subprocess.check_output(
499+
subprocess.check_output( # noqa: ASYNC101
500500
checkout_cmd,
501501
cwd=repo_dir,
502502
)
503503

504504
base_commit = (
505-
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir)
505+
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir) # noqa: ASYNC101
506506
.decode('utf-8')
507507
.strip()
508508
)

openhands/runtime/action_execution_server.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ async def read(self, action: FileReadAction) -> Observation:
375375
filepath = self._resolve_path(action.path, working_dir)
376376
try:
377377
if filepath.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
378-
with open(filepath, 'rb') as file:
378+
with open(filepath, 'rb') as file: # noqa: ASYNC101
379379
image_data = file.read()
380380
encoded_image = base64.b64encode(image_data).decode('utf-8')
381381
mime_type, _ = mimetypes.guess_type(filepath)
@@ -385,13 +385,13 @@ async def read(self, action: FileReadAction) -> Observation:
385385

386386
return FileReadObservation(path=filepath, content=encoded_image)
387387
elif filepath.lower().endswith('.pdf'):
388-
with open(filepath, 'rb') as file:
388+
with open(filepath, 'rb') as file: # noqa: ASYNC101
389389
pdf_data = file.read()
390390
encoded_pdf = base64.b64encode(pdf_data).decode('utf-8')
391391
encoded_pdf = f'data:application/pdf;base64,{encoded_pdf}'
392392
return FileReadObservation(path=filepath, content=encoded_pdf)
393393
elif filepath.lower().endswith(('.mp4', '.webm', '.ogg')):
394-
with open(filepath, 'rb') as file:
394+
with open(filepath, 'rb') as file: # noqa: ASYNC101
395395
video_data = file.read()
396396
encoded_video = base64.b64encode(video_data).decode('utf-8')
397397
mime_type, _ = mimetypes.guess_type(filepath)
@@ -401,7 +401,7 @@ async def read(self, action: FileReadAction) -> Observation:
401401

402402
return FileReadObservation(path=filepath, content=encoded_video)
403403

404-
with open(filepath, 'r', encoding='utf-8') as file:
404+
with open(filepath, 'r', encoding='utf-8') as file: # noqa: ASYNC101
405405
lines = read_lines(file.readlines(), action.start, action.end)
406406
except FileNotFoundError:
407407
return ErrorObservation(
@@ -434,7 +434,7 @@ async def write(self, action: FileWriteAction) -> Observation:
434434

435435
mode = 'w' if not file_exists else 'r+'
436436
try:
437-
with open(filepath, mode, encoding='utf-8') as file:
437+
with open(filepath, mode, encoding='utf-8') as file: # noqa: ASYNC101
438438
if mode != 'w':
439439
all_lines = file.readlines()
440440
new_file = insert_lines(insert, all_lines, action.start, action.end)
@@ -651,7 +651,7 @@ async def upload_file(
651651
)
652652

653653
zip_path = os.path.join(full_dest_path, file.filename)
654-
with open(zip_path, 'wb') as buffer:
654+
with open(zip_path, 'wb') as buffer: # noqa: ASYNC101
655655
shutil.copyfileobj(file.file, buffer)
656656

657657
# Extract the zip file
@@ -664,7 +664,7 @@ async def upload_file(
664664
else:
665665
# For single file uploads
666666
file_path = os.path.join(full_dest_path, file.filename)
667-
with open(file_path, 'wb') as buffer:
667+
with open(file_path, 'wb') as buffer: # noqa: ASYNC101
668668
shutil.copyfileobj(file.file, buffer)
669669
logger.debug(f'Uploaded file {file.filename} to {destination}')
670670

0 commit comments

Comments
 (0)