-
Notifications
You must be signed in to change notification settings - Fork 54
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
Fix version comparison #335
Conversation
packaging is added by ansible https://github.com/ansible/ansible/blob/devel/requirements.txt#L9 Not sure why the CI is failing, do we need to include it elsewhere? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean, thanks!
@sean-m-sullivan CI is failing because the packaging dependency cannot be found |
it looks like this dependency is not part of the ansible install. need it in requirements.txt in the base directory. |
ALternativelly we can create our own implementation of the class class Version:
def __init__(self, version_str):
components = list(map(int, version_str.split('.')))
self.major = components[0]
self.minor = components[1] if len(components) > 1 else 0
self.patch = components[2] if len(components) > 2 else 0
def __str__(self):
return f"{self.major}.{self.minor}.{self.patch}"
def __eq__(self, other):
if not isinstance(other, Version):
return NotImplemented
return (self.major, self.minor, self.patch) == (other.major, other.minor, other.patch)
def __lt__(self, other):
if not isinstance(other, Version):
return NotImplemented
return (self.major, self.minor, self.patch) < (other.major, other.minor, other.patch)
def __le__(self, other):
if not isinstance(other, Version):
return NotImplemented
return (self < other) or (self == other)
def __gt__(self, other):
if not isinstance(other, Version):
return NotImplemented
return not (self <= other)
def __ge__(self, other):
if not isinstance(other, Version):
return NotImplemented
return not (self < other)
def __ne__(self, other):
if not isinstance(other, Version):
return NotImplemented
return not (self == other)
# Example usage:
version1 = Version("4.2")
version2 = Version("5.1.3")
print(version1 < version2) # Output: True
print(version1 >= version2) # Output: False |
plugins/modules/ah_ee_image.py
Outdated
@@ -9,6 +9,7 @@ | |||
|
|||
|
|||
from __future__ import absolute_import, division, print_function | |||
from ansible.module_utils.compat.version import LooseVersion as Version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sanity check is stating that this needs to be with the imports further down below the documentation segment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus the same for all the other modules
f45bbc5
to
6c61875
Compare
6c61875
to
3afa90f
Compare
fix ansible#334 alternative implementarion for ansible#335
Trying a simpler implementation on #337 |
Closing in favor of #337 |
* Update pre-commit (#326) Co-authored-by: branic <branic@users.noreply.github.com> * Update pre-commit * Fix ansible-lint running against .py files (#332) * Fix ansible-lint running against .py files * Fix a pylint issue * Update description in the user role README (#333) Updated the one line description in the role. Co-authored-by: Sean Sullivan <ssulliva@redhat.com> * Fix version comparison (#337) fix #334 alternative implementarion for #335 * Update pre-commit (#338) Co-authored-by: branic <branic@users.noreply.github.com> * user: Fix password type field in README (#342) The `password` type was set to bool instead of str. Signed-off-by: Dimitri Savineau <dsavinea@redhat.com> * update repository roles (#343) Co-authored-by: David Danielsson <djdanielsson@users.noreply.github.com> * Update pre-commit (#344) Co-authored-by: branic <branic@users.noreply.github.com> * Fix wording to sync (#345) * Update pre-commit * Fix markdown tables (#349) Co-authored-by: Sean Sullivan <ssulliva@redhat.com> * Update pre-commit (#348) Co-authored-by: branic <branic@users.noreply.github.com> Co-authored-by: Sean Sullivan <ssulliva@redhat.com> * Update pre-commit * collection_remote: set sync_dependencies default to PAH default (#346) Co-authored-by: David Danielsson <djdanielsson@users.noreply.github.com> * Fix typo in ah_group_roles variable * Add branch specifics to Contributing guide (#360) * Fix documentation for validate_certs (#364) * Fixed issue in all roles where AH_HOST was not being defaulted to if no variable set (#363) * Fix documentation for group_roles role (#359) * Update pre-commit (#361) Co-authored-by: branic <branic@users.noreply.github.com> --------- Signed-off-by: Dimitri Savineau <dsavinea@redhat.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: branic <branic@users.noreply.github.com> Co-authored-by: Tom Page <tpage@redhat.com> Co-authored-by: Richard J Osborne <20555769+rjo-uk@users.noreply.github.com> Co-authored-by: Bruno Rocha <rochacbruno@users.noreply.github.com> Co-authored-by: Dimitri Savineau <savineau.dimitri@gmail.com> Co-authored-by: David Danielsson <djdanielsson@users.noreply.github.com> Co-authored-by: dbk-rabel <57803476+dbk-rabel@users.noreply.github.com> Co-authored-by: Bram Mertens <bmertens@redhat.com>
Compara versions using ansible.module_utils.compat.version.LooseVersion
closes #334