Skip to content

Commit 6b06e51

Browse files
codelionCTY-git
andauthored
Update GenerateDocstring.py (#193)
* Update GenerateDocstring.py * Update * better ignore --------- Co-authored-by: TIANYOU CHEN <42710806+CTY-git@users.noreply.github.com>
1 parent 2b4195e commit 6b06e51

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

patchwork/common/ignore.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
1+
import itertools
2+
from itertools import chain
3+
from pathlib import Path
4+
from typing import Iterable
5+
6+
# switch to pure globs once https://github.com/python/cpython/issues/73435 is resolved
17
IGNORE_DIRS = {
28
".git",
39
".idea",
410
"__pycache__",
11+
".mvn",
12+
}
13+
14+
IGNORE_EXTS_GLOBS = {
15+
"*.pyc",
16+
"*.pyo",
17+
"*.pyd",
18+
"*.whl",
19+
"*.egg",
20+
"*.egg-info",
21+
"*.dist-info",
522
}
623

7-
IGNORE_EXTS = {
8-
".pyc",
9-
".pyo",
10-
".pyd",
11-
".whl",
12-
".egg",
13-
".egg-info",
14-
".dist-info",
24+
IGNORE_FILES_GLOBS = {
25+
"requirements.txt",
26+
"requirements-dev.txt",
27+
"requirements-test.txt",
28+
"mvnw",
29+
"mvnw.cmd",
30+
"gradlew",
31+
"gradlew.bat",
1532
}
33+
34+
35+
def is_ignored(file_path: Path, ignored_dirs: Iterable[str] | None = None, *globs: Iterable[str]) -> bool:
36+
final_ignore_globs = globs if globs else itertools.chain(IGNORE_EXTS_GLOBS, IGNORE_FILES_GLOBS)
37+
final_ignored_dirs = ignored_dirs if ignored_dirs else IGNORE_DIRS
38+
return (any(file_path.match(ignore_glob) for ignore_glob in final_ignore_globs) or
39+
any(ignore_dir in file_path.parts[:-1] for ignore_dir in final_ignored_dirs))

patchwork/patchflows/GenerateDocstring/GenerateDocstring.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def __init__(self, inputs: dict):
3434
final_inputs["branch_prefix"] = f"{self.__class__.__name__.lower()}-"
3535
final_inputs["context_grouping"] = "FUNCTION"
3636
final_inputs["allow_overlap_contexts"] = False
37-
37+
final_inputs["force_code_contexts"] = final_inputs.get("rewrite_existing", False)
38+
3839
self.inputs: dict[str, Any] = final_inputs
3940

4041
def run(self) -> dict:

patchwork/patchflows/GenerateDocstring/defaults.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# GenerateDocstring Inputs
22
base_path: .
3+
rewrite_existing: false
34

45
# CallLLM Inputs
56
# For OpenAI API use the following the select the model

patchwork/steps/ExtractCodeContexts/ExtractCodeContexts.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from patchwork.common.context_strategy.context_strategies import ContextStrategies
55
from patchwork.common.context_strategy.position import Position
6-
from patchwork.common.ignore import IGNORE_DIRS, IGNORE_EXTS
6+
from patchwork.common.ignore import is_ignored
77
from patchwork.logger import logger
88
from patchwork.step import Step
99

@@ -81,15 +81,9 @@ def run(self) -> dict:
8181
if self.base_path.is_file():
8282
files_to_consider.append(self.base_path)
8383
for root, dirs, files in os.walk(self.base_path):
84-
root_path = Path(root)
85-
if IGNORE_DIRS.intersection(root_path.parents):
86-
continue
87-
8884
for file in files:
89-
if any(file.endswith(ext) for ext in IGNORE_EXTS):
90-
continue
91-
file_path = root_path / file
92-
if not file_path.is_file():
85+
file_path = Path(root) / file
86+
if not file_path.is_file() or is_ignored(file_path):
9387
continue
9488
files_to_consider.append(file_path)
9589

0 commit comments

Comments
 (0)