Skip to content

Commit 48dc602

Browse files
committed
Use conan 2.0 as default conan version
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 2290ed2 commit 48dc602

8 files changed

Lines changed: 161 additions & 146 deletions

File tree

src/univers/conan/errors.py

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ def conanfile_exception_formatter(conanfile_name, func_name):
4141
"""
4242

4343
def _raise_conanfile_exc(e):
44-
from conan.api.output import LEVEL_DEBUG
45-
from conan.api.output import conan_output_level
46-
47-
if conan_output_level <= LEVEL_DEBUG:
48-
import traceback
49-
50-
raise ConanExceptionInUserConanfileMethod(traceback.format_exc())
5144
m = _format_conanfile_exception(conanfile_name, func_name, e)
5245
raise ConanExceptionInUserConanfileMethod(m)
5346

@@ -132,13 +125,18 @@ def remote_message(self):
132125
return ""
133126

134127
def __str__(self):
135-
from conans.util.files import exception_message_safe
136128

137129
msg = super(ConanException, self).__str__()
130+
131+
try:
132+
msg = str(msg)
133+
except Exception:
134+
msg = repr(msg)
135+
138136
if self.remote:
139-
return "{}.{}".format(exception_message_safe(msg), self.remote_message())
137+
return "{}.{}".format(msg, self.remote_message())
140138

141-
return exception_message_safe(msg)
139+
return msg
142140

143141

144142
class ConanReferenceDoesNotExistInDB(ConanException):
@@ -230,36 +228,6 @@ def __init__(self, *args, **kwargs):
230228
super(NotFoundException, self).__init__(*args, **kwargs)
231229

232230

233-
class RecipeNotFoundException(NotFoundException):
234-
def __init__(self, ref, remote=None):
235-
from conans.model.recipe_ref import RecipeReference
236-
237-
assert isinstance(
238-
ref, RecipeReference
239-
), "RecipeNotFoundException requires a RecipeReference"
240-
self.ref = ref
241-
super(RecipeNotFoundException, self).__init__(remote=remote)
242-
243-
def __str__(self):
244-
tmp = repr(self.ref)
245-
return "Recipe not found: '{}'".format(tmp, self.remote_message())
246-
247-
248-
class PackageNotFoundException(NotFoundException):
249-
def __init__(self, pref, remote=None):
250-
from conans.model.package_ref import PkgReference
251-
252-
assert isinstance(pref, PkgReference), "PackageNotFoundException requires a PkgReference"
253-
self.pref = pref
254-
255-
super(PackageNotFoundException, self).__init__(remote=remote)
256-
257-
def __str__(self):
258-
return "Binary package not found: '{}'{}".format(
259-
self.pref.repr_notime(), self.remote_message()
260-
)
261-
262-
263231
class UserInterfaceErrorException(RequestErrorException):
264232
"""
265233
420 error
@@ -274,7 +242,5 @@ class UserInterfaceErrorException(RequestErrorException):
274242
AuthenticationException: 401,
275243
ForbiddenException: 403,
276244
NotFoundException: 404,
277-
RecipeNotFoundException: 404,
278-
PackageNotFoundException: 404,
279245
UserInterfaceErrorException: 420,
280246
}

src/univers/conan/version.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __lt__(self, other):
4747

4848

