def find_user_config(file_path, max_trials=10):
 file_path = os.path.normpath(os.path.abspath(os.path.expanduser(file_path)))
 old_dir = None
 base_dir = (file_path if os.path.isdir(file_path) else os.path.dirname(file_path))
 home_dir = os.path.expanduser('~')
 while ((base_dir != old_dir) and (old_dir != home_dir) and (max_trials != 0)):
  config_file = os.path.join(base_dir, '.coafile')
  if os.path.isfile(config_file):
   return config_file
  old_dir = base_dir
  base_dir = os.path.dirname(old_dir)
  max_trials = (max_trials - 1)
 return ''

def find_user_config ( file_path , max_trials = 10 ) : file_path = os . path . normpath ( os . path . abspath ( os . path . expanduser ( file_path ) ) ) old_dir = None base_dir = ( file_path if os . path . isdir ( file_path ) else os . path . dirname ( file_path ) ) home_dir = os . path . expanduser ( '~' ) while ( ( base_dir != old_dir ) and ( old_dir != home_dir ) and ( max_trials != 0 ) ) : config_file = os . path . join ( base_dir , '.coafile' ) if os . path . isfile ( config_file ) : return config_file old_dir = base_dir base_dir = os . path . dirname ( old_dir ) max_trials = ( max_trials - 1 ) return ''
uses the filepath to find the most suitable user config file for the file by going down one directory at a time and finding config files there .