@@ -528,33 +528,39 @@ def locate_config(root: str) -> str | None:
528
528
config_path = os .path .join (root , f )
529
529
return config_path
530
530
531
- ensure_file_accessible (args .debug_filepath )
532
- # Get preprocessor definitions from config file
533
- pp_suffixes = None
534
- pp_defs = {}
535
- include_dirs = set ()
536
- if args .debug_rootpath :
531
+ def read_config (root : str | None ):
532
+ pp_suffixes = None
533
+ pp_defs = {}
534
+ include_dirs = set ()
535
+ if root is None :
536
+ return pp_suffixes , pp_defs , include_dirs
537
+
537
538
# Check for config files
538
- config_path = locate_config (args .debug_rootpath )
539
- config_exists = os .path .isfile (config_path )
540
- if config_exists :
541
- try :
542
- with open (config_path , encoding = "utf-8" ) as fhandle :
543
- config_dict = json .load (fhandle )
544
- pp_suffixes = config_dict .get ("pp_suffixes" , None )
545
- pp_defs = config_dict .get ("pp_defs" , {})
546
- for path in config_dict .get ("include_dirs" , set ()):
547
- include_dirs .update (
548
- only_dirs (resolve_globs (path , args .debug_rootpath ))
549
- )
550
-
551
- if isinstance (pp_defs , list ):
552
- pp_defs = {key : "" for key in pp_defs }
553
- except ValueError as e :
554
- print (f"Error { e } while parsing '{ args .config } ' settings file" )
539
+ config_path = locate_config (root )
540
+ if not os .path .isfile (config_path ):
541
+ return pp_suffixes , pp_defs , include_dirs
542
+
543
+ try :
544
+ with open (config_path , encoding = "utf-8" ) as fhandle :
545
+ config_dict = json .load (fhandle )
546
+ pp_suffixes = config_dict .get ("pp_suffixes" , None )
547
+ pp_defs = config_dict .get ("pp_defs" , {})
548
+ for path in config_dict .get ("include_dirs" , set ()):
549
+ include_dirs .update (only_dirs (resolve_globs (path , root )))
550
+
551
+ if isinstance (pp_defs , list ):
552
+ pp_defs = {key : "" for key in pp_defs }
553
+ except ValueError as e :
554
+ print (f"Error { e } while parsing '{ config_path } ' settings file" )
555
+
556
+ return pp_suffixes , pp_defs , include_dirs
555
557
556
558
print ("\n Testing parser" )
557
559
separator ()
560
+
561
+ ensure_file_accessible (args .debug_filepath )
562
+ pp_suffixes , pp_defs , include_dirs = read_config (args .debug_rootpath )
563
+
558
564
print (f' File = "{ args .debug_filepath } "' )
559
565
file_obj = FortranFile (args .debug_filepath , pp_suffixes )
560
566
err_str , _ = file_obj .load_from_disk ()
0 commit comments