4949
@total_ordering
50-
class ConanVersion:
50+
class Version:
5151
"""
5252
This is NOT an implementation of semver, as users may use any pattern in their versions.
5353
It is just a helper to parse "." or "-" and compare taking into account integers when possible
@@ -60,15 +60,15 @@ def __init__(self, value):
6060
items = value.rsplit("+", 1) # split for build
6161
if len(items) == 2:
6262
value, build = items
63-
self._build = ConanVersion(build) # This is a nested version by itself
63+
self._build = Version(build) # This is a nested version by itself
6464
else:
6565
value = items[0]
6666
self._build = None
6767

6868
items = value.rsplit("-", 1) # split for pre-release
6969
if len(items) == 2:
7070
value, pre = items
71-
self._pre = ConanVersion(pre) # This is a nested version by itself
71+
self._pre = Version(pre) # This is a nested version by itself
7272
else:
7373
value = items[0]
7474
self._pre = None
@@ -101,7 +101,7 @@ def bump(self, index):
101101
items.extend([0] * (len(items) - index - 1))
102102
v = ".".join(str(i) for i in items)
103103
# prerelease and build are dropped while bumping digits
104-
result = ConanVersion(v)
104+
result = Version(v)
105105
return result
106106

107107
def upper_bound(self, index):
@@ -113,7 +113,7 @@ def upper_bound(self, index):
113113
items.extend([0] * (len(items) - index - 1))
114114
v = ".".join(str(i) for i in items)
115115
v += "-" # Exclude prereleases
116-
result = ConanVersion(v)
116+
result = Version(v)
117117
return result
118118

119119
@property
@@ -165,8 +165,8 @@ def __repr__(self):
165165
def __eq__(self, other):
166166
if other is None:
167167
return False
168-
if not isinstance(other, ConanVersion):
169-
other = ConanVersion(other)
168+
if not isinstance(other, Version):
169+
other = Version(other)
170170

171171
return (self._nonzero_items, self._pre, self._build) == (
172172
other._nonzero_items,
@@ -180,8 +180,8 @@ def __hash__(self):
180180
def __lt__(self, other):
181181
if other is None:
182182
return False
183-
if not isinstance(other, ConanVersion):
184-
other = ConanVersion(other)
183+
if not isinstance(other, Version):
184+
other = Version(other)
185185

186186
if self._pre:
187187
if other._pre: # both are pre-releases

src/univers/conan/version_range.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import namedtuple
22

33
from univers.conan.errors import ConanException
4-
from univers.conan.version import ConanVersion
4+
from univers.versions import ConanVersion
55

66
_Condition = namedtuple("_Condition", ["operator", "version"])
77

src/univers/version_range.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from univers import gem
1515
from univers import maven
1616
from univers import versions
17+
from univers.conan.version_range import VersionRange as conan_version_range
1718
from univers.utils import remove_spaces
1819
from univers.version_constraint import VersionConstraint
1920
from univers.version_constraint import contains_version
@@ -377,9 +378,27 @@ def from_native(cls, string):
377378
return cls(constraints=constraints)
378379

379380

380-
class ConanVersionRange(NpmVersionRange):
381+
class ConanVersionRange(VersionRange):
381382
scheme = "conan"
382-
version_class = versions.SemverVersion
383+
version_class = versions.ConanVersion
384+
385+
@classmethod
386+
def from_native(cls, string):
387+
"""
388+
Return a VersionRange built from a conan range ``string``.
389+
"""
390+
condition_sets = conan_version_range(string).condition_sets
391+
constraints = []
392+
for conditions in condition_sets:
393+
for condition in conditions.conditions:
394+
comparator = condition.operator
395+
version = condition.version
396+
constraints.append(
397+
VersionConstraint(
398+
comparator=comparator, version=cls.version_class(str(version))
399+
)
400+
)
401+
return cls(constraints=constraints)
383402

384403

385404
class GemVersionRange(VersionRange):

src/univers/versions.py

Lines changed: 77 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from univers import maven
1919
from univers import nuget
2020
from univers import rpm
21-
from univers.conan.version import ConanVersion as conan_version
21+
from univers.conan.version import Version as conan_version
2222
from univers.utils import remove_spaces
2323

2424
"""
@@ -140,7 +140,6 @@ def __eq__(self, other):
140140

141141
def __lt__(self, other):
142142
if not isinstance(other, self.__class__):
143-
print('Hello!')
144143
return NotImplemented
145144
return self.value.__lt__(other.value)
146145

@@ -653,22 +652,14 @@ def __ge__(self, other):
653652
# version value are of diff type, then semver one is always ahead of legacy
654653
return isinstance(self.value, SemverVersion)
655654

655+
656+
@attr.s(frozen=True, order=False, eq=False, hash=True)
657+
@total_ordering
656658
class ConanVersion(Version):
657659
@classmethod
658660
def build_value(cls, string):
659661
return conan_version(string)
660662

