Repository: conda/conda-build

Issue:
Conda build skeleton pypi does not select the newest version
conda-build 1.21.11 on osx

`conda skeleton pypi pg8000`
selects version 1.9.9, the newest version is 1.10.6

As far as I am aware conda skeleton automatically selects the newest version via version numbering.  Assuming this is the case (and there is not other logic at play), it seems to not be comparing versions correctly, i.e. 1.10.6 > 1.9.9

Manually specifying version 1.10.6 seems to work correctly
`conda skeleton pypi pg8000 --version 1.10.6`



Discussion:
What version of conda build? 

Updated the ticket

On Aug 15, 2016 3:30 PM, "Mike Sarahan" notifications@github.com wrote:

> What version of conda build?
> 
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> https://github.com/conda/conda-build/issues/1214#issuecomment-239903623,
> or mute the thread
> https://github.com/notifications/unsubscribe-auth/ADsARcOb8sxLPXvs8Sh9hxBPueTGa2y-ks5qgL5bgaJpZM4Jkru9
> .

The version sorting is really primitive: https://github.com/conda/conda-build/blob/master/conda_build/pypi.py#L309-L338

It just sorts things as strings, then picks the last one.  It works for a surprising number of things, but I think it falls over when you roll from x.9.x to x.10.x.

I'll leave this open, but I don't have time to work on it right now.  PR's welcome in the meantime.

Does this only affect 'conda skeleton' or other version checks as well?  Its pretty common to have a major/minor version which is >= 10.


Resolving patch:
diff --git a/conda_build/skeletons/pypi.py b/conda_build/skeletons/pypi.py
--- a/conda_build/skeletons/pypi.py
+++ b/conda_build/skeletons/pypi.py
@@ -9,6 +9,7 @@
 import os
 from os import makedirs, listdir, getcwd, chdir
 from os.path import join, isdir, exists, isfile, abspath
+from pkg_resources import parse_version
 import re
 from shutil import copy2
 import subprocess
@@ -356,7 +357,7 @@ def skeletonize(packages, output_dir=".", version=None, recursive=False,
         if is_url:
             d['version'] = 'UNKNOWN'
         else:
-            versions = sorted(client.package_releases(package, True))
+            versions = sorted(client.package_releases(package, True), key=parse_version)
             if version_compare:
                 version_compare(versions)
             if version:


Test patch:
diff --git a/tests/test_api_skeleton.py b/tests/test_api_skeleton.py
--- a/tests/test_api_skeleton.py
+++ b/tests/test_api_skeleton.py
@@ -1,5 +1,6 @@
 import os
 
+from pkg_resources import parse_version
 import pytest
 import yaml
 
@@ -74,12 +75,11 @@ def test_pypi_pin_numpy(testing_workdir, test_config):
 def test_pypi_version_sorting(testing_workdir, test_config):
     # The package used here must have a numpy dependence for pin-numpy to have
     # any effect.
-    api.skeletonize("conda_version_test", "pypi")
+    api.skeletonize("impyla", "pypi")
 
-    with open('conda_version_test/meta.yaml') as f:
+    with open('impyla/meta.yaml') as f:
         actual = yaml.load(f)
-        assert actual['package']['version'] != "0.1.0"
-        assert actual['package']['version'] >= "0.1.0-1"
+        assert parse_version(actual['package']['version']) >= parse_version("0.13.8")
 
 
 def test_list_skeletons():