ansible / ansible-lint

ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you
https://ansible.readthedocs.io/projects/lint/
GNU General Public License v3.0
3.51k stars 665 forks source link

Add support for distributing rules as python packages (pluggy) #4354

Open wimglenn opened 1 month ago

wimglenn commented 1 month ago

When developing a custom lint rule as described in Packaging Custom Rules, the lint is not available if installed with pip install -e ./my-custom-lint. The same lint is available (and appears in ansible-lint --list-rules) when doing pip install ./my-custom-lint.

I'm using setuptools and the editable installation mode is the thing with an __editable__ .pth file in site-packages which installs a meta-path finder. Trying all modes with --config-settings editable_mode=compat, --config-settings editable_mode=strict, --config-settings editable_mode=lenient, none of them works.

Maybe relevant: unlike the "normal" install, an editable install doesn't create files under .../site-packages/ansiblelint/rules/custom/. I didn't check how ansible-lint discovers custom rules, but perhaps an entry-point group would be worth considering.

alisonlhart commented 1 month ago

We have renamed this and changed it to a feature request, as it is not something currently possible with ansible-lint.

wimglenn commented 1 month ago

@alisonlhart I am confused by the rename / change to a feature request.

Distributing rules as Python packages is already possible, and it is even officially documented at Creating Custom Rules for Ansible Lint, section Packaging Custom Rules. I am using custom rules packages in production already. It's only editable installations which aren’t discovered, and that is clearly a bug. Could you undo this change, or explain what I'm missing here?

ssbarnea commented 1 week ago

@wimglenn You are right, misssed https://www.ansible.com/blog/creating-custom-rules-for-ansible-lint/ as is not part of upstream docs. In fact the way is documented is not really what I would do these days. Instead I would fully switch to pluggy instead and deprecated the old method. This should sort the problem of editable and many other problems.

wimglenn commented 1 week ago

Thank you @ssbarnea, that makes more sense. I agree that a switch to pluggy would be a good idea here.