661-
# def __eq__(self, other):
662-
# if not isinstance(other, self.__class__):
663-
# return NotImplemented
664-
# return conan_version.vercmp(self.value, other.value) == 0
665-
666-
def __eq__(self, other):
667-
if other is None:
668-
return False
669-
if not isinstance(other, conan_version):
670-
other = conan_version(other)
671-
672663
@classmethod
673664
def is_valid(cls, string):
674665
try:
@@ -697,6 +688,46 @@ def prerelease(self):
697688
def build(self):
698689
return self.value and self.value.build
699690

691+
@property
692+
def micro(self):
693+
return self.value and self.value.micro
694+
695+
@property
696+
def pre(self):
697+
return self.value and self.value._pre
698+
699+
@property
700+
def nonzero_items(self):
701+
return self.value and self.value._nonzero_items
702+
703+
@property
704+
def main(self):
705+
return self.value._items
706+
707+
@property
708+
def major(self):
709+
try:
710+
return self.value.main[0]
711+
except IndexError:
712+
return None
713+
714+
@property
715+
def minor(self):
716+
try:
717+
return self.value.main[1]
718+
except IndexError:
719+
return None
720+
721+
@property
722+
def patch(self):
723+
try:
724+
return self.value.main[2]
725+
except IndexError:
726+
return None
727+
728+
def upper_bound(self, index):
729+
return self.value and self.value.upper_bound(index)
730+
700731
def next_major(self):
701732
return self.value and self.value.next_major()
702733

@@ -706,42 +737,41 @@ def next_minor(self):
706737
def next_patch(self):
707738
return self.value and self.value.next_patch()
708739

709-
@property
710-
def micro(self):
711-
# self.value()
712-
return self.value and self.value.micro
740+
def bump(self, index):
741+
return self.value and self.value.bump(index)
713742

714-
@property
715-
def pre(self):
716-
return self.value and self.value._pre
743+
def __eq__(self, other):
744+
if other is None:
745+
return False
746+
if not isinstance(other, ConanVersion):
747+
other = ConanVersion.build_value(other)
748+
return self.value == other
749+
return self.value == other.value
717750

718751
def __lt__(self, other):
719752
if other is None:
720753
return False
721-
if not isinstance(other, conan_version):
722-
other = conan_version(other)
723-
724-
if self.value._pre:
725-
if other._pre: # both are pre-releases
726-
return (self.value._nonzero_items, self.value._pre, self.value._build) < (
727-
other._nonzero_items,
728-
other._pre,
729-
other._build,
730-
)
731-
else: # Left hand is pre-release, right side is regular
732-
if (
733-
self.value._nonzero_items == other._nonzero_items
734-
): # Problem only happens if both equal
735-
return True
736-
else:
737-
return self.value._nonzero_items < other._nonzero_items
738-
else:
739-
if other._pre: # Left hand is regular, right side is pre-release
740-
if (
741-
self.value._nonzero_items == other._nonzero_items
742-
): # Problem only happens if both equal
743-
return False
744-
else:
745-
return self.value._nonzero_items < other._nonzero_items
746-
else: # None of them is pre-release
747-
return (self.value._nonzero_items, self.value._build) < (other._nonzero_items, other._build)
754+
if not isinstance(other, ConanVersion):
755+
other = ConanVersion(str(other))
756+
return self.value < other.value
757+
758+
def __le__(self, other):
759+
if other is None:
760+
return False
761+
if not isinstance(other, ConanVersion):
762+
other = ConanVersion(str(other))
763+
return self.value <= other.value
764+
765+
def __gt__(self, other):
766+
if other is None:
767+
return False
768+
if not isinstance(other, ConanVersion):
769+
other = ConanVersion(str(other))
770+
return self.value > other.value
771+
772+
def __ge__(self, other):
773+
if other is None:
774+
return False
775+
if not isinstance(other, ConanVersion):
776+
other = ConanVersion(str(other))
777+
return self.value >= other.value

0 commit comments

Comments
 (0)