Exemplo n.º 1
0
 def version_key(self, fn, majoronly=False):
     rec = self.index[fn]
     if majoronly:
         return VersionOrder(rec['version'])
     else:
         return (VersionOrder(rec['version']), len(self.features(fn)),
                 rec['build_number'])
Exemplo n.º 2
0
def get_latest_build(package_name, preferred_channel=None):
    """
    Find the latest build of the given package and return a BuildInfo tuple.
    If the package can't be found in the cloud, None is returned in all fields. 
    
    package_name: The package to search for
    preferred_channel: If provided, the 'latest' version will always be chosen from this channel, if possible.
    """
    # Convert to unicode
    preferred_channel = preferred_channel and unicode(preferred_channel)

    # Search the cloud
    package_info = conda_search(package_name)
    if package_name not in package_info:
        return BuildInfo(None, None, None)  # Not found

    latest = None
    for file_details in package_info[package_name]:
        channel = file_details["channel"]
        version = file_details["version"]
        build_number = file_details['build_number']

        if latest is None:
            # First found is latest by default
            latest = BuildInfo(channel, file_details["version"], build_number)
            continue

        better = False

        # Channel is better
        better |= (preferred_channel is not None
                   and (channel == preferred_channel
                        and latest.channel != preferred_channel))

        # Channel is same, but version is better
        better |= ((preferred_channel is None or channel == latest.channel)
                   and VersionOrder(version) > VersionOrder(latest.version))

        # Channel and version are the same, but build_number is better
        better |= ((preferred_channel is None or channel == latest.channel)
                   and VersionOrder(version) == VersionOrder(latest.version)
                   and build_number > latest.build_number)

        if better:
            latest = BuildInfo(channel, file_details["version"], build_number)

    return latest
Exemplo n.º 3
0
 def __init__(self, fn, info):
     self.fn = fn
     self.name = info.get('name')
     self.version = info.get('version')
     self.build = info.get('build')
     if not (self.name and self.version and self.build):
         self.name, self.version, self.build = fn.rsplit('-',2)
     self.build_number = info.get('build_number')
     self.channel = info.get('channel')
     self.norm_version = VersionOrder(self.version)
     self.info = info
Exemplo n.º 4
0
def compare_recipe_to_pypi(recipe, env):
    """
    If it looks like a PyPI package, returns a tuple of
    (name, current_bioconda_version, latest_version_on_PyPI, needs_update).

    If it doesn't look like a PyPI package, then return None.

    If it looks like a PyPI package but the PyPI info can't be found (e.g.,
    "python-wget") then a tuple is returned but with a value of None for the
    latest version on PyPI and None for needs_update.
    """
    meta = utils.load_meta(os.path.join(recipe, 'meta.yaml'), env)
    current = meta['package']['version']
    name = meta['package']['name']

    try:
        source_url = meta['source']['url']
    except KeyError:
        return

    if 'pypi' in source_url:
        pypi = requests.get('http://pypi.python.org/pypi/' + name + '/json')
        if pypi.status_code == 200:
            contents = pypi.json()
            latest = contents['info']['version']
            needs_update = False
            if VersionOrder(latest) > VersionOrder(current):
                needs_update = True
            return (name, current, latest, needs_update)

        # We could do something like strip a leading `python-` off the name
        # (e.g., for python-wget) but this won't work in all cases and there
        # aren't that many of them anyway. So we just report that nothing was
        # found.
        else:
            return (name, current, None, None)
Exemplo n.º 5
0
    def __init__(self, fn, info):
        self.fn = fn
        self.name = info.get('name')
        self.version = info.get('version')
        self.build = info.get('build')
        if not (self.name and self.version and self.build):
            self.name, self.version, self.build = fn.rsplit('-', 2)
        self.build_number = info.get('build_number')
        self.channel = info.get('channel')
        try:
            self.norm_version = VersionOrder(self.version)
        except ValueError:
            stderrlog.error("\nThe following stack trace is in reference to "
                            "package:\n\n\t%s\n\n" % fn)
            raise

        self.info = info
Exemplo n.º 6
0
 def get_version(p):
     return VersionOrder(
         load_meta(os.path.join(p, 'meta.yaml'), env)['package']['version']
     )
Exemplo n.º 7
0
def normalized_version(version):
    return VersionOrder(version)
