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

Ensure that rules collections use Runtime in offline mode #3526

Merged
merged 1 commit into from
Jun 1, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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