Skip to content

Commit 8b31ebc

Browse files
committed
Add explicit property for defaulted versions
Currently there is no way to detect whether a version was defaulted. The current default value ('0.0.0') is a valid value for the versions list and the appropriate default comparator for that should be `==`. However such a version is (mis-)detected as being the default and the resulting default comparator is `>=` which is less restrictive than intended. Fix by introducing a property set only for the default version.
1 parent ed789e7 commit 8b31ebc

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

easybuild/framework/easyconfig/format/version.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@
4545

4646

4747
class EasyVersion(LooseVersion):
48-
"""Exact LooseVersion. No modifications needed (yet)"""
48+
"""Represent a version"""
49+
50+
def __init__(self, vstring, is_default=False):
51+
super().__init__(vstring)
52+
self._is_default = is_default
53+
54+
@property
55+
def is_default(self):
56+
"""Return whether this is the default version used when no explicit version is specified"""
57+
return self._is_default
4958

5059
def __len__(self):
5160
"""Determine length of this EasyVersion instance."""
@@ -74,7 +83,7 @@ class VersionOperator(object):
7483
OPERATOR_FAMILIES = [['>', '>='], ['<', '<=']] # similar operators
7584

7685
# default version and operator when version is undefined
77-
DEFAULT_UNDEFINED_VERSION = EasyVersion('0.0.0')
86+
DEFAULT_UNDEFINED_VERSION = EasyVersion('0.0', is_default=True)
7887
DEFAULT_UNDEFINED_VERSION_OPERATOR = OPERATOR_MAP['>']
7988
# default operator when operator is undefined (but version is)
8089
DEFAULT_UNDEFINED_OPERATOR = OPERATOR_MAP['==']
@@ -256,7 +265,7 @@ def _convert_operator(self, operator_str, version=None):
256265
"""Return the operator"""
257266
operator = None
258267
if operator_str is None:
259-
if version == self.DEFAULT_UNDEFINED_VERSION or version is None:
268+
if version is None or version.is_default:
260269
operator = self.DEFAULT_UNDEFINED_VERSION_OPERATOR
261270
else:
262271
operator = self.DEFAULT_UNDEFINED_OPERATOR

0 commit comments

Comments
 (0)