You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix first-run collection discovery by gating plugin loader initialization (#516)
* fix: gate plugin loader initialization to prevent early collection path capture
Fixes first-run collection discovery issue where ansible-lint fails to find
plugins from collections installed during prepare_environment().
The problem occurs because Ansible's plugin loader was initialized too early
with incomplete collection paths, before prepare_environment() installs
dependencies from requirements.yml and galaxy.yml files. This particularly
affects Templar usage since it relies on the collection loader for template
rendering and plugin discovery.
Changes:
- Add Runtime.plugin_loader_enabled class variable to gate access
- Add enable_plugin_loader() method for explicit initialization
- Modify Plugins.__getattribute__ to raise RuntimeError if accessed early
- Enhance clean() to reset flags and unload ansible modules for test isolation
- Move plugin loader init from _ensure_module_available() to enable_plugin_loader()
This ensures plugin loader initialization happens after collections are
installed, eliminating the 'works on second run' behavior.
* chore: auto fixes from pre-commit.com hooks
* lint fixes
* deps
* chore: auto fixes from pre-commit.com hooks
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: .config/pydoclint-baseline.txt
-6Lines changed: 0 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -58,10 +58,6 @@ src/ansible_compat/runtime.py
58
58
DOC101: Method `Plugins.__getattribute__`: Docstring contains fewer arguments than in function signature.
59
59
DOC103: Method `Plugins.__getattribute__`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [attr: str].
60
60
DOC201: Method `Plugins.__getattribute__` does not have a return section in docstring
61
-
DOC501: Method `Plugins.__getattribute__` has raise statements, but the docstring does not have a "Raises" section
62
-
DOC503: Method `Plugins.__getattribute__` exceptions in the "Raises" section in the docstring do not match those in the function body. Raised exceptions in the docstring: []. Raised exceptions in the body: ['AnsibleCompatError'].
63
-
DOC601: Class `Runtime`: Class docstring contains fewer class attributes than actual class attributes. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.)
64
-
DOC603: Class `Runtime`: Class docstring attributes are different from actual class attributes. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Attributes in the class definition but not in the docstring: [_has_playbook_cache: dict[tuple[str, Path | None], bool], _version: Version | None, cache_dir: Path, collections: OrderedDict[str, Collection], initialized: bool, plugins: Plugins, require_module: bool]. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.)
65
61
DOC101: Method `Runtime.__init__`: Docstring contains fewer arguments than in function signature.
66
62
DOC103: Method `Runtime.__init__`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [environ: dict[str, str] | None, isolated: bool, max_retries: int, min_required_version: str | None, project_dir: Path | None, require_module: bool, verbosity: int].
67
63
DOC501: Method `Runtime.__init__` has raise statements, but the docstring does not have a "Raises" section
@@ -129,8 +125,6 @@ src/ansible_compat/schema.py
129
125
DOC201: Method `JsonSchemaError.to_friendly` does not have a return section in docstring
130
126
--------------------
131
127
test/conftest.py
132
-
DOC101: Function `runtime`: Docstring contains fewer arguments than in function signature.
133
-
DOC103: Function `runtime`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [scope: str].
134
128
DOC402: Function `runtime` has "yield" statements, but the docstring does not have a "Yields" section
135
129
DOC101: Function `runtime_tmp`: Docstring contains fewer arguments than in function signature.
136
130
DOC103: Function `runtime_tmp`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [scope: str, tmp_path: pathlib.Path].
0 commit comments