Example #1
0
File: version.py Project: gst/rez
    def __init__(self,
                 range_str='',
                 make_token=AlphanumericVersionToken,
                 invalid_bound_error=True):
        """Create a VersionRange object.

        Args:
            range_str: Range string, such as "3", "3+<4.5", "2|6+". The range
                will be optimised, so the string representation of this instance
                may not match range_str. For example, "3+<6|4+<8" == "3+<8".
            make_token: Version token class to use.
            invalid_bound_error (bool): If True, raise an exception if an
                impossible range is given, such as '3+<2'.
        """
        self._str = None
        self.bounds = []
        if range_str is None:
            return

        try:
            parser = _VersionRangeParser(
                range_str, make_token, invalid_bound_error=invalid_bound_error)
            bounds = parser.bounds
        except ParseException as e:
            raise VersionError("Syntax error in version range '%s': %s" %
                               (range_str, str(e)))
        except VersionError as e:
            raise VersionError("Invalid version range '%s': %s" %
                               (range_str, str(e)))

        if bounds:
            self.bounds = self._union(bounds)
        else:
            self.bounds.append(_Bound.any)
Example #2
0
File: version.py Project: gst/rez
    def __init__(self, ver_str='', make_token=AlphanumericVersionToken):
        """Create a Version object.

        Args:
            ver_str: Version string.
            make_token: Callable that creates a VersionToken subclass from a
                string.
        """
        self.tokens = []
        self.seps = []
        self._str = None
        self._hash = None

        if ver_str:
            toks = re_token.findall(ver_str)
            if not toks:
                raise VersionError(ver_str)

            seps = re_token.split(ver_str)
            if seps[0] or seps[-1] or max(len(x) for x in seps) > 1:
                raise VersionError("Invalid version syntax: '%s'" % ver_str)

            for tok in toks:
                try:
                    self.tokens.append(make_token(tok))
                except VersionError as e:
                    raise VersionError("Invalid version '%s': %s" %
                                       (ver_str, str(e)))

            self.seps = seps[1:-1]
Example #3
0
File: version.py Project: gst/rez
 def __init__(self, token):
     if token is None:
         self.subtokens = None
     elif not self.regex.match(token):
         raise VersionError("Invalid version token: '%s'" % token)
     else:
         self.subtokens = self._parse(token)
Example #4
0
 def __init__(self, lower=None, upper=None):
     self.lower = lower or _LowerBound.min
     self.upper = upper or _UpperBound.inf
     if (self.lower.version > self.upper.version) \
         or ((self.lower.version == self.upper.version)
             and not (self.lower.inclusive and self.upper.inclusive)):
         raise VersionError("Invalid bound")
Example #5
0
File: version.py Project: gst/rez
    def from_version(cls, version, op=None):
        """Create a range from a version.

        Args:
            version: Version object. This is used as the upper/lower bound of
                the range.
            op: Operation as a string. One of 'gt'/'>', 'gte'/'>=', lt'/'<',
                'lte'/'<=', 'eq'/'=='. If None, a bounded range will be created
                that contains the version superset.

        Returns:
            `VersionRange` object.
        """
        lower = None
        upper = None

        if op is None:
            lower = _LowerBound(version, True)
            upper = _UpperBound(version.next(), False)
        elif op in ("eq", "=="):
            lower = _LowerBound(version, True)
            upper = _UpperBound(version, True)
        elif op in ("gt", ">"):
            lower = _LowerBound(version, False)
        elif op in ("gte", ">="):
            lower = _LowerBound(version, True)
        elif op in ("lt", "<"):
            upper = _UpperBound(version, False)
        elif op in ("lte", "<="):
            upper = _UpperBound(version, True)
        else:
            raise VersionError("Unknown bound operation '%s'" % op)

        bound = _Bound(lower, upper)
        range = cls(None)
        range.bounds = [bound]
        return range
Example #6
0
File: version.py Project: gst/rez
 def __init__(self, version, inclusive):
     self.version = version
     self.inclusive = inclusive
     if not version and not inclusive:
         raise VersionError("Invalid upper bound: '%s'" % str(self))
Example #7
0
File: version.py Project: gst/rez
 def __init__(self, token):
     if not token.isdigit():
         raise VersionError("Invalid version token: '%s'" % token)
     else:
         self.n = int(token)