Skip to content

Commit

Permalink
Assure project_dir is always valid
Browse files Browse the repository at this point in the history
Avoid case where project_dir could endup being None.
  • Loading branch information
ssbarnea committed Mar 19, 2021
1 parent c76d9d7 commit 10b0cff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/ansiblelint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,18 @@ def get_config(arguments: List[str]) -> Namespace:

options.rulesdirs = get_rules_dirs(options.rulesdir, options.use_default_rules)

if not options.project_dir:
if options.project_dir == ".":
project_dir = os.path.dirname(
os.path.abspath(
options.config_file or f"{guess_project_dir()}/.ansible-lint"
)
)
options.project_dir = normpath(project_dir)
if not os.path.exists(options.project_dir):
raise RuntimeError(
f"Failed to determine a valid project_dir: {options.project_dir}"
)

# print(666, options.quiet, options.verbosity)
# Compute final verbosity level by subtracting -q counter.
options.verbosity -= options.quiet
return config
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
mock_roles=[],
loop_var_prefix=None,
offline=False,
project_dir=None,
project_dir=".", # default should be valid folder (do not use None here)
extra_vars=None,
enable_list=[],
skip_action_validation=True,
Expand Down

0 comments on commit 10b0cff

Please sign in to comment.