Repository: conda/conda-build

Issue:
Regression: --version not respected in conda-build-2.0.4 skeleton
The --version flag does not seem to be respected by conda skeleton.
version is conda-build-2.0.4.

```
(bjorn3) bjorn@bjorn-ThinkPad-T450s:~/Desktop$ conda skeleton pypi PrettyTable --version 0.7.2
Warning, the following versions were found for PrettyTable
0.1
0.2
0.2.1
0.3
0.4
0.5
0.6
0.6.1
0.7.1
0.7.2
7
Using 7
Use --version to specify a different version.
More than one source version is available for PrettyTable:
Using the one with the least source size
use --manual-url to override this behavior
Using url https://pypi.python.org/packages/c7/21/8911c1b4aab57b891a54bcb6b1fab2ef59e80a78f7f699dd3d162ddda87f/prettytable-0.7.tar.bz2 (21 KB) for PrettyTable.
Downloading PrettyTable
Using cached download
Unpacking PrettyTable...
done
working in /tmp/tmpxippxdfoconda_skeleton_prettytable-0.7.tar.bz2
```

will try to manually pin the url as suggested meanwhile



Discussion:
Manually specifying url seems to work...

```
(bjorn3) bjorn@bjorn-ThinkPad-T450s:~/Desktop$ conda skeleton pypi --manual-url https://pypi.python.org/packages/ef/30/4b0746848746ed5941f052479e7c23d2b56d174b82f4fd34a25e389831f5/prettytable-0.7.2.tar.bz2
Using url https://pypi.python.org/packages/ef/30/4b0746848746ed5941f052479e7c23d2b56d174b82f4fd34a25e389831f5/prettytable-0.7.2.tar.bz2
Downloading https://pypi.python.org/packages/ef/30/4b0746848746ed5941f052479e7c23d2b56d174b82f4fd34a25e389831f5/prettytable-0.7.2.tar.bz2
Unpacking https://pypi.python.org/packages/ef/30/4b0746848746ed5941f052479e7c23d2b56d174b82f4fd34a25e389831f5/prettytable-0.7.2.tar.bz2...
done
working in /tmp/tmpkb7mozbgconda_skeleton_prettytable-0.7.2.tar.bz2

The following NEW packages will be INSTALLED:

    openssl:    1.0.2j-0      defaults
    pip:        8.1.2-py35_0  defaults
    python:     3.5.2-0       defaults
    pyyaml:     3.12-py35_0   defaults
    readline:   6.2-2         defaults
    setuptools: 27.2.0-py35_0 defaults
    sqlite:     3.13.0-0      defaults
    tk:         8.5.18-0      defaults
    wheel:      0.29.0-py35_0 defaults
    xz:         5.2.2-0       defaults
    yaml:       0.1.6-0       defaults
    zlib:       1.2.8-3       defaults

Applying patch: '/tmp/tmpkb7mozbgconda_skeleton_prettytable-0.7.2.tar.bz2/pypi-distutils.patch'
patching file core.py
Hunk #1 succeeded at 167 with fuzz 2 (offset 1 line).
Writing recipe for https://pypi.python.org/packages/ef/30/4b0746848746ed5941f052479e7c23d2b56d174b82f4fd34a25e389831f5/prettytable-0.7.2.tar.bz2
(bjorn3) bjorn@bjorn-ThinkPad-T450s:~/Desktop$ 

```

Thanks for the report, and the workaround.  I'll fix this for the next release.


Resolving patch:
diff --git a/conda_build/api.py b/conda_build/api.py
--- a/conda_build/api.py
+++ b/conda_build/api.py
@@ -165,6 +165,13 @@ def skeletonize(packages, repo, output_dir=".", version=None, recursive=False,
     """Generate a conda recipe from an external repo.  Translates metadata from external
     sources into expected conda recipe format."""
 
+    if version:
+        kwargs.update({'version': version})
+    if recursive:
+        kwargs.update({'version': version})
+    if output_dir != ".":
+        kwargs.update({'output_dir': output_dir})
+
     # here we're dumping all extra kwargs as attributes on the config object.  We'll extract
     #    only relevant ones below
     config = get_or_merge_config(config, **kwargs)


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
@@ -93,3 +93,11 @@ def test_list_skeletons():
 def test_pypi_with_entry_points(testing_workdir):
     api.skeletonize('planemo', repo='pypi', python_version="2.7")
     assert os.path.isdir('planemo')
+
+
+def test_pypi_with_version_arg(testing_workdir):
+    # regression test for https://github.com/conda/conda-build/issues/1442
+    api.skeletonize('PrettyTable', 'pypi', version='0.7.2')
+    with open('prettytable/meta.yaml') as f:
+        actual = yaml.load(f)
+        assert parse_version(actual['package']['version']) == parse_version("0.7.2")