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

Replace cmp_version with rpm python bindings #110

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
sudo: false
language: python
before_install:
# for rpm-py-installer
- sudo apt-get install -y rpm

install: pip install tox
matrix:
include:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests
more-executors
ubi-config
cmp_version
rpm-py-installer
Copy link
Member

Choose a reason for hiding this comment

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

I think this might cause some issues for the RPM packages of this project. Is this going to result in the egg always requiring some "rpm-py-installer" distribution to be present, while it's actually nonsense to set that as Requires in an RPM?

In general though I think it's OK for what we put in these repos to be somewhat ignorant of RPM packaging complexities. So this comment is more like a heads up that this might cause us to run into issues and we may need patches in dist-git, or may need to revisit this later.

17 changes: 10 additions & 7 deletions tests/test_ubipop.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,22 @@ def test_sort_packages(mock_ubipop_runner):
get_test_pkg(filename="rubygems-2.0.14-26.el7_1.noarch.rpm"),
get_test_pkg(filename="rubygems-2.0.14-25.el7_1.noarch.rpm"),
get_test_pkg(filename="rubygems-2.0.14.1-33.el7_6.noarch.rpm"),
get_test_pkg(filename="rubygems-2.0.14.1-34.el7_6.noarch.rpm"),
get_test_pkg(filename="rubygems-2.0.14.1-34.1.el7_6.noarch.rpm"),
get_test_pkg(filename="rubygems-2.0.14.1-34.1.1.el7_6.noarch.rpm"),
get_test_pkg(filename="rubygems-2.0.13.1-34.el7_6.noarch.rpm"),
get_test_pkg(filename="rubygems-2.0.13.2-34.el7_6.noarch.rpm"),
]

mock_ubipop_runner.sort_packages(packages)

assert "2.0.13.1-34" in packages[0].filename
assert "2.0.13.2-34" in packages[1].filename
assert "2.0.14-25" in packages[2].filename
assert "2.0.14-26" in packages[3].filename
assert "2.0.14.1-33" in packages[4].filename
assert "2.0.14.1-34" in packages[5].filename
assert "2.0.13.1-34.el7_6" in packages[0].filename
assert "2.0.13.2-34.el7_6" in packages[1].filename
assert "2.0.14-25.el7_1" in packages[2].filename
assert "2.0.14-26.el7_1" in packages[3].filename
assert "2.0.14.1-33.el7_6" in packages[4].filename
assert "2.0.14.1-34.1.el7_6" in packages[5].filename
assert "2.0.14.1-34.1.1.el7_6" in packages[6].filename


@pytest.mark.parametrize("n, expected_versions_modules",
[(1, {3: 2}), (2, {2: 3, 3: 2}), (3, {1: 1, 2: 3, 3: 2})])
Expand Down
18 changes: 11 additions & 7 deletions ubipop/_pulp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import time

from urllib3.util.retry import Retry
from ubipop._utils import split_filename

try:
from urllib.parse import urljoin
except ImportError:
from urlparse import urljoin

import requests
from rpm import labelCompare as label_compare # pylint: disable=no-name-in-module
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of adding an extra dep, would not be easy to just borrow this function?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, sounds like a plan.

Copy link
Member

Choose a reason for hiding this comment

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

But it's implemented in C, isn't it? I would rather keep our stuff pure-python as much as we can.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, it's in C, I also wouldn't like to have extra C code in our stuff.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, if it's in C makes sense.


from cmp_version import cmp_version

_LOG = logging.getLogger("ubipop")

Expand Down Expand Up @@ -296,24 +297,27 @@ def __init__(self, name, filename, sourcerpm_filename=None, is_modular=False):
self.filename = filename
self.sourcerpm_filename = sourcerpm_filename
self.is_modular = is_modular
# return name, ver, rel, epoch, arch
_, self.version, self.release, self.epoch, _ = split_filename(self.filename)
self.evr_tuple = (self.epoch, self.version, self.release)

def __lt__(self, other):
return cmp_version(self.filename, other.filename) < 0
return label_compare(self.evr_tuple, other.evr_tuple) < 0

def __gt__(self, other):
return cmp_version(self.filename, other.filename) > 0
return label_compare(self.evr_tuple, other.evr_tuple) > 0

def __eq__(self, other):
return cmp_version(self.filename, other.filename) == 0
return label_compare(self.evr_tuple, other.evr_tuple) == 0

def __le__(self, other):
return cmp_version(self.filename, other.filename) <= 0
return label_compare(self.evr_tuple, other.evr_tuple) <= 0

def __ge__(self, other):
return cmp_version(self.filename, other.filename) >= 0
return label_compare(self.evr_tuple, other.evr_tuple) >= 0

def __ne__(self, other):
return cmp_version(self.filename, other.filename) != 0
return label_compare(self.evr_tuple, other.evr_tuple) != 0

def __str__(self):
return self.filename
Expand Down