From bc788736a74a99e1646dc9c4483309c103a0ca11 Mon Sep 17 00:00:00 2001 From: Jan Hermann Date: Tue, 2 Feb 2021 09:33:39 +0100 Subject: [PATCH] fix config file search when stdin --- fprettify/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fprettify/__init__.py b/fprettify/__init__.py index d6450a3..fb8fdb9 100644 --- a/fprettify/__init__.py +++ b/fprettify/__init__.py @@ -1929,10 +1929,10 @@ def str2bool(str): else: return None - def get_config_file_list(filename): + def get_config_file_list(start_dir): """helper function to create list of config files found in parent directories""" config_file_list = [] - dir = os.path.dirname(filename) + dir = start_dir while True: config_file = os.path.join(dir, '.fprettify.rc') if os.path.isfile(config_file): @@ -2095,7 +2095,8 @@ def build_ws_dict(args): # reparse arguments using the file's list of config files filearguments = arguments if argparse.__name__ == "configargparse": - filearguments['default_config_files'] = ['~/.fprettify.rc'] + get_config_file_list(os.path.abspath(filename) if filename != '-' else os.getcwd()) + filearguments['default_config_files'] = ['~/.fprettify.rc'] \ + + get_config_file_list(os.path.dirname(os.path.abspath(filename)) if filename != '-' else os.getcwd()) file_argparser = get_arg_parser(filearguments) file_args = file_argparser.parse_args(argv[1:]) ws_dict = build_ws_dict(file_args)