Skip to content

Commit

Permalink
adding an api to enable version joins.
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Dec 20, 2017
1 parent ab3ce94 commit 9508484
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tests/packages/test_versions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from uranium.packages.versions import Versions
from packaging.specifiers import SpecifierSet


@pytest.fixture
Expand Down Expand Up @@ -43,3 +44,12 @@ def test_delete_coerce_lowercase(versions):
"SQLAlchemy": "==1.0.11"
})
del versions["SQLAlchemy"]


def test_and_operator(versions):
"""
the and operator should work for dictionaries
"""
versions["foo"] = ">1.0"
versions &= {"foo": "<1.1"}
assert SpecifierSet(versions["foo"]) == SpecifierSet(">1.0,<1.1")
1 change: 0 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def main(build):
"uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT, "-c", "test_key:test_value",
cwd=tmpdir.strpath
)
assert err.decode("UTF-8") == ""
assert "test_key" in out.decode("UTF-8")
assert "test_value" in out.decode("UTF-8")

Expand Down
12 changes: 12 additions & 0 deletions uranium/packages/versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import MutableMapping
from packaging.specifiers import SpecifierSet


class Versions(MutableMapping):
Expand Down Expand Up @@ -28,3 +29,14 @@ def __len__(self):
@staticmethod
def _clean_key(key):
return str(key).lower()

def __and__(self, other):
"""
join version specifiers, consuming a mapping object.
"""
for k, v in other.items():
if k in self._values:
self._values[k] = str(SpecifierSet(self._values[k]) & v)
else:
self._values[k] = v
return self

0 comments on commit 9508484

Please sign in to comment.