Compare function for package version sorting
480598
def _cmp_version(item1, item2):
    '''
    
    '''
    vers1 = _LooseVersion(item1)
    vers2 = _LooseVersion(item2)

    if vers1 < vers2:
        return -1
    if vers1 > vers2:
        return 1
    return 0
1323302
def _compare_by_version(path1, path2):
    
    if path1.source == path2.source:
        if path1.source_version_num > path2.source_version_num:
            return path1
        else:
            return path2
    return None
747649
def _recursive_compare(v1, v2):
    '''
    
    '''
    if isinstance(v1, list):
        if v2 is None:
            v2 = []
        if len(v1) != len(v2):
            return False
        v1.sort(key=_id_or_key)
        v2.sort(key=_id_or_key)
        for x, y in zip(v1, v2):
            if not _recursive_compare(x, y):
                return False
        return True
    elif isinstance(v1, dict):
        if v2 is None:
            v2 = {}
        v1 = dict(v1)
        v2 = dict(v2)
        if sorted(v1) != sorted(v2):
            return False
        for k in v1:
            if not _recursive_compare(v1[k], v2[k]):
                return False
        return True
    else:
        return v1 == v2
1360628
def _version_checker(module, minver):
    
    # We could use LooseVersion, but distutils imports imp which is deprecated
    version_regexp = r'[a-z]?((?:\d|\.)+\d+)(?:\.dev[0-9]+)?'
    version_tags = re.match(version_regexp, module.__version__)
    if not version_tags:
        return False
    version_tags = version_tags.group(1).split(".")
    version_tags = tuple(int(x) for x in version_tags)
    return version_tags >= minver
1029577
def package_version(package_name: str) -> typing.Optional[str]:
    

    try:
        return pkg_resources.get_distribution(package_name).version
    except (pkg_resources.DistributionNotFound, AttributeError):
        return None
514234
def version(self):
        
        if self.find:
            return self.meta.sp + split_package(self.find)[1]
        return ""
