Skip to content

refactor: the ansible six PY2 is deprecated - just use sys.version_info instead#324

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
richm:refactor-fix-ansible-test-errors
Apr 1, 2026
Merged

refactor: the ansible six PY2 is deprecated - just use sys.version_info instead#324
richm merged 1 commit intolinux-system-roles:mainfrom
richm:refactor-fix-ansible-test-errors

Conversation

@richm
Copy link
Copy Markdown
Collaborator

@richm richm commented Apr 1, 2026

Fixes the following ansible-test error:

ERROR: plugins/module_utils/certificate_lsr/providers/base.py:90:0: ansible-bad-import-from:
Import PY2 from the Python standard library equivalent instead of ansible.module_utils.six

PY2 is only used to determine the name of an exception, which can be done using sys.version_info
instead.

This also adds ansible-test ignores files for all tested versions.

Signed-off-by: Rich Megginson rmeggins@redhat.com

Summary by Sourcery

Replace deprecated Python 2 detection in certificate provider utilities and add ansible-test ignore configuration for supported Ansible versions.

Enhancements:

  • Use sys.version_info for Python 2 detection in certificate_lsr base provider instead of the deprecated ansible.module_utils.six.PY2 import.

CI:

  • Add ansible sanity ignore configuration files for Ansible versions 2.18 through 2.21 to align with current testing setup.

…fo instead

Fixes the following ansible-test error:

```
ERROR: plugins/module_utils/certificate_lsr/providers/base.py:90:0: ansible-bad-import-from:
Import PY2 from the Python standard library equivalent instead of ansible.module_utils.six
```

PY2 is only used to determine the name of an exception, which can be done using sys.version_info
instead.

This also adds ansible-test ignores files for all tested versions.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@richm richm requested review from rjeffman and spetrosi as code owners April 1, 2026 22:36
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 1, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces deprecated ansible.module_utils.six.PY2 usage with a direct sys.version_info check in the certificate provider base module, and adds ansible-test sanity ignore files for multiple Ansible versions.

Flow diagram for Python version-dependent FileNotFoundError alias using sys.version_info

flowchart TD
    start[[Module_import]] --> check_version["Check sys.version_info[0]"]
    check_version -->|== 2| alias_ioerror["Set FileNotFoundError = IOError (for Python 2)"]
    check_version -->|!= 2| keep_builtin["Keep built-in FileNotFoundError (Python 3)"]
    alias_ioerror --> module_runtime[[Module_runtime]]
    keep_builtin --> module_runtime
Loading

File-Level Changes

Change Details Files
Replace deprecated PY2 import from ansible.module_utils.six with direct Python version check using sys.version_info.
  • Remove import of PY2 from ansible.module_utils.six
  • Introduce use of sys.version_info[0] to detect Python 2 at runtime
  • Retain conditional alias of FileNotFoundError to IOError for Python 2 environments
module_utils/certificate_lsr/providers/base.py
Add ansible-test sanity ignore configuration files for specific Ansible versions.
  • Create .sanity-ansible-ignore-2.18.txt to configure sanity test ignores for Ansible 2.18
  • Create .sanity-ansible-ignore-2.19.txt to configure sanity test ignores for Ansible 2.19
  • Create .sanity-ansible-ignore-2.20.txt to configure sanity test ignores for Ansible 2.20
  • Create .sanity-ansible-ignore-2.21.txt to configure sanity test ignores for Ansible 2.21
.sanity-ansible-ignore-2.18.txt
.sanity-ansible-ignore-2.19.txt
.sanity-ansible-ignore-2.20.txt
.sanity-ansible-ignore-2.21.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The new sys.version_info[0] == 2 check uses sys without importing it; add an explicit import sys at the top of the module to avoid a NameError.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `sys.version_info[0] == 2` check uses `sys` without importing it; add an explicit `import sys` at the top of the module to avoid a NameError.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@richm
Copy link
Copy Markdown
Collaborator Author

richm commented Apr 1, 2026

[citest]

@richm richm merged commit 98b1433 into linux-system-roles:main Apr 1, 2026
35 of 37 checks passed
@richm richm deleted the refactor-fix-ansible-test-errors branch April 1, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant