Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A093E200C7E for ; Mon, 8 May 2017 18:19:11 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9C23A160BA5; Mon, 8 May 2017 16:19:11 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C8ADB160BCB for ; Mon, 8 May 2017 18:19:10 +0200 (CEST) Received: (qmail 69796 invoked by uid 500); 8 May 2017 16:19:09 -0000 Mailing-List: contact dev-help@ariatosca.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ariatosca.incubator.apache.org Delivered-To: mailing list dev@ariatosca.incubator.apache.org Received: (qmail 69607 invoked by uid 99); 8 May 2017 16:19:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 May 2017 16:19:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id D610F1A7ACB for ; Mon, 8 May 2017 16:19:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.002 X-Spam-Level: X-Spam-Status: No, score=-100.002 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 3inWZky3FECS for ; Mon, 8 May 2017 16:19:07 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 55C7E5FE3F for ; Mon, 8 May 2017 16:19:06 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 2903DE0DC8 for ; Mon, 8 May 2017 16:19:05 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 6A5AF21E09 for ; Mon, 8 May 2017 16:19:04 +0000 (UTC) Date: Mon, 8 May 2017 16:19:04 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@ariatosca.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (ARIA-140) General purpose version comparison MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 08 May 2017 16:19:11 -0000 [ https://issues.apache.org/jira/browse/ARIA-140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16001016#comment-16001016 ] ASF GitHub Bot commented on ARIA-140: ------------------------------------- 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. > General purpose version comparison > ---------------------------------- > > Key: ARIA-140 > URL: https://issues.apache.org/jira/browse/ARIA-140 > Project: AriaTosca > Issue Type: Story > Reporter: Tal Liron > Assignee: Tal Liron > Priority: Minor > > Add {{aria.utils.versions}} to allow for general-purpose comparison and sorting of version strings. > For now this will be used for resolving plugin specifications to plugins, but it may very well have other uses in the future. -- This message was sent by Atlassian JIRA (v6.3.15#6346)