Skip to content

Commit bc9c7fd

Browse files
committedOct 7, 2021
Refactor the find_all_configs function
1 parent 2f2bc56 commit bc9c7fd

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed
 

‎isort/settings.py

+25-21
Original file line numberDiff line numberDiff line change
@@ -787,28 +787,32 @@ def _find_config(path: str) -> Tuple[str, Dict[str, Any]]:
787787

788788

789789
@lru_cache()
790-
def find_all_configs(src_paths: Tuple[str]) -> Trie:
791-
trie_root = Trie("default", DEFAULT_CONFIG.__dict__)
792-
793-
for path in src_paths:
794-
for (dirpath, _, _) in os.walk(path):
795-
for config_file_name in CONFIG_SOURCES:
796-
potential_config_file = os.path.join(dirpath, config_file_name)
797-
if os.path.isfile(potential_config_file):
798-
config_data: Dict[str, Any]
799-
try:
800-
config_data = _get_config_data(
801-
potential_config_file, CONFIG_SECTIONS[config_file_name]
802-
)
803-
except Exception:
804-
warn(
805-
f"Failed to pull configuration information from {potential_config_file}"
806-
)
807-
config_data = {}
790+
def find_all_configs(path: str) -> Trie:
791+
"""
792+
Looks for config files in the path provided and in all of its sub-directories.
793+
Parses and stores any config file encountered in a trie and returns the root of
794+
the trie
795+
"""
796+
trie_root = Trie("default", {})
808797

809-
if config_data:
810-
trie_root.insert(potential_config_file, config_data)
811-
break
798+
for (dirpath, _, _) in os.walk(path):
799+
for config_file_name in CONFIG_SOURCES:
800+
potential_config_file = os.path.join(dirpath, config_file_name)
801+
if os.path.isfile(potential_config_file):
802+
config_data: Dict[str, Any]
803+
try:
804+
config_data = _get_config_data(
805+
potential_config_file, CONFIG_SECTIONS[config_file_name]
806+
)
807+
except Exception:
808+
warn(
809+
f"Failed to pull configuration information from {potential_config_file}"
810+
)
811+
config_data = {}
812+
813+
if config_data:
814+
trie_root.insert(potential_config_file, config_data)
815+
break
812816

813817
return trie_root
814818

0 commit comments

Comments
 (0)
Please sign in to comment.