Skip to content

Commit

Permalink
Ensure that rules collections use Runtime in offline mode (#3526)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jun 1, 2023
1 parent 11d3d18 commit 70d2443
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,12 @@ def main(argv: list[str] | None = None) -> int:
console.print(profiles_as_rich())
return 0

app = get_app(offline=None) # to be sure we use the offline value from settings
rules = RulesCollection(options.rulesdirs, profile_name=options.profile, app=app)

if options.list_rules or options.list_tags:
return _do_list(rules)

app = get_app()
if isinstance(options.tags, str):
options.tags = options.tags.split(",") # pragma: no cover
result = _get_matches(rules, options)
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,10 @@ def _sanitize_list_options(tag_list: list[str]) -> list[str]:


@lru_cache
def get_app() -> App:
def get_app(*, offline: bool | None = None) -> App:
"""Return the application instance, caching the return value."""
offline = default_options.offline
if offline is None:
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
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def __init__(
"""Initialize a RulesCollection instance."""
self.options = options
self.profile = []
self.app = app or get_app()
self.app = app or get_app(offline=True)

if profile_name:
self.profile = PROFILES[profile_name]
Expand Down

0 comments on commit 70d2443

Please sign in to comment.