-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Perform lint repair on generated test code
- Loading branch information
Showing
5 changed files
with
250 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import subprocess | ||
|
||
|
||
# Lint the file and return a dictionary of line numbers with lint errors. | ||
def lint(lint_command: list) -> dict: | ||
lint_result = subprocess.run( | ||
lint_command, capture_output=True, shell=False, text=True | ||
) | ||
|
||
lint_output = lint_result.stdout | ||
lint_errors = lint_output.split("\n") | ||
|
||
# Lint errors are formatted like this: | ||
# bin/solve.py:257:80: E501 line too long (231 > 79 characters) | ||
# Collect the line numbers of the lint errors. | ||
lint_errors_by_line_number = {} | ||
for error in lint_errors: | ||
if error: | ||
tokens = error.split(":") | ||
if len(tokens) > 1: | ||
line_number = tokens[1] | ||
if line_number and line_number.isdigit(): | ||
lint_errors_by_line_number[int(line_number)] = error | ||
|
||
return lint_errors_by_line_number | ||
|
||
|
||
def lint_in_conda(conda_path, conda_env, lint_command, file): | ||
return lint( | ||
[ | ||
"bash", | ||
"-c", | ||
f". {conda_path}/bin/activate {conda_env} && {lint_command} {file}", | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.