Deduplicate paths in find_config_files

Signed-off-by: Jörg Behrmann <behrmann@physik.fu-berlin.de>
This commit is contained in:
Joerg Behrmann 2022-08-30 17:08:05 +02:00
parent 4249082eed
commit 1abc5a39ba
1 changed files with 25 additions and 26 deletions

View File

@ -876,35 +876,34 @@ def find_config_files(search_paths: List[str]) -> List[str]:
A list of file paths. A list of file paths.
""" """
config_files = [] config_files = {config_path: [] for config_path in search_paths}
if search_paths: for config_path, files in config_files.items():
for config_path in search_paths: if os.path.isdir(config_path):
if os.path.isdir(config_path): # We accept specifying directories as config paths, we search
# We accept specifying directories as config paths, we search # inside that directory for all files matching *.yaml, and then
# inside that directory for all files matching *.yaml, and then # we apply them in *sorted* order.
# we apply them in *sorted* order. found_files = []
files = [] for entry in os.listdir(config_path):
for entry in os.listdir(config_path): entry_path = os.path.join(config_path, entry)
entry_path = os.path.join(config_path, entry) if not os.path.isfile(entry_path):
if not os.path.isfile(entry_path): err = "Found subdirectory in config directory: %r. IGNORING."
err = "Found subdirectory in config directory: %r. IGNORING." print(err % (entry_path,))
print(err % (entry_path,)) continue
continue
if not entry.endswith(".yaml"): if not entry.endswith(".yaml"):
err = ( err = (
"Found file in config directory that does not end in " "Found file in config directory that does not end in "
"'.yaml': %r. IGNORING." "'.yaml': %r. IGNORING."
) )
print(err % (entry_path,)) print(err % (entry_path,))
continue continue
files.append(entry_path) found_files.append(entry_path)
config_files.extend(sorted(files)) files.extend(sorted(found_files))
else: else:
config_files.append(config_path) files.append(config_path)
return config_files return list(itertools.chain(*config_files.values()))
@attr.s(auto_attribs=True) @attr.s(auto_attribs=True)