1337395
function Compare () {

    var self = this;

    function compare (current, previous) {

        // all up/down properties are arrays of string.
        var build = {
                up: {
                    createTable: [],
                    dropTable: [],
                    dropTables: [],
                    addColumn: [],
                    changeColumn: [],
                    removeColumn: []
                    //renameTable: [],  // TODO future feature.
                    //renameColumn: [], // TODO future feature.
                    //addIndex: [],     // TODO future feature.
                    //removeIndex: []   // TODO future feature.
                },
                down: {
                    createTable: [],
                    dropTable: [],
                    dropTables: [],
                    addColumn: [],
                    changeColumn: [],
                    removeColumn: []
                    //renameTable: [],  // TODO future feature.
                    //renameColumn: [], // TODO future feature.
                    //addIndex: [],     // TODO future feature.
                    //removeIndex: []   // TODO future feature.
                },
                options: []
            },
            validAttrs = self.migConf.validAttributes,
            excludeAttrs = self.migConf.excludeAttributes,
            typeVariable = self.migConf.typeVariable || 'types',
            modelName = current.name,
            baseTabs = 2;

        function getTabs(int, addBase) {
            var tabs = '';
            if(addBase)
                int += baseTabs;
            while(int){
                tabs += '\t';
                --int;
            }
            return tabs;
        }

        function isValid(attr) {
            return validAttrs.indexOf(attr) !== -1;
        }

        function qwrap(str) {
            return "'" + str + "'";
        }

        function getActions(type) {
            var actions = [];
            _.forEach(type, function (v) {
                if(v.length) actions.push(v);
            });
            return actions;
        }

        function filterAttributes(obj) {
            var clone = _.clone(obj);
            _.forEach(clone, function (v,k) {
                if(!isValid(k))
                delete clone[k];
            });
            return clone;
        }

        function arrayToString(arr, def) {
            var val = '[';
            def = def || undefined;
            if(!arr || !arr.length)
                return def;
            if(!_.isString(arr[0])){
                val += arr.join(',');
            }else {
                _.forEach(arr, function (v) {
                    val += qwrap(v) + ',';
                });
                val = val.slice(0, val.length -1);
            }
            val += ']';
           return val;
        }

        function funcToString(func, level) {
            var split = func.split('\n'),
                tmp = [];
            _.forEach(split, function (v, k) {
                v = v.replace(/^\s+/, '').replace('\r', '');
                if(k +1 === split.length)
                    tmp.push(getTabs(level + 1, true) + v);
                else if(k > 0)
                    tmp.push(getTabs(level + 2, true) + v);
                else tmp.push(v);
            });
            return tmp.join('\n');
        }

        /**
         * Concats all up migration events to string.
         * @private
         * @memberof Compare
         * @returns {string}
         */
        function upToString() {
            var upStr = '',
                ctr = 0,
                items = getActions(build.up),
                tab,
                suffix;
            // build the output string for up.
            _.forEach(items, function (v,k) {
                _.forEach(v, function(item, key){
                    suffix = (ctr < v.length -1) || (k+1 < items.length) ? '\n' : '';
                    tab = ctr > 0 ? getTabs(0, true) : '';
                    upStr += (tab + item + suffix);
                    ctr += 1;
                });
            });
            return upStr;
        }

        /**
         * Concats all down migration events to string.
         * @private
         * @memberof Compare
         * @returns {string}
         */
        function downToString() {
            var dwnStr = '',
                ctr = 0,
                items = getActions(build.down),
                tab,
                suffix;
            // build the output string for down.
            _.forEach(items, function (v,k) {
                _.forEach(v, function(item, key){
                    suffix = (ctr < v.length -1) || (k+1 < items.length) ? '\n' : '';
                    tab = ctr > 0 ? getTabs(0, true) : '';
                    dwnStr += (tab + item + suffix);
                    ctr += 1;
                });
            });
            return dwnStr;
        }

        /**
         * Recurse child options concat to string.
         * @private
         * @memberof Compare
         * @param {object} obj - the child object.
         * @returns {string}
         */
        function recurseChildOptions(obj, level){
            var child = '',
                len = Object.keys(obj).length,
                ctr = 0,
                prefix;
            level = level || 1;
            for(var prop in obj) {
                if(obj.hasOwnProperty(prop)){
                    var tab = getTabs(level +1, true),
                        val;
                    prefix = ctr > 0 ? ',\n' : '';
                    if(_.isPlainObject(obj[prop])){
                        if(!_.isEmpty(obj[prop])){
                            var subChild = recurseChildOptions(obj[prop], level + 1);
                            if(subChild && subChild.length)
                                child += (tab + prop + ': { \n' + subChild + '\n' + tab + '}');
                        }
                    } else {
                        if(_.isArray(obj[prop])){
                            val = arrayToString(obj[prop]);
                            if(val){
                                tab = ctr === 0 ? getTabs(level) : getTabs(level +1, true);
                                child += (prefix + tab + prop + ': ' + arrayToString(obj[prop]));
                            }
                        } else {
                            var isFunc;
                            val = obj[prop];
                            isFunc = _.isFunction(val);
                            if(_.isString(val)){
                                val = "'" + val.toString() + "'";
                            } else {
                                val = val.toString();
                                if(isFunc)
                                    val = funcToString(val, level);
                            }
                            child += (prefix + tab + prop + ': ' + val);
                        }
                    }
                    ctr +=1;
                }
            }
            return child;
        }

        /**
         * Parse options for create model migrations.
         * @private
         * @memberof Compare
         * @param {object} obj - the object of options.
         */
        function parseOptions(obj) {
            var ctr = 0,
                tab = getTabs(1, true);
            for(var prop in obj) {
                if(obj.hasOwnProperty(prop)){
                    if(_.isPlainObject(obj[prop])){
                        if(!_.isEmpty(obj[prop])){
                            var child = recurseChildOptions(obj[prop]);
                            if(child && child.length)
                                build.options.push(tab + prop + ': { \n' + child + ' \n' + tab + '}');
                        }
                    } else {
                        if(_.isArray(obj[prop])){
                            build.options.push(tab + prop + ': ' + arrayToString(obj[prop]));
                        } else {
                            var val = obj[prop];
                            if(_.isString(val))
                                val = qwrap(val);
                            else
                                val = val.toString();
                            build.options.push(tab + prop + ': ' + val);
                        }
                    }
                }
                ctr +=1;
            }

        }

        /**
         * Converts a property's atttributes to string.
         * @private
         * @memberof Compare
         * @param {object} obj - the object of attributes.
         * @param {object} prevObj - the previous object of attributes from last snapshot.
         * @returns {string}
         */
        function attributesToString(obj, prevObj, level) {
            var attrs = '',
                prefix,
                tab;
            level = level || 1;
            tab = getTabs(level, true);
            _.forEach(obj, function (v, k) {
                if(excludeAttrs.indexOf(k) === -1){
                    var prev = prevObj && prevObj[k] !== undefined ? prevObj[k] : undefined;
                    prefix = attrs.length ? ',\n' : '';
                    if(_.isPlainObject(v)){
                        var subAttr = attributesToString(v, prev, level +1);
                        if(subAttr && subAttr.length)
                            attrs += (prefix + tab + k + ': {\n' + subAttr + '\n' + tab + '}');
                    } else {
                        if(prev !== v){
                            var val = k === 'type' ? 'types.' + v : v;
                            if(_.isArray(val))
                                val = arrayToString(val);
                            if(_.isFunction(val)){
                                val = funcToString(val.toString(), 2);
                            }
                            attrs += (prefix + tab + k + ': ' + val);
                        }
                    }
                }
            });

            return attrs;
        }

        /**
         * Iterate table/model properties and compare or create new.
         * @private
         * @memberof Compare
         */
        function compareMigration(){

            var tab

            // the model/table already exists.
            if(previous){

                tab = getTabs(0, true),

                // compare to previous table checking for
                // any dropped columns.
                _.forEach(previous.attributes, function (v,k) {
                    if (v._modelAttribute) {
                        var curCol = current && current.attributes ? current.attributes[k] : undefined,
                            removeAttrs;
                        // if curCol is undefined it was removed.
                        if(!curCol){
                            removeAttrs = attributesToString(filterAttributes(v));
                            if(removeAttrs) {
                                build.up.removeColumn.push(
                                        'migration.removeColumn(' + qwrap(modelName) + ', ' + qwrap(k) + ');'
                                );
                                build.down.addColumn.push(
                                        'migration.addColumn(' + qwrap(modelName) + ', ' + qwrap(k) + ',\n' +
                                        tab + '{\n'+ removeAttrs + '\n' + tab + '});'
                                );
                            }
                        }
                    }

                });

                // iterate current defined attrs
                // looking for adds & changes.
                _.forEach(current.attributes, function (v,k) {

                    if(v._modelAttribute){
                        // check if is new column or existing.
                        var prevCol = previous.attributes ? previous.attributes[k] : undefined,
                            prevAttrs, curAttrs;

                        if(prevCol){

                            curAttrs = attributesToString(filterAttributes(v), filterAttributes(prevCol));
                            prevAttrs = attributesToString(filterAttributes(prevCol), filterAttributes(v));

                            if(curAttrs) {
                                build.up.changeColumn.push(
                                        'migration.changeColumn(' + qwrap(modelName) + ', ' + qwrap(k) + ',\n' +
                                        tab + '{\n' + curAttrs + '\n' + tab + '});'
                                );
                            }

                            if(prevAttrs) {
                                build.down.changeColumn.push(
                                        'migration.changeColumn(' + qwrap(modelName) + ', ' + qwrap(k) + ',\n' +
                                        tab + '{\n' +  prevAttrs + '\n' + tab +'});'
                                );
                            }

                        } else {

                            curAttrs = attributesToString(filterAttributes(v));
                            // column needs to be added.

                            if(curAttrs) {
                                build.up.addColumn.push(
                                        'migration.addColumn(' + qwrap(modelName) + ', ' + qwrap(k) + ',\n' +
                                        '{\n' + curAttrs + '\n' + tab + '});'
                                );
                                build.down.removeColumn.push(
                                        'migration.removeColumn(' + qwrap(modelName) + ', ' + qwrap(k) + ');'
                                );
                            }

                        }
                    }

                    ctr += 1;

                });

            }

            // this is a new model/table.
            else {

                // this is a new table so we need to parse options.
                var newAttrs = [],
                    ctr = 0,
                    attrTab = getTabs(1, true),
                    newOpts;

                tab = getTabs(0, true);

                parseOptions(current.options);
                newOpts = build.options.join(',\n')

                _.forEach(current.attributes, function (v,k) {

                    //if (v._modelAttribute) {
                        var attrs = attributesToString(filterAttributes(v), null, 2);
                        if(attrs) newAttrs.push(attrTab + k + ': {\n' + attrs + '\n' + attrTab + '}');
                    //}
                    ctr +=1;
                });

                build.up.createTable.push(
                        'migration.createTable(' + qwrap(modelName) + ',\n' +
                        tab + '{\n' + newAttrs.join(',\n') + '\n' + tab + '},\n' +
                        tab + '{\n' + newOpts + '\n' + tab + '});'
                );
                build.down.dropTable.push('migration.dropTable(' + qwrap(modelName) + ');');

            }

            build.up.toString = upToString;
            build.down.toString = downToString;
        }

        // parse properties attributes & options.
        compareMigration();

        return build;

    };

    return compare;

}
102031
function sortCompare(left, right) {
        var hasj = $hasOwn(left, 0),
            hask = $hasOwn(right, 0),
            typex,
            typey,
            val;

        if (!hasj && !hask) {
            val = +0;
        } else if (!hasj) {
            val = 1;
        } else if (!hask) {
            val = -1;
        } else {
            typex = typeof left[0];
            typey = typeof right[0];
            if (typex === 'undefined' && typey === 'undefined') {
                val = +0;
            } else if (typex === 'undefined') {
                val = 1;
            } else if (typey === 'undefined') {
                val = -1;
            }
        }

        return val;
    }