Exemplo n.º 8
0
    def test_version_order(self):
        versions = [
            (VersionOrder("0.4"), [[0], [0], [4]]),
            (VersionOrder("0.4.0"), [[0], [0], [4], [0]]),
            (VersionOrder("0.4.1a.vc11"), [[0], [0], [4], [1, 'a'],
                                           [0, 'vc', 11]]),
            (VersionOrder("0.4.1.rc"), [[0], [0], [4], [1], [0, 'rc']]),
            (VersionOrder("0.4.1.vc11"), [[0], [0], [4], [1], [0, 'vc', 11]]),
            (VersionOrder("0.4.1"), [[0], [0], [4], [1]]),
            (VersionOrder("0.5*"), [[0], [0], [5, '*']]),
            (VersionOrder("0.5a1"), [[0], [0], [5, 'a', 1]]),
            (VersionOrder("0.5b3"), [[0], [0], [5, 'b', 3]]),
            (VersionOrder("0.5C1"), [[0], [0], [5, 'c', 1]]),
            (VersionOrder("0.5z"), [[0], [0], [5, 'z']]),
            (VersionOrder("0.5za"), [[0], [0], [5, 'za']]),
            (VersionOrder("0.5"), [[0], [0], [5]]),
            (VersionOrder("0.5_5"), [[0], [0], [5], [5]]),
            (VersionOrder("0.5-5"), [[0], [0], [5], [5]]),
            (VersionOrder("0.9.6"), [[0], [0], [9], [6]]),
            (VersionOrder("0.960923"), [[0], [0], [960923]]),
            (VersionOrder("1.0"), [[0], [1], [0]]),
            (VersionOrder("1.0.4a3"), [[0], [1], [0], [4, 'a', 3]]),
            (VersionOrder("1.0.4b1"), [[0], [1], [0], [4, 'b', 1]]),
            (VersionOrder("1.0.4"), [[0], [1], [0], [4]]),
            (VersionOrder("1.1dev1"), [[0], [1], [1, 'DEV', 1]]),
            (VersionOrder("1.1a1"), [[0], [1], [1, 'a', 1]]),
            (VersionOrder("1.1.dev1"), [[0], [1], [1], [0, 'DEV', 1]]),
            (VersionOrder("1.1.a1"), [[0], [1], [1], [0, 'a', 1]]),
            (VersionOrder("1.1"), [[0], [1], [1]]),
            (VersionOrder("1.1.post1"), [[0], [1], [1], [0, float('inf'), 1]]),
            (VersionOrder("1.1.1dev1"), [[0], [1], [1], [1, 'DEV', 1]]),
            (VersionOrder("1.1.1rc1"), [[0], [1], [1], [1, 'rc', 1]]),
            (VersionOrder("1.1.1"), [[0], [1], [1], [1]]),
            (VersionOrder("1.1.1post1"), [[0], [1], [1], [1,
                                                          float('inf'), 1]]),
            (VersionOrder("1.1post1"), [[0], [1], [1, float('inf'), 1]]),
            (VersionOrder("2g6"), [[0], [2, 'g', 6]]),
            (VersionOrder("2.0b1pr0"), [[0], [2], [0, 'b', 1, 'pr', 0]]),
            (VersionOrder("2.2be.ta29"), [[0], [2], [2, 'be'], [0, 'ta', 29]]),
            (VersionOrder("2.2be5ta29"), [[0], [2], [2, 'be', 5, 'ta', 29]]),
            (VersionOrder("2.2beta29"), [[0], [2], [2, 'beta', 29]]),
            (VersionOrder("2.2.0.1"), [[0], [2], [2], [0], [1]]),
            (VersionOrder("3.1.1.6"), [[0], [3], [1], [1], [6]]),
            (VersionOrder("3.2.p.r0"), [[0], [3], [2], [0, 'p'], [0, 'r', 0]]),
            (VersionOrder("3.2.pr0"), [[0], [3], [2], [0, 'pr', 0]]),
            (VersionOrder("3.2.pr.1"), [[0], [3], [2], [0, 'pr'], [1]]),
            (VersionOrder("5.5.kw"), [[0], [5], [5], [0, 'kw']]),
            (VersionOrder("11g"), [[0], [11, 'g']]),
            (VersionOrder("14.3.1"), [[0], [14], [3], [1]]),
            (VersionOrder("14.3.1.post26.g9d75ca2"),
             [[0], [14], [3], [1], [0, float('inf'), 26],
              [0, 'g', 9, 'd', 75, 'ca', 2]]),
            (VersionOrder("1996.07.12"), [[0], [1996], [7], [12]]),
            (VersionOrder("1!0.4.1"), [[1], [0], [4], [1]]),
            (VersionOrder("1!3.1.1.6"), [[1], [3], [1], [1], [6]]),
            (VersionOrder("2!0.4.1"), [[2], [0], [4], [1]]),
        ]

        # check parser
        for v, l in versions:
            self.assertEqual(v.version, l)
        self.assertEqual(VersionOrder("0.4.1.rc"),
                         VersionOrder("  0.4.1.RC  "))
        self.assertEqual(normalized_version("  0.4.1.RC  "),
                         VersionOrder("0.4.1.rc"))
        with self.assertRaises(ValueError):
            VersionOrder("")
        with self.assertRaises(ValueError):
            VersionOrder("  ")
        with self.assertRaises(ValueError):
            VersionOrder("3.5&1")
        with self.assertRaises(ValueError):
            VersionOrder("5.5++")
        with self.assertRaises(ValueError):
            VersionOrder("5.5..mw")
        with self.assertRaises(ValueError):
            VersionOrder("5.5.mw.")
        with self.assertRaises(ValueError):
            VersionOrder("!")
        with self.assertRaises(ValueError):
            VersionOrder("a!1.0")
        with self.assertRaises(ValueError):
            VersionOrder("a!b!1.0")

        # check __eq__
        self.assertEqual(VersionOrder("  0.4.rc  "), VersionOrder("0.4.RC"))
        self.assertEqual(VersionOrder("0.4"), VersionOrder("0.4.0"))
        self.assertNotEqual(VersionOrder("0.4"), VersionOrder("0.4.1"))
        self.assertEqual(VersionOrder("0.4.a1"), VersionOrder("0.4.0a1"))
        self.assertNotEqual(VersionOrder("0.4.a1"), VersionOrder("0.4.1a1"))

        # check __lt__
        self.assertEqual(sorted(versions, key=lambda x: x[0]), versions)

        # test openssl convention
        openssl = [
            VersionOrder(k) for k in [
                '1.0.1', '1.0.1post.a', '1.0.1post.b', '1.0.1post.z',
                '1.0.1post.za', '1.0.2'
            ]
        ]
        self.assertEqual(sorted(openssl), openssl)
