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

ansible-lint's version check makes incorrect assumptions #3541

Closed
gotmax23 opened this issue Jun 10, 2023 · 0 comments · Fixed by #3551
Closed

ansible-lint's version check makes incorrect assumptions #3541

gotmax23 opened this issue Jun 10, 2023 · 0 comments · Fixed by #3551
Assignees
Labels

Comments

@gotmax23
Copy link
Contributor

Summary

ansible-lint's version check breaks completely or gives incorrect instructions in certain cases.

Issue Type
  • Bug Report
OS / ENVIRONMENT

Fedora Rawhide container running ansible-lint 6.16.2

With pipx:

$ pipx install ansible-lint==6.16.2
$ ansible-lint --version
WARNING: PATH altered to include /home/ME/.local/pipx/venvs/ansible-lint/bin :: This is usually a sign of broken local setup, which can cause unexpected behaviors.
ansible-lint 6.16.2 using ansible-core:2.15.0 ruamel-yaml:0.17.31 ruamel-yaml-clib:0.2.7
A new release of ansible-lint is available: 6.16.2 → 6.17.0 Upgrade by running: pip install --upgrade ansible-lint

With RPM:

# dnf install ansible-lint
$ /usr/bin/ansible-lint --version
ansible-lint 6.16.2 using ansible-core:2.15.0 ruamel-yaml:0.17.24 ruamel-yaml-clib:0.2.7
Traceback (most recent call last):
  File "/usr/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/ansiblelint/__main__.py", line 310, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
             ^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/ansiblelint/__main__.py", line 223, in main
    msg = get_version_warning()
          ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/ansiblelint/config.py", line 302, in get_version_warning
    pip = guess_install_method()
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/ansiblelint/config.py", line 229, in guess_install_method
    for _ in uninstallation_paths(dist):
  File "/usr/lib/python3.11/site-packages/pip/_internal/req/req_uninstall.py", line 45, in unique
    for item in fn(*args, **kw):
  File "/usr/lib/python3.11/site-packages/pip/_internal/req/req_uninstall.py", line 83, in uninstallation_paths
    raise UninstallationError(msg)
pip._internal.exceptions.UninstallationError: Cannot uninstall ansible-lint 6.16.2, RECORD file not found. Hint: The package was installed by rpm.
  • ansible installation method: one of n/a
  • ansible-lint installation method: pipx/rpm
STEPS TO REPRODUCE
  1. Install ansible-lint and run ansible-lint --version as shown in the steps above.
Desired Behavior

pipx:

ansible-lint --version should not suggest running pip install -U ansible-lint when it's installed in a pipx environment. It should not warn about WARNING: PATH altered to include /home/ME/.local/pipx/venvs/ansible-lint/bin :: This is usually a sign of broken local setup, which can cause unexpected behaviors. either.

I would argue that it shouldn't suggest running pip install -U in any case, as there's many environmental variations and this will be wrong in many cases, but pipx is a supported installation method and running pip install -U ansible-lint is definitely wrong when ansible-lint is installed with pipx.

RPM:

ansible-lint --version should not error out and should not suggest running pip install -U ansible-lint when it's installed via RPM.

ansible-lint is calling pip._internal.req.req_uninstall.uninstallation_paths() which does not work on RPM-installed Python packages. In dist-info directories, we purposely remove RECORD file (see https://peps.python.org/pep-0627/#optional-record-file) and set the contents of INSTALLER to rpm so users do not break their systems by trying to uninstall RPM-installed Python packages with pip uninstall.

There's a couple potential ways ansible-lint can handle this case:

  1. Suppress pip._internal.exceptions.UninstallationError and move on like the code already does with AttributeError.
  2. Check if importlib.metadata.distribution('ansible_lint').read_text('INSTALLER').strip() == "pip" and skip this code if it does not. This would need proper error handling for FileNotFoundErrors.
Actual Behavior

See ansible-lint --version output above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants