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

Prepare for distutils.version being removed in Python 3.12 #3936

Merged
merged 7 commits into from
Dec 24, 2021

Conversation

felixfontein
Copy link
Collaborator

@felixfontein felixfontein commented Dec 22, 2021

SUMMARY

distutils has been deprecafed and will be removed from Python's stdlib in Python 3.12 (see https://www.python.org/dev/peps/pep-0632/). This PR replaces the use of distutils.version.LooseVersion and distutils.version.StrictVersion with LooseVersion from the vendored copy of distutils.version included with ansible-core 2.12 (ansible/ansible#74644) if available, and falls back to distutils.version for ansible-core 2.11 and before. Since ansible-core 2.11 and earlier do not support Python 3.12 (since they use LooseVersion itself in various places), this incomplete fix should be OK for now. Also, the way this PR works (by adding a new module_utils version that abstracts away where LooseVersion comes from), it is easy to also fix this for ansible-core 2.11 and earlier later on.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

Various modules and plugins

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-3 labels Dec 22, 2021
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added has_issue needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Dec 22, 2021
@felixfontein felixfontein merged commit a2f72be into ansible-collections:main Dec 24, 2021
@patchback
Copy link

patchback bot commented Dec 24, 2021

Backport to stable-3: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply a2f72be on top of patchback/backports/stable-3/a2f72be6c8d36c0b836755093e2837518b2e5869/pr-3936

Backporting merged PR #3936 into main

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/ansible-collections/community.general.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/stable-3/a2f72be6c8d36c0b836755093e2837518b2e5869/pr-3936 upstream/stable-3
  4. Now, cherry-pick PR Prepare for distutils.version being removed in Python 3.12 #3936 contents into that branch:
    $ git cherry-pick -x a2f72be6c8d36c0b836755093e2837518b2e5869
    If it'll yell at you with something like fatal: Commit a2f72be6c8d36c0b836755093e2837518b2e5869 is a merge but no -m option was given., add -m 1 as follows intead:
    $ git cherry-pick -m1 -x a2f72be6c8d36c0b836755093e2837518b2e5869
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR Prepare for distutils.version being removed in Python 3.12 #3936 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/stable-3/a2f72be6c8d36c0b836755093e2837518b2e5869/pr-3936
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@patchback
Copy link

patchback bot commented Dec 24, 2021

Backport to stable-4: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-4/a2f72be6c8d36c0b836755093e2837518b2e5869/pr-3936

Backported as #3941

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Dec 24, 2021
* Prepare for distutils.version being removed in Python 2.12.

* Fix copy'n'paste error.

* Re-add Loose prefix.

* Fix Python version typos.

* Improve formulation.

* Move message into own line.

* Fix casing, now that the object is no longer called Version.

(cherry picked from commit a2f72be)
@felixfontein
Copy link
Collaborator Author

@briantist @Andersson007 @zanssa thanks a lot for reviewing this!

@felixfontein felixfontein deleted the distutils.version branch December 24, 2021 17:35
felixfontein added a commit to felixfontein/community.general that referenced this pull request Dec 24, 2021
…ollections#3936)

* Prepare for distutils.version being removed in Python 2.12.

* Fix copy'n'paste error.

* Re-add Loose prefix.

* Fix Python version typos.

* Improve formulation.

* Move message into own line.

* Fix casing, now that the object is no longer called Version.

(cherry picked from commit a2f72be)
@felixfontein
Copy link
Collaborator Author

Manual backport to stable-3 in #3942.

felixfontein added a commit that referenced this pull request Dec 24, 2021
…3941)

* Prepare for distutils.version being removed in Python 2.12.

* Fix copy'n'paste error.

* Re-add Loose prefix.

* Fix Python version typos.

* Improve formulation.

* Move message into own line.

* Fix casing, now that the object is no longer called Version.

(cherry picked from commit a2f72be)

Co-authored-by: Felix Fontein <felix@fontein.de>
felixfontein added a commit that referenced this pull request Dec 24, 2021
…3942)

* Prepare for distutils.version being removed in Python 2.12.

* Fix copy'n'paste error.

* Re-add Loose prefix.

* Fix Python version typos.

* Improve formulation.

* Move message into own line.

* Fix casing, now that the object is no longer called Version.

(cherry picked from commit a2f72be)
@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Dec 26, 2021
@rockaut
Copy link

rockaut commented Dec 28, 2021

@felixfontein may I asked for community.zabbix: do I understand correctly. We may use the builtin class which falls back to distutils in older releases. But we might get problems in some unsupported version combinations?

And do I interpreted this correctly that this class will only be in the community.general collection and not in the core Ansible?

@felixfontein
Copy link
Collaborator Author

@felixfontein may I asked for community.zabbix: do I understand correctly. We may use the builtin class which falls back to distutils in older releases. But we might get problems in some unsupported version combinations?

Yes. Right now the only unsupported comination (to my knowledge) is Python >= 3.12 with ansible-core < 2.12.

And do I interpreted this correctly that this class will only be in the community.general collection and not in the core Ansible?

Yes. But you can copy it into your collection as well. If you only use LooseVersion in one place you can solve this differently, but if you use it in more than one place it's IMO better to have this extra file. (This is how some other collections did it: ansible-collections/ansible.posix#304, ansible-collections/amazon.aws#599, ansible-collections/community.vmware#1165, ansible-collections/community.crypto#353, ansible-collections/community.docker#258, ansible-collections/community.mysql#267, ansible-collections/community.postgresql#178, ansible-collections/kubernetes.core#314)

@rockaut
Copy link

rockaut commented Dec 28, 2021

Thx. We have now done it like this too.

@felixfontein
Copy link
Collaborator Author

According to ansible-collections/community.docker#267, this change breaks the modules which use it on Ansible < 2.9.20 and ansible-base < 2.10.8 since it relies on ansible/ansible#73832.

@felixfontein
Copy link
Collaborator Author

#3979 adds some documentation on this.

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

Successfully merging this pull request may close these issues.

6 participants