Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assure project_dir is always valid #1482

Merged
merged 1 commit into from Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/ansiblelint/cli.py
Expand Up @@ -187,7 +187,7 @@ def get_cli_parser() -> argparse.ArgumentParser:
parser.add_argument(
'--project-dir',
dest='project_dir',
default=None,
default=".",
help="Location of project/repository, autodetected based on location "
" of configuration file.",
)
Expand Down Expand Up @@ -324,7 +324,7 @@ def merge_config(file_config: Dict[Any, Any], cli_config: Namespace) -> Namespac
'enable_list': [],
}

scalar_map = {"loop_var_prefix": None, "project_dir": None}
scalar_map = {"loop_var_prefix": None, "project_dir": "."}

if not file_config:
# use defaults if we don't have a config file and the commandline
Expand Down 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 options.project_dir or 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
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