Skip to content

Commit

Permalink
add CI fix tool to app
Browse files Browse the repository at this point in the history
  • Loading branch information
XianBW committed May 24, 2024
1 parent 037ef5d commit b6a1f90
Show file tree
Hide file tree
Showing 10 changed files with 586 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ mypy:

# Check lint with ruff.
ruff:
$(PIPRUN) python -m ruff . --exclude FinCo,finco,rdagent/scripts,test/scripts,git_ignore_folder --ignore ANN101,ANN401,TCH003,D,ERA001,PLR0913,S101 --line-length 120
$(PIPRUN) ruff check . --exclude FinCo,finco,rdagent/scripts,test/scripts,git_ignore_folder

# Check lint with toml-sort.
toml-sort:
$(PIPRUN) toml-sort --check pyproject.toml

# Check lint with all linters.
lint: black isort mypy ruff toml-sort
lint: mypy ruff toml-sort

# Run pre-commit with autofix against all files.
pre-commit:
Expand Down
2 changes: 1 addition & 1 deletion constraints/3.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ rfc3986==2.0.0
rich==13.7.0
ruamel.yaml==0.18.5
ruamel.yaml.clib==0.2.8
ruff==0.1.9
ruff==0.4.5
scipy==1.11.4
SecretStorage==3.3.3
semver==3.0.2
Expand Down
2 changes: 1 addition & 1 deletion constraints/3.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ rfc3986==2.0.0
rich==13.7.0
ruamel.yaml==0.18.5
ruamel.yaml.clib==0.2.8
ruff==0.1.9
ruff==0.4.5
scipy==1.11.4
SecretStorage==3.3.3
semver==3.0.2
Expand Down
2 changes: 1 addition & 1 deletion constraints/3.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ rfc3986==2.0.0
rich==13.7.0
ruamel.yaml==0.18.5
ruamel.yaml.clib==0.2.8
ruff==0.1.9
ruff==0.4.5
scipy==1.10.1
SecretStorage==3.3.3
semver==3.0.2
Expand Down
2 changes: 1 addition & 1 deletion constraints/3.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ rfc3986==2.0.0
rich==13.7.0
ruamel.yaml==0.18.5
ruamel.yaml.clib==0.2.8
ruff==0.1.9
ruff==0.4.5
scipy==1.11.4
SecretStorage==3.3.3
semver==3.0.2
Expand Down
26 changes: 11 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,28 @@ log_format = "%(asctime)s %(levelname)s %(message)s"
minversion = "6.0"

[tool.ruff]
fix = true
line-length = 120
src = ["src"]

[tool.ruff.lint]
ignore = [
# https://docs.astral.sh/ruff/rules/#pydocstyle-d
"D203",
"D204",
"D213",
"D215",
"D400",
"D404",
"D406",
"D407",
"D408",
"D409",
"D413",
"ANN101",
"ANN401",
"TCH003",
"D",
"ERA001",
"FIX",
"INP001",
"PGH",
"PLR0913",
"S101",
"T20",
"TCH003",
"TD",
]
select = ["ALL"]
src = ["rdagent"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"docs/conf.py" = ["INP001"]
"test/*" = ["S101"]

Expand Down
99 changes: 99 additions & 0 deletions rdagent/app/CI/prompts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
linting_system_prompt_template = "You are a software engineer. You can write code to a high standard and are adept at solving {language} linting problems."


user_get_makefile_lint_commands_template = """You get a Makefile which contains some linting rules. Here are its content ```{file_text}```
Please find executable commands about linting from it.
Please response with following json template:
{{
"commands": <python -m xxx --params >,
}}
"""

user_get_files_contain_lint_commands_template = """You get a file list of a repository. Some file maybe contain linting rules or linting commands which defined by repo authors. Here are the file list ```{file_list}```
Please find all files maybe correspond to linting from it.
Please response with following json template:
{{
"files": </path/to/file>,
}}
"""


generate_lint_command_template = """Please generate a command to lint or format a {language} repository. Here are some information about different linting tools ```{linting_tools}```
"""


suffix2language_template = """Here are the files suffix in one code repo: {suffix}. Please tell me the programming language used in this repo and which language has linting-tools.
Your response should follow this template:
{{
"languages": <languages list>,
"languages_with_linting_tools": <languages with lingting tools list>
}}
"""


session_start_template = """Please modify the Python code based on the lint info. Due to the length of the code, I will first tell you the entire code, and then each time I ask a question, I will extract a portion of the code and tell you the error information contained in this code segment. You need to fix the corresponding error in the code segment and return the code that can replace the corresponding code segment.
The Python code is from a complete Python project file. Each line of the code is annotated with a line number, separated from the original code by three characters ("<white space>|<white space>"). The vertical bars are aligned.
Here is the complete code, please be prepared to fix it:
```Python
{code}
```
"""


session_normal_template = """Please modify this code snippet based on the lint info. Here is the code snippet:
```Python
{code}
```
-----Lint info-----
{lint_info}
-------------------
The lint info contains one or more errors. Different errors are separated by blank lines. Each error follows this format:
-----Lint info format-----
<Line Number>:<Error Start Position> <Error Code> <Error Message>
<Error Context (multiple lines)>
<Helpful Information (last line)>
--------------------------
The error code is an abbreviation set by the checker for ease of describing the error. The error context includes the relevant code around the error, and the helpful information suggests possible fixes.
Please simply reply the code after you fix all linting errors.
The code you return does not require line numbers, and should just replace the code I provided you, and does not require comments.
Please wrap your code with following format:
```python
<your code..>
```
"""


user_template_for_code_snippet = """Please modify the Python code based on the lint info.
-----Python Code-----
{code}
---------------------
-----Lint info-----
{lint_info}
-------------------
The Python code is a snippet from a complete Python project file. Each line of the code is annotated with a line number, separated from the original code by three characters ("<white space>|<white space>"). The vertical bars are aligned.
The lint info contains one or more errors. Different errors are separated by blank lines. Each error follows this format:
-----Lint info format-----
<Line Number>:<Error Start Position> <Error Code> <Error Message>
<Error Context (multiple lines)>
<Helpful Information (last line)>
--------------------------
The error code is an abbreviation set by the checker for ease of describing the error. The error context includes the relevant code around the error, and the helpful information suggests possible fixes.
Please simply reply the code after you fix all linting errors.
The code you return does not require line numbers, and should just replace the code I provided you, and does not require comments.
Please wrap your code with following format:
```python
<your code..>
```
"""
Loading

0 comments on commit b6a1f90

Please sign in to comment.