You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by tliron <gi...@git.apache.org> on 2017/04/14 22:02:25 UTC

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

GitHub user tliron opened a pull request:

    https://github.com/apache/incubator-ariatosca/pull/100

    ARIA-140 Version utils

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/apache/incubator-ariatosca ARIA-140-version-utils

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-ariatosca/pull/100.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #100
    
----
commit 3f11fd718c9ee7d96a332ef23c2806086aacc384
Author: Tal Liron <ta...@gmail.com>
Date:   2017-04-14T18:39:02Z

    ARIA-140 Version utils

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115142636
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    +
    +    # Split to primary and qualifier on '-'
    +    split = version.split('-', 2)
    +    if len(split) == 2:
    +        primary, qualifier = split
    +    else:
    +        primary = split[0]
    +        qualifier = None
    +
    +    # Parse primary
    +    split = primary.split('.')
    +    primary = []
    +    for element in split:
    +        if _DIGITS_RE.match(element) is None:
    +            # Invalid version string
    +            return _NULL
    +        try:
    +            element = int(element)
    +        except ValueError:
    +            # Invalid version string
    +            return _NULL
    +        primary.append(element)
    +
    +    # Remove redundant zeros
    +    for element in reversed(primary):
    +        if element == 0:
    +            primary.pop()
    +        else:
    +            break
    +    primary = tuple(primary)
    +
    +    # Parse qualifier
    +    if qualifier is not None:
    +        if _DIGITS_RE.match(qualifier) is not None:
    +            # Integer qualifer
    +            try:
    +                qualifier = float(int(qualifier))
    +            except ValueError:
    +                # Invalid version string
    +                return _NULL
    +        else:
    +            # Prefixed integer qualifier
    +            value = None
    +            qualifier = qualifier.lower()
    +            for prefix, factor in _PREFIXES.iteritems():
    +                if qualifier.startswith(prefix):
    +                    value = qualifier[len(prefix):]
    +                    if _DIGITS_RE.match(value) is None:
    +                        # Invalid version string
    +                        return _NULL
    +                    try:
    --- End diff --
    
    And again.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115281253
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    --- End diff --
    
    Because "Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" > "1.1-beta1". The qualifier is a float that is an extra, but if the qualifier is not present "infinity" should always win over it. It shouldn't matter what's "more natural" seeming: this is an underscored internal var that's never seen by users of the lib.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115288142
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    +
    +    # Split to primary and qualifier on '-'
    +    split = version.split('-', 2)
    +    if len(split) == 2:
    +        primary, qualifier = split
    +    else:
    +        primary = split[0]
    +        qualifier = None
    +
    +    # Parse primary
    +    split = primary.split('.')
    +    primary = []
    +    for element in split:
    +        if _DIGITS_RE.match(element) is None:
    +            # Invalid version string
    +            return _NULL
    +        try:
    +            element = int(element)
    +        except ValueError:
    +            # Invalid version string
    +            return _NULL
    +        primary.append(element)
    +
    +    # Remove redundant zeros
    +    for element in reversed(primary):
    +        if element == 0:
    +            primary.pop()
    +        else:
    +            break
    +    primary = tuple(primary)
    +
    +    # Parse qualifier
    +    if qualifier is not None:
    +        if _DIGITS_RE.match(qualifier) is not None:
    +            # Integer qualifer
    +            try:
    +                qualifier = float(int(qualifier))
    +            except ValueError:
    +                # Invalid version string
    +                return _NULL
    +        else:
    +            # Prefixed integer qualifier
    +            value = None
    +            qualifier = qualifier.lower()
    +            for prefix, factor in _PREFIXES.iteritems():
    +                if qualifier.startswith(prefix):
    +                    value = qualifier[len(prefix):]
    +                    if _DIGITS_RE.match(value) is None:
    +                        # Invalid version string
    +                        return _NULL
    +                    try:
    +                        value = float(int(value)) * factor
    +                    except ValueError:
    +                        # Invalid version string
    +                        return _NULL
    +                    break
    +            if value is None:
    +                # Invalid version string
    +                return _NULL
    +            qualifier = value
    +    else:
    +        # Version strings with no qualifiers are higher
    +        qualifier = _INF
    +
    +    return primary, qualifier
    +
    +
    +VersionString.NULL = VersionString()
    --- End diff --
    
    It's a constant for the user to use in any situation where they need a `NULL` value. It's customary to provide singletons for efficiency.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115141677
  
    --- Diff: aria/modeling/service_template.py ---
    @@ -33,7 +33,8 @@
     from ..parser import validation
     from ..parser.consumption import ConsumptionContext
     from ..parser.reading import deepcopy_with_locators
    -from ..utils import collections, formatting, console
    +from ..utils import (collections, formatting, console)
    --- End diff --
    
    According to https://cwiki.apache.org/confluence/display/ARIATOSCA/Code+Style+Guidelines, section 5c, these should be separated into multiple lines.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115288925
  
    --- Diff: aria/modeling/service_template.py ---
    @@ -33,7 +33,8 @@
     from ..parser import validation
     from ..parser.consumption import ConsumptionContext
     from ..parser.reading import deepcopy_with_locators
    -from ..utils import collections, formatting, console
    +from ..utils import (collections, formatting, console)
    --- End diff --
    
    We have discussed this and have agreed that it can be in one line if it fits. We have a lot of code that is like this.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115285799
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    +
    +    # Split to primary and qualifier on '-'
    +    split = version.split('-', 2)
    +    if len(split) == 2:
    +        primary, qualifier = split
    +    else:
    --- End diff --
    
    Oops, yes, changed to rsplit on 1.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115144550
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    --- End diff --
    
    How can version be `None` here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115142924
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    --- End diff --
    
    Why is `_NULL` not `(), 0`? Seems more natural, as it represents an invalid version string.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115142886
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    +
    +    # Split to primary and qualifier on '-'
    +    split = version.split('-', 2)
    +    if len(split) == 2:
    +        primary, qualifier = split
    +    else:
    --- End diff --
    
    The `2` in `split` means you include the part to the right of the second separator as the third element in the result.
    Which means that if you get passed `1.2-3-beta4`, you will treat it as a valid version string with the value `1.2`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-ariatosca/pull/100


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115287946
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    +
    +    # Split to primary and qualifier on '-'
    +    split = version.split('-', 2)
    +    if len(split) == 2:
    +        primary, qualifier = split
    +    else:
    +        primary = split[0]
    +        qualifier = None
    +
    +    # Parse primary
    +    split = primary.split('.')
    +    primary = []
    +    for element in split:
    +        if _DIGITS_RE.match(element) is None:
    +            # Invalid version string
    +            return _NULL
    +        try:
    --- End diff --
    
    Maybe it's too many digits for the current Python platform's size of int? Seems to me that it's best not to assume it would always work. Utility methods need to be especially robust.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115289497
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    --- End diff --
    
    Because "Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" > "1.1-beta1". The qualifier is a float that is an extra, but if the qualifier is not present "infinity" should always win over it. It shouldn't matter what's "more natural" seeming: this is an underscored internal var that's never seen by users of the lib. Users instead use `VersionString.NULL` or can init `VersionString` with None.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115142082
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    +
    +    # Split to primary and qualifier on '-'
    +    split = version.split('-', 2)
    +    if len(split) == 2:
    +        primary, qualifier = split
    +    else:
    +        primary = split[0]
    +        qualifier = None
    +
    +    # Parse primary
    +    split = primary.split('.')
    +    primary = []
    +    for element in split:
    +        if _DIGITS_RE.match(element) is None:
    +            # Invalid version string
    +            return _NULL
    +        try:
    --- End diff --
    
    If, on the previous `if`, we ensured that the element is a sequence of numbers, what bad things can happen when trying to convert it into an `int`?
    i.e, why is this stage necessary?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115281803
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    --- End diff --
    
    Because "Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" > "1.1-beta1". The qualifier is a float that is an extra, but if the qualifier is not present "infinity" should always win over it. It shouldn't matter what's "more natural" seeming: this is an underscored internal var that's never seen by users of the lib. Users instead use `VersionString.NULL` or can init `VersionString` with None.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115142635
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    +
    +    # Split to primary and qualifier on '-'
    +    split = version.split('-', 2)
    +    if len(split) == 2:
    +        primary, qualifier = split
    +    else:
    +        primary = split[0]
    +        qualifier = None
    +
    +    # Parse primary
    +    split = primary.split('.')
    +    primary = []
    +    for element in split:
    +        if _DIGITS_RE.match(element) is None:
    +            # Invalid version string
    +            return _NULL
    +        try:
    +            element = int(element)
    +        except ValueError:
    +            # Invalid version string
    +            return _NULL
    +        primary.append(element)
    +
    +    # Remove redundant zeros
    +    for element in reversed(primary):
    +        if element == 0:
    +            primary.pop()
    +        else:
    +            break
    +    primary = tuple(primary)
    +
    +    # Parse qualifier
    +    if qualifier is not None:
    +        if _DIGITS_RE.match(qualifier) is not None:
    +            # Integer qualifer
    +            try:
    --- End diff --
    
    Same as before, what can be a problem here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115289271
  
    --- Diff: aria/modeling/service_template.py ---
    @@ -2131,13 +2132,15 @@ def resolve(self, model_storage):
             # moved to.
             plugins = model_storage.plugin.list()
             matching_plugins = []
    -        for plugin in plugins:
    -            # TODO: we need to use a version comparator
    -            if (plugin.name == self.name) and \
    -                    ((self.version is None) or (plugin.package_version >= self.version)):
    -                matching_plugins.append(plugin)
    +        if plugins:
    +            for plugin in plugins:
    +                if (plugin.name == self.name) and \
    --- End diff --
    
    I strongly disagree, especially in this case when there is `or` and `and` in the same clause. Do you otherwise expect the reader to know the priority of logical binary operations? Parentheses remove any potential confusion.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115145852
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    +
    +    # Split to primary and qualifier on '-'
    +    split = version.split('-', 2)
    +    if len(split) == 2:
    +        primary, qualifier = split
    +    else:
    +        primary = split[0]
    +        qualifier = None
    +
    +    # Parse primary
    +    split = primary.split('.')
    +    primary = []
    +    for element in split:
    +        if _DIGITS_RE.match(element) is None:
    +            # Invalid version string
    +            return _NULL
    +        try:
    +            element = int(element)
    +        except ValueError:
    +            # Invalid version string
    +            return _NULL
    +        primary.append(element)
    +
    +    # Remove redundant zeros
    +    for element in reversed(primary):
    +        if element == 0:
    +            primary.pop()
    +        else:
    +            break
    +    primary = tuple(primary)
    +
    +    # Parse qualifier
    +    if qualifier is not None:
    +        if _DIGITS_RE.match(qualifier) is not None:
    +            # Integer qualifer
    +            try:
    +                qualifier = float(int(qualifier))
    +            except ValueError:
    +                # Invalid version string
    +                return _NULL
    +        else:
    +            # Prefixed integer qualifier
    +            value = None
    +            qualifier = qualifier.lower()
    +            for prefix, factor in _PREFIXES.iteritems():
    +                if qualifier.startswith(prefix):
    +                    value = qualifier[len(prefix):]
    +                    if _DIGITS_RE.match(value) is None:
    +                        # Invalid version string
    +                        return _NULL
    +                    try:
    +                        value = float(int(value)) * factor
    +                    except ValueError:
    +                        # Invalid version string
    +                        return _NULL
    +                    break
    +            if value is None:
    +                # Invalid version string
    +                return _NULL
    +            qualifier = value
    +    else:
    +        # Version strings with no qualifiers are higher
    +        qualifier = _INF
    +
    +    return primary, qualifier
    +
    +
    +VersionString.NULL = VersionString()
    --- End diff --
    
    What is the purpose of this NULL? I don't see any use of it except in the tests.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115141664
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    --- End diff --
    
    This line will always be called, since `version` cannot be `None`.
    And except the case when `VersionString` is called with no arguments, this line was already called in `__init__`.
    In addition, in all of your tests, you never pass through line 93.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115289426
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    --- End diff --
    
    It is true, there is no tests for this function specifically with a None value. I will add it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca issue #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on the issue:

    https://github.com/apache/incubator-ariatosca/pull/100
  
    Responses.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115289404
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    --- End diff --
    
    This is a user-exposed function and None values do occur in the wild.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca issue #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on the issue:

    https://github.com/apache/incubator-ariatosca/pull/100
  
    @tliron and I discussed his replies via zoom, and this pull request is free to merge (with minor changes).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115141706
  
    --- Diff: aria/modeling/service_template.py ---
    @@ -2131,13 +2132,15 @@ def resolve(self, model_storage):
             # moved to.
             plugins = model_storage.plugin.list()
             matching_plugins = []
    -        for plugin in plugins:
    -            # TODO: we need to use a version comparator
    -            if (plugin.name == self.name) and \
    -                    ((self.version is None) or (plugin.package_version >= self.version)):
    -                matching_plugins.append(plugin)
    +        if plugins:
    +            for plugin in plugins:
    +                if (plugin.name == self.name) and \
    --- End diff --
    
    I know that wrapping `if` conditions with parenthesis is your thing, but in this case it seems to cause some clutter...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by AviaE <gi...@git.apache.org>.
Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115145936
  
    --- Diff: aria/modeling/service_template.py ---
    @@ -33,7 +33,8 @@
     from ..parser import validation
    --- End diff --
    
    Please expand the commit message by adding information on the purpose of your change/addition.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115288664
  
    --- Diff: aria/modeling/service_template.py ---
    @@ -33,7 +33,8 @@
     from ..parser import validation
    --- End diff --
    
    I don't understand. What does this have to do with this line in the code? Where in the commit message? We have limited our commit messages to one line with reference to the JIRA for more information. I know you tend to add more info, but the rest of us don't normally.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115281656
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    --- End diff --
    
    Already in line #64 do you see the default to be None. But anyway, this is a user-exposed function and None values do occur in the wild.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #100: ARIA-140 Version utils

