2020
2121pylint_scores = {}
2222
23-
2423def my_custom_logger (logger_name , level = logging .DEBUG ):
2524 """
2625 Method to return a custom logger with the given name and level
@@ -30,20 +29,23 @@ def my_custom_logger(logger_name, level=logging.DEBUG):
3029 format_string = ("%(asctime)s — %(name)s — %(levelname)s — %(funcName)s:"
3130 "%(lineno)d — %(message)s" )
3231 log_format = logging .Formatter (format_string )
32+
3333 # Creating and adding the console handler
3434 console_handler = logging .StreamHandler (sys .stdout )
3535 console_handler .setFormatter (log_format )
3636 logger .addHandler (console_handler )
37+
3738 # Creating and adding the file handler
3839 file_handler = logging .FileHandler (logger_name , mode = 'a' )
3940 file_handler .setFormatter (log_format )
4041 logger .addHandler (file_handler )
42+
4143 return logger
4244
4345def ensure_directories ():
4446 """Create necessary directories for file organization."""
4547 base_dir = Path (__file__ ).parent
46- dirs = ['test_files' , 'fixed_files' , 'backup_files' , 'fixed_files_without_comments' , 'test_files_without_comment' , ' output_logs' ]
48+ dirs = ['test_files' , 'fixed_files' , 'backup_files' , 'output_logs' ]
4749 for dir_name in dirs :
4850 (base_dir / dir_name ).mkdir (exist_ok = True )
4951 return base_dir
@@ -54,29 +56,24 @@ def get_test_cases():
5456 Returns:
5557 list: A list of dictionaries containing file name and content
5658 """
57- try :
58- test_cases = []
59- test_files_dir = Path (__file__ ).parent / 'test_files'
60-
61- # Create test_files directory if it doesn't exist
62- test_files_dir .mkdir (exist_ok = True )
63-
64- # Read all .py files from test_files directory
65- for test_file in test_files_dir .glob ('*.py' ):
66- with open (test_file , 'r' , encoding = 'utf-8' ) as f :
67- test_cases .append ({
68- 'name' : test_file .name ,
69- 'content' : f
70- })
71-
72- if not test_cases :
73- print ("Warning: No test files found in test_files directory" )
74- # Fallback to default test case
75-
76- return test_cases
77- except Exception as e :
78- print (f"Error reading test cases from local directory: { e } " )
79- return []
59+ test_cases = []
60+ test_files_dir = Path (__file__ ).parent / 'test_files'
61+
62+ # Create test_files directory if it doesn't exist
63+ test_files_dir .mkdir (exist_ok = True )
64+
65+ # Read all .py files from test_files directory
66+ for test_file in test_files_dir .glob ('*.py' ):
67+ with open (test_file , 'r' , encoding = 'utf-8' ) as f :
68+ test_cases .append ({
69+ 'name' : test_file .name ,
70+ 'content' : f
71+ })
72+
73+ if not test_cases :
74+ print ("Warning: No test files found in test_files directory" )
75+
76+ return test_cases
8077
8178def fix_file (file_path : str , logger ) -> dict :
8279 """
@@ -92,7 +89,6 @@ def fix_file(file_path: str, logger) -> dict:
9289
9390 # Define output paths
9491 fixed_path = base_dir / 'fixed_files' / f"{ file_name } _fixed_{ datetime .now ().strftime ('%Y%m%d_%H%M%S' )} .py"
95- # fixed_path = base_dir / 'fixed_files_without_comments' / f"{file_name}_fixed.{datetime.now().strftime('%Y%m%d_%H%M%S')}.py"
9692
9793 # Read the original content
9894 with open (file_path , 'r' , encoding = 'utf-8' ) as f :
@@ -188,21 +184,19 @@ def run_pylint(file_path: str, logger) -> dict:
188184 if not pylintrc_path .exists ():
189185 raise FileNotFoundError (f"pylintrc not found at { pylintrc_path } " )
190186
191- # Create string buffer for JSON output
192- output = StringIO ()
193- reporter = JSONReporter (output )
194-
195187 # Run pylint with configuration
196188 results = Run (
197189 [
198190 str (file_path ),
199191 f'--rcfile={ pylintrc_path } ' ,
200192 '--output-format=json'
201193 ],
202- reporter = reporter ,
203194 exit = False
204195 )
205196
197+ messages = results .linter .reporter .messages
198+ logger .debug (f"PYLINT MESSAGES: { messages } " )
199+
206200 logger .debug (f"PYLINT SCORE: { results .linter .stats .global_note } " )
207201 pylint_name = file_path .split ("/" )[- 1 ].split (".py" )[0 ]
208202 try :
@@ -229,7 +223,6 @@ def run_pylint(file_path: str, logger) -> dict:
229223 logger = my_custom_logger (f"Logger_{ test_case ['name' ]} _{ next } .log" )
230224 logger .debug (test_case ['name' ])
231225 file_path = Path (__file__ ).parent / 'test_files' / test_case ['name' ]
232- # file_path = Path(__file__).parent / 'test_files_without_comment' / test_case['name']
233226
234227 print (f"Processing file: { file_path } " )
235228
@@ -238,7 +231,6 @@ def run_pylint(file_path: str, logger) -> dict:
238231 original_pylint = run_pylint (str (file_path ), logger )
239232 logger .debug ("-----" * 80 )
240233
241-
242234 fixed_pylint = original_pylint
243235 counter = 0
244236 while fixed_pylint != 10 and counter < 3 :
0 commit comments