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

Catch ansible-compat initialization warnings #4463

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import shutil
import site
import sys
import warnings
from pathlib import Path
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -269,39 +270,46 @@
result.matches.pop(idx)


# pylint: disable=too-many-locals
# pylint: disable=too-many-locals,too-many-statements
def main(argv: list[str] | None = None) -> int:
"""Linter CLI entry point."""
# alter PATH if needed (venv support)
path_inject(argv[0] if argv and argv[0] else "")

if argv is None: # pragma: no cover
argv = sys.argv
cache_dir_lock = initialize_options(argv[1:])

reconfigure(colored=options.colored)

if options.version:
deps = get_deps_versions()
msg = f"ansible-lint [repr.number]{__version__}[/] using[dim]"
for k, v in deps.items():
msg += f" {k}:[repr.number]{v}[/]"
msg += "[/]"
console.print(msg)
msg = get_version_warning()
if msg:
console.print(msg)
support_banner()
sys.exit(0)
else:
support_banner()

initialize_logger(options.verbosity)
for level, message in log_entries:
_logger.log(level, message)
_logger.debug("Options: %s", options)
_logger.debug("CWD: %s", Path.cwd())
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter(action="ignore")

cache_dir_lock = initialize_options(argv[1:])

reconfigure(colored=options.colored)

if options.version:
deps = get_deps_versions()
msg = f"ansible-lint [repr.number]{__version__}[/] using[dim]"
for k, v in deps.items():
msg += f" {k}:[repr.number]{v}[/]"
msg += "[/]"
console.print(msg)
msg = get_version_warning()
if msg:
console.print(msg)

Check warning on line 298 in src/ansiblelint/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/ansiblelint/__main__.py#L298

Added line #L298 was not covered by tests
support_banner()
sys.exit(0)
else:
support_banner()

initialize_logger(options.verbosity)
for level, message in log_entries:
_logger.log(level, message)
_logger.debug("Options: %s", options)
_logger.debug("CWD: %s", Path.cwd())

for warn in warns:
_logger.warning(str(warn.message))

Check warning on line 311 in src/ansiblelint/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/ansiblelint/__main__.py#L311

Added line #L311 was not covered by tests
warnings.resetwarnings()
# checks if we have `ANSIBLE_LINT_SKIP_SCHEMA_UPDATE` set to bypass schema
# update. Also skip if in offline mode.
# env var set to skip schema refresh
Expand Down
Loading