1045277
def squash_old_versions
      specifiers = map_specifiers_to_versions

      compare_versions = lambda do |x, y|
        v_x = x =~ Lyp::PACKAGE_RE && Lyp.version($2)
        v_y = y =~ Lyp::PACKAGE_RE && Lyp.version($2)
        x <=> y
      end

      specifiers.each do |package, clauses|
        # Remove old versions only if the package is referenced using a single
        # specifier clause
        next unless clauses.size == 1

        specs = clauses.values.first
        specs.each do |s|
          if s.versions.values.uniq.size == 1
            versions = s.versions.keys.sort(&compare_versions)
            latest = versions.last
            s.versions.select! {|k, v| k == latest}
          end
        end
      end
    end
1044886
def _get_version():
    """"""

    with open(join(dirname(__file__), '{{project.package}}/VERSION'), 'rb') as f:
        version = f.read().decode('ascii').strip()
    return version
1349226
public static int compareVersions(String v1, String v2) {
		String s1 = normalisedVersion(v1);
		String s2 = normalisedVersion(v2);
		return s1 != null ? (s2 != null ? s1.compareTo(s2) : 1)
				: (s2 != null ? -1 : 0);
	}
528902
function sortDjangoVersions(versions) {
  return versions.sort((a, b) => {
    if (
      parseDjangoVersionString(a).major === parseDjangoVersionString(b).major
    ) {
      return (
        parseDjangoVersionString(a).minor - parseDjangoVersionString(b).minor
      )
    } else {
      return (
        parseDjangoVersionString(a).major - parseDjangoVersionString(b).major
      )
    }
  })
}
188932
function compareDottedVersion(v1, v2) {
  const parts1 = /([0-9.]+)(.*)$/.exec(v1)
  const parts2 = /([0-9.]+)(.*)$/.exec(v2)
  if (parts1 != null && parts2 != null) {
    const numbers1 = parts1[1]
    const numbers2 = parts2[1]
    const distinguisher1 = parts1[2]
    const distinguisher2 = parts2[2]
    const numlist1 = numbers1.split('.').map(e => +e)
    const numlist2 = numbers2.split('.').map(e => +e)
    const cmp = listCompare(numlist1, numlist2)
    if (cmp !== 0) {
      return cmp
    } else {
      return distinguisher1 < distinguisher2
        ? -1
        : distinguisher1 > distinguisher2
        ? 1
        : 0
    }
  }
  return v1 < v2 ? -1 : v1 > v2 ? 1 : 0
}
529359
public static int compareVersions(String version_1, String version_2)
	{
		for (int j = 0; j < Math.min(version_2.length(), version_1.length()); j++)
		{

			char v1_c = version_1.charAt(j);
			char v2_c = version_2.charAt(j);

			if (v1_c == v2_c)
			{

				continue;
			}

			if (v2_c == '.')
			{

				// version1 higher (e.g. 10.2 -vs- 1.2)

				return (+1);

			} else if (v1_c == '.')
			{

				// version2 higher ( e.g. 1.2 -vs- 10.2 )

				return (-1);

			} else
			{

				return (v1_c - v2_c);
			}
		}

		// longest one wins. e.g. 1.2.1 -vs- 1.2

		return (version_1.length() - version_2.length());
	}
817603
def compare_version(version1, version2):
    
    def normalize(v):
        return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
    return (normalize(version1) > normalize(version2))-(normalize(version1) < normalize(version2))
951567
def unpack_version(version):
    """"""
    minor_version = version % VERSION_MULTIPLIER
    major_version = (version - minor_version) / VERSION_MULTIPLIER
    return (major_version, minor_version)
986169
def _sort(self):
        
        self.versions = OrderedDict(sorted(self.versions.items(), key=lambda v: v[0]))