Skip to content

Commit

Permalink
refactor(config): search yaml using pathlib.Path.parents (#172)
Browse files Browse the repository at this point in the history
* refactor: search yaml using `pathlib.Path.parents`

Signed-off-by: Pablo Woolvett <pablowoolvett@gmail.com>

* Update config.py
  • Loading branch information
pwoolvett authored Mar 31, 2021
1 parent 2a8a228 commit 6fe8953
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions fixit/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dataclasses import asdict
from functools import lru_cache
from pathlib import Path
from typing import Any, Dict, Optional, Pattern, Set
from typing import Any, Dict, Pattern, Set

import yaml

Expand Down Expand Up @@ -114,23 +114,19 @@ def get_validated_settings(
@lru_cache()
def get_lint_config() -> LintConfig:
config = {}
current_dir = Path.cwd()
previous_dir: Optional[Path] = None
while current_dir != previous_dir:

cwd = Path.cwd()
for directory in (cwd, *cwd.parents):
# Check for config file.
possible_config = current_dir / LINT_CONFIG_FILE_NAME
possible_config = directory / LINT_CONFIG_FILE_NAME
if possible_config.is_file():
with open(possible_config, "r") as f:
file_content = yaml.safe_load(f.read())

if isinstance(file_content, dict):
config = get_validated_settings(file_content, current_dir)
config = get_validated_settings(file_content, directory)
break

# Try to go up a directory.
previous_dir = current_dir
current_dir = current_dir.parent

# Find formatter executable if there is one.
formatter_args = config.get("formatter", DEFAULT_FORMATTER)
exe = distutils.spawn.find_executable(formatter_args[0]) or formatter_args[0]
Expand Down

0 comments on commit 6fe8953

Please sign in to comment.