diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index 8630746d2b..dfdbc7dfd7 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -211,7 +211,7 @@ def main(argv: list[str] | None = None) -> int: # noqa: C901 if options.listrules or options.listtags: return _do_list(rules) - app = get_app(offline=options.offline) + app = get_app() if isinstance(options.tags, str): options.tags = options.tags.split(",") result = _get_matches(rules, options) diff --git a/src/ansiblelint/app.py b/src/ansiblelint/app.py index 479b3af5f8..7fae8e0fe5 100644 --- a/src/ansiblelint/app.py +++ b/src/ansiblelint/app.py @@ -325,9 +325,10 @@ def _sanitize_list_options(tag_list: list[str]) -> list[str]: return sorted(set(tags)) -@lru_cache(maxsize=1) -def get_app(offline: bool = False) -> App: - """Return the application instance.""" +@lru_cache +def get_app() -> App: + """Return the application instance, caching the return value.""" + offline = default_options.offline app = App(options=default_options) # Make linter use the cache dir from compat default_options.cache_dir = app.runtime.cache_dir diff --git a/src/ansiblelint/rules/syntax_check.py b/src/ansiblelint/rules/syntax_check.py index 402e99d7d7..32d5b1e1c6 100644 --- a/src/ansiblelint/rules/syntax_check.py +++ b/src/ansiblelint/rules/syntax_check.py @@ -93,7 +93,7 @@ def _get_ansible_syntax_check_matches(lintable: Lintable) -> list[MatchError]: # To reduce noisy warnings like # CryptographyDeprecationWarning: Blowfish has been deprecated # https://github.com/paramiko/paramiko/issues/2038 - env = get_app(offline=True).runtime.environ.copy() + env = get_app().runtime.environ.copy() env["PYTHONWARNINGS"] = "ignore" run = subprocess.run( diff --git a/src/ansiblelint/testing/__init__.py b/src/ansiblelint/testing/__init__.py index 3eeff7c2f8..ec66479e0b 100644 --- a/src/ansiblelint/testing/__init__.py +++ b/src/ansiblelint/testing/__init__.py @@ -33,7 +33,7 @@ def __init__(self, collection: RulesCollection) -> None: # Emulate command line execution initialization as without it Ansible module # would be loaded with incomplete module/role/collection list. if not self.app: - self.app = get_app(offline=True) + self.app = get_app() self.collection = collection diff --git a/src/ansiblelint/utils.py b/src/ansiblelint/utils.py index 34266258cf..22fe2f85b5 100644 --- a/src/ansiblelint/utils.py +++ b/src/ansiblelint/utils.py @@ -472,7 +472,7 @@ def _rolepath(basedir: str, role: str) -> str | None: path_dwim(basedir, os.path.join("..", role)), ] - for loc in get_app(offline=True).runtime.config.default_roles_path: + for loc in get_app().runtime.config.default_roles_path: loc = os.path.expanduser(loc) possible_paths.append(path_dwim(loc, role))