Exemplo n.º 9
0
 def test_hexrd(self):
     VERSIONS = ['0.3.0.dev', '0.3.3']
     vos = [VersionOrder(v) for v in VERSIONS]
     self.assertEqual(sorted(vos), vos)
Exemplo n.º 10
0
    def test_pep440(self):
        # this list must be in sorted order (slightly modified from the PEP 440 test suite
        # https://github.com/pypa/packaging/blob/master/tests/test_version.py)
        VERSIONS = [
            # Implicit epoch of 0
            "1.0a1",
            "1.0a2.dev456",
            "1.0a12.dev456",
            "1.0a12",
            "1.0b1.dev456",
            "1.0b2",
            "1.0b2.post345.dev456",
            "1.0b2.post345",
            "1.0c1.dev456",
            "1.0c1",
            "1.0c3",
            "1.0rc2",
            "1.0.dev456",
            "1.0",
            "1.0.post456.dev34",
            "1.0.post456",
            "1.1.dev1",
            "1.2.r32+123456",
            "1.2.rev33+123456",
            "1.2+abc",
            "1.2+abc123def",
            "1.2+abc123",
            "1.2+123abc",
            "1.2+123abc456",
            "1.2+1234.abc",
            "1.2+123456",

            # Explicit epoch of 1
            "1!1.0a1",
            "1!1.0a2.dev456",
            "1!1.0a12.dev456",
            "1!1.0a12",
            "1!1.0b1.dev456",
            "1!1.0b2",
            "1!1.0b2.post345.dev456",
            "1!1.0b2.post345",
            "1!1.0c1.dev456",
            "1!1.0c1",
            "1!1.0c3",
            "1!1.0rc2",
            "1!1.0.dev456",
            "1!1.0",
            "1!1.0.post456.dev34",
            "1!1.0.post456",
            "1!1.1.dev1",
            "1!1.2.r32+123456",
            "1!1.2.rev33+123456",
            "1!1.2+abc",
            "1!1.2+abc123def",
            "1!1.2+abc123",
            "1!1.2+123abc",
            "1!1.2+123abc456",
            "1!1.2+1234.abc",
            "1!1.2+123456",
        ]

        version = [VersionOrder(v) for v in VERSIONS]

        self.assertEqual(version, sorted(version))