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

Fix version comparison #335

Closed
wants to merge 4 commits into from

Conversation

rochacbruno
Copy link
Member

@rochacbruno rochacbruno commented Nov 16, 2023

Compara versions using ansible.module_utils.compat.version.LooseVersion

closes #334

@rochacbruno
Copy link
Member Author

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?

Copy link
Contributor

@sean-m-sullivan sean-m-sullivan left a comment

Choose a reason for hiding this comment

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

Clean, thanks!

@rochacbruno
Copy link
Member Author

@sean-m-sullivan CI is failing because the packaging dependency cannot be found

@sean-m-sullivan
Copy link
Contributor

it looks like this dependency is not part of the ansible install. need it in requirements.txt in the base directory.

@rochacbruno
Copy link
Member Author

ALternativelly we can create our own implementation of the class Version and not depend on external library.

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

@@ -9,6 +9,7 @@


from __future__ import absolute_import, division, print_function
from ansible.module_utils.compat.version import LooseVersion as Version
Copy link
Contributor

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

Copy link
Contributor

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

@rochacbruno rochacbruno force-pushed the fix_version_comparison branch 2 times, most recently from f45bbc5 to 6c61875 Compare November 17, 2023 14:33
rochacbruno added a commit to rochacbruno/galaxy_collection that referenced this pull request Nov 17, 2023
fix ansible#334

alternative implementarion for ansible#335
@rochacbruno
Copy link
Member Author

Trying a simpler implementation on #337

@rochacbruno
Copy link
Member Author

Closing in favor of #337

sean-m-sullivan pushed a commit that referenced this pull request Nov 17, 2023
fix #334

alternative implementarion for #335
sean-m-sullivan added a commit that referenced this pull request Feb 27, 2024
* 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>
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.

Version Comparison is broken when galaxy version >= 4.10.0
3 participants