Skip to content

ansible-lint: Unset PYTHONPATH in wrapper #251948

Closed
wfdewith wants to merge 2 commits intoNixOS:masterfrom
wfdewith:ansible-lint-fix
Closed

ansible-lint: Unset PYTHONPATH in wrapper #251948
wfdewith wants to merge 2 commits intoNixOS:masterfrom
wfdewith:ansible-lint-fix

Conversation

@wfdewith
Copy link
Member

@wfdewith wfdewith commented Aug 28, 2023

Description of changes

Since the update of ruamel.yaml to 0.17.32 (5330b05), ansible-lint is broken with the following error, when ran from a nix-shell:

Traceback (most recent call last):
  File "/nix/store/20wbbb8w5d95k23hyf417aqh85qjmzp9-ansible-lint-6.17.1/bin/.ansible-lint-wrapped", line 6, in <module>
    from ansiblelint.__main__ import _run_cli_entrypoint
  File "/nix/store/20wbbb8w5d95k23hyf417aqh85qjmzp9-ansible-lint-6.17.1/lib/python3.10/site-packages/ansiblelint/__main__.py", line 39, in <module>
    from ansiblelint import cli
  File "/nix/store/20wbbb8w5d95k23hyf417aqh85qjmzp9-ansible-lint-6.17.1/lib/python3.10/site-packages/ansiblelint/cli.py", line 29, in <module>
    from ansiblelint.yaml_utils import clean_json
  File "/nix/store/20wbbb8w5d95k23hyf417aqh85qjmzp9-ansible-lint-6.17.1/lib/python3.10/site-packages/ansiblelint/yaml_utils.py", line 15, in <module>
    import ruamel.yaml.events
ModuleNotFoundError: No module named 'ruamel.yaml'

I did some investigation, and it appears to have something to do with different versions of Python namespaces. I'm not very familiar with the Python packaging and module loading process, so that was as far as I got. @tjni has been working on this (see here), so I hope that he understands the problem better than I do. In any case, I found that unsetting the PYTHONPATH environment variable fixes the problem for ansible-lint so this PR does exactly that.

I think a better fix needs to be found in the future, but for now, this fix at least mitigates the issue.

In addition, since an update for ansible-lint was released in the meantime, this PR includes a version bump.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

There seems to be a weird interaction between PYTHONPATH and the
explicitly set Python search paths with site.addsitedir. Since
ruamel.yaml updated to 0.17.32, ansible-lint errors with the following
error: ModuleNotFoundError: No module named 'ruamel.yaml'

By unsetting the PYTHONPATH, this mitigates the issue, though a more
thorough fix is still needed.
@NixOSInfra NixOSInfra added the 12.first-time contribution This PR is the author's first one; please be gentle! label Aug 28, 2023
@ofborg ofborg bot requested a review from sengaya August 28, 2023 11:18
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Aug 28, 2023
@tjni
Copy link
Contributor

tjni commented Aug 28, 2023

I'm sorry that this causes you pain. It's only on staging right now, but do you think #250830 would fix it?

@wfdewith
Copy link
Member Author

Oh, that's great! I'll try it, and if it works I will change this PR to only include the update.

@wfdewith
Copy link
Member Author

Closed in favor of #252021

@wfdewith wfdewith closed this Aug 28, 2023
@wfdewith wfdewith deleted the ansible-lint-fix branch February 8, 2024 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments