3737from  pydantic .fields  import  FieldInfo 
3838from  pydantic_settings  import  BaseSettings , CliSettingsSource , SettingsConfigDict 
3939
40+ import  paperqa .configs 
4041from  paperqa ._ldp_shims  import  (
4142    HAS_LDP_INSTALLED ,
4243    Agent ,
@@ -927,24 +928,25 @@ def from_name(
927928                )
928929            return  Settings (_cli_settings_source = cli_source (args = True ))
929930
930-         # First, try to find the config file in the user's .config directory 
931931        user_config_path  =  pqa_directory ("settings" ) /  f"{ config_name }  
932- 
932+         pkg_config_path  =  (
933+             # Use importlib.resources.files() which is recommended for Python 3.9+ 
934+             importlib .resources .files (paperqa .configs )
935+             /  f"{ config_name }  
936+         )
933937        if  user_config_path .exists ():
938+             # First, try to find the config file in the user's .config directory 
934939            json_path  =  user_config_path 
935- 
936-         # If not found, fall back to the package's default config 
937-         try :
938-             # Use importlib.resources.files() which is recommended for Python 3.9+ 
939-             pkg_config_path  =  (
940-                 importlib .resources .files ("paperqa.configs" ) /  f"{ config_name }  
941-             )
942-             if  pkg_config_path .is_file ():
943-                 json_path  =  cast ("pathlib.Path" , pkg_config_path )
944-         except  FileNotFoundError  as  e :
945-             raise  FileNotFoundError (
946-                 f"No configuration file found for { config_name }  
947-             ) from  e 
940+         else :
941+             # If not found, fall back to the package's default config 
942+             try :
943+                 if  pkg_config_path .is_file ():
944+                     json_path  =  cast ("pathlib.Path" , pkg_config_path )
945+             except  FileNotFoundError  as  e :
946+                 raise  FileNotFoundError (
947+                     f"No configuration file { config_name !r}  
948+                     f" { user_config_path } { pkg_config_path }  
949+                 ) from  e 
948950
949951        if  json_path :
950952            # we do the ole switcheroo 
@@ -956,8 +958,10 @@ def from_name(
956958                ** (tmp .model_dump ()),
957959                _cli_settings_source = cli_source (args = True ) if  cli_source  else  None ,
958960            )
959- 
960-         raise  FileNotFoundError (f"No configuration file found for { config_name }  )
961+         raise  FileNotFoundError (
962+             f"No configuration file { config_name !r}  
963+             f" { user_config_path } { pkg_config_path }  
964+         )
961965
962966    def  get_llm (self ) ->  LiteLLMModel :
963967        return  LiteLLMModel (
0 commit comments