Posted by tliron <gi...@git.apache.org>.
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/100#discussion_r115282963
  
    --- Diff: aria/utils/versions.py ---
    @@ -0,0 +1,162 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +General-purpose version string handling
    +"""
    +
    +import re
    +
    +
    +_INF = float('inf')
    +
    +_NULL = (), _INF
    +
    +_DIGITS_RE = re.compile(r'^\d+$')
    +
    +_PREFIXES = {
    +    'dev':   0.0001,
    +    'alpha': 0.001,
    +    'beta':  0.01,
    +    'rc':    0.1
    +}
    +
    +
    +class VersionString(unicode):
    +    """
    +    Version string that can be compared, sorted, made unique in a set, and used as a unique dict
    +    key.
    +
    +    The primary part of the string is one or more dot-separated natural numbers. Trailing zeroes
    +    are treated as redundant, e.g. "1.0.0" == "1.0" == "1".
    +
    +    An optional qualifier can be added after a "-". The qualifier can be a natural number or a
    +    specially treated prefixed natural number, e.g. "1.1-beta1" > "1.1-alpha2". The case of the
    +    prefix is ignored.
    +
    +    Numeric qualifiers will always be greater than prefixed integer qualifiers, e.g. "1.1-1" >
    +    "1.1-beta1".
    +
    +    Versions without a qualifier will always be greater than their equivalents with a qualifier,
    +    e.g. e.g. "1.1" > "1.1-1".
    +
    +    Any value that does not conform to this format will be treated as a zero version, which would
    +    be lesser than any non-zero version.
    +
    +    For efficient list sorts use the ``key`` property, e.g.:
    +    ``sorted(versions, key=lambda x: x.key)``
    +    """
    +
    +    NULL = None # initialized below
    +
    +    def __init__(self, value=None):
    +        if value is not None:
    +            super(VersionString, self).__init__(value)
    +        self.key = parse_version_string(self)
    +
    +    def __eq__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key == version.key
    +
    +    def __lt__(self, version):
    +        if not isinstance(version, VersionString):
    +            version = VersionString(version)
    +        return self.key < version.key
    +
    +    def __hash__(self):
    +        return self.key.__hash__()
    +
    +
    +def parse_version_string(version): # pylint: disable=too-many-branches
    +    """
    +    Parses a version string.
    +
    +    :param version: The version string
    +    :returns: The primary tuple and qualifier float
    +    :rtype: ((int), float)
    +    """
    +
    +    if version is None:
    +        return _NULL
    +    version = unicode(version)
    --- End diff --
    
    It is true, there is no test for this function specifically with a None value. I will add it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---