File tree Expand file tree Collapse file tree 4 files changed +38
-18
lines changed
patchflows/GenerateDocstring Expand file tree Collapse file tree 4 files changed +38
-18
lines changed Original file line number Diff line number Diff line change 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
17IGNORE_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 ))
Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff line change 11# GenerateDocstring Inputs
22base_path : .
3+ rewrite_existing : false
34
45# CallLLM Inputs
56# For OpenAI API use the following the select the model
Original file line number Diff line number Diff line change 33
44from patchwork .common .context_strategy .context_strategies import ContextStrategies
55from 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
77from patchwork .logger import logger
88from 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
You can’t perform that action at this time.
0 commit comments