Repository: conda/conda-build

Issue:
conda skeleton needs to gracefully handle pypi versions that lack tarballs
~:~$ conda skeleton pypi pyavl
Warning, the following versions were found for pyavl
1.12_1
1.12
Using 1.12
Use --version to specify a different version.
Using url http://sourceforge.net/projects/pyavl/ (0 B) for pyavl.
Downloading pyavl
Unpacking pyavl...
An unexpected error has occurred, please consider sending the
following traceback to the conda GitHub issue tracker at:

```
https://github.com/conda/conda-build/issues
```

Include the output of the command 'conda info' in your report.

Traceback (most recent call last):
  File "/home/novalis/miniconda2/bin/conda-skeleton", line 5, in <module>
    sys.exit(main())
  File "/home/novalis/miniconda2/lib/python2.7/site-packages/conda_build/main_skeleton.py", line 319, in main
    args_func(args, p)
  File "/home/novalis/miniconda2/lib/python2.7/site-packages/conda_build/main_build.py", line 401, in args_func
    args.func(args, p)
  File "/home/novalis/miniconda2/lib/python2.7/site-packages/conda_build/main_skeleton.py", line 334, in execute
    pypi.main(args, parser)
  File "/home/novalis/miniconda2/lib/python2.7/site-packages/conda_build/pypi.py", line 352, in main
    get_package_metadata(args, package, d, data)
  File "/home/novalis/miniconda2/lib/python2.7/site-packages/conda_build/pypi.py", line 503, in get_package_metadata
    setup_options=args.setup_options)
  File "/home/novalis/miniconda2/lib/python2.7/site-packages/conda_build/pypi.py", line 757, in get_pkginfo
    unpack(join(SRC_CACHE, filename), tempdir)
  File "/home/novalis/miniconda2/lib/python2.7/site-packages/conda_build/pypi.py", line 691, in unpack
    raise Exception("not a valid source")
Exception: not a valid source
~:~$ conda info
Warning: somethings is wrong with binstar_client (No module named binstar_client.utils)Current conda install:

```
         platform : linux-64
    conda version : 4.1.9
conda-env version : 2.5.2
```

  conda-build version : 1.21.6
       python version : 2.7.12.final.0
     requests version : 2.9.1
     root environment : /home/novalis/miniconda2  (writable)
  default environment : /home/novalis/miniconda2
     envs directories : /home/novalis/miniconda2/envs
        package cache : /home/novalis/miniconda2/pkgs
         channel URLs : https://repo.continuum.io/pkgs/free/linux-64/
                        https://repo.continuum.io/pkgs/free/noarch/
                        https://repo.continuum.io/pkgs/pro/linux-64/
                        https://repo.continuum.io/pkgs/pro/noarch/
          config file : None
         offline mode : False
##     is foreign system : False
1. 1.12_1 is in fact later than 1.12
2. Conda should detect that the tarball is missing from 1.12 and provide a reasonable error message.



Discussion:

Resolving patch:
diff --git a/conda_build/pypi.py b/conda_build/pypi.py
--- a/conda_build/pypi.py
+++ b/conda_build/pypi.py
@@ -305,7 +305,7 @@ def main(args, parser):
         if is_url:
             d['version'] = 'UNKNOWN'
         else:
-            versions = client.package_releases(package, True)
+            versions = sorted(client.package_releases(package, True))
             if args.version_compare:
                 version_compare(args, package, versions)
             if args.version:


Test patch:
diff --git a/tests/test-skeleton/test_skeleton.py b/tests/test-skeleton/test_skeleton.py
--- a/tests/test-skeleton/test_skeleton.py
+++ b/tests/test-skeleton/test_skeleton.py
@@ -68,7 +68,8 @@ def test_skeleton_pin_numpy(tmpdir):
     # The package used here must have a numpy dependence for pin-numpy to have
     # any effect.
     package_name = 'msumastro'
-    cmd = "conda skeleton pypi --output-dir {} --version=0.9.0 --pin-numpy {}".format(tmpdir, package_name)
+    cmd = "conda skeleton pypi --output-dir {} --version=0.9.0 --pin-numpy {}".format(tmpdir,
+                                                                                      package_name)
     subprocess.check_call(cmd.split())
 
     with open('{}/{}/meta.yaml'.format(tmpdir, package_name)) as f:
@@ -76,3 +77,16 @@ def test_skeleton_pin_numpy(tmpdir):
 
     assert 'numpy x.x' in actual['requirements']['run']
     assert 'numpy x.x' in actual['requirements']['build']
+
+
+def test_skeleton_pypi_version_sorting(tmpdir):
+    # The package used here must have a numpy dependence for pin-numpy to have
+    # any effect.
+    package_name = 'conda_version_test'
+    cmd = "conda skeleton pypi --output-dir {} {}".format(tmpdir, package_name)
+    subprocess.check_call(cmd.split())
+
+    with open('{}/{}/meta.yaml'.format(tmpdir, package_name)) as f:
+        actual = yaml.load(f)
+        assert actual['package']['version'] != "0.1.0"
+        assert actual['package']['version'] >= "0.1.0-1"