Repository: conda/conda-build

Issue:
conda convert ignores dependencies
```
conda convert pakcage-xyz-linux-bla.tar.bz -d 'numpy >=1.8'
```
The dependency 'numpy >=1.8' will not be in the converted package.

How it should be?
The dependency should be included in the new package. Even better, the parsed meta.yaml with conditional depenencies should be used for the converted package.

Example:
meta.yaml
```
requirements:
    build:
        - python
    run:
        - python
        - pywin32 # [win]
```

when first built on linux and then converted to win64 using `conda convert --platform win-64 -o /opt/miniconda3/conda-bld/ /opt/miniconda3/conda-bld/linux-64/package_xy-0.1.31-py34_0.tar.bz2 -d 'pywin32'` the converted package will not have the dependency of pywin32.
The "quick hack" with -d failed as well as mentioned above.

Fix for convert:
See https://github.com/conda/conda-build/blob/master/conda_build/convert.py#L235
There should be something like:
```
# see https://github.com/conda/conda-build/blob/master/conda_build/convert.py#L412
        if dependencies:
            info['depends'].extend(dependencies)
```


Discussion:
@mandeep since you are digging into conda-convert already, please take a look at this.

Resolving patch:
diff --git a/conda_build/convert.py b/conda_build/convert.py
--- a/conda_build/convert.py
+++ b/conda_build/convert.py
@@ -208,7 +208,7 @@ def _update_paths(paths, mapping_dict):
 pyver_re = re.compile(r'python\s+(?:[<>=]*)(\d.\d)')
 
 
-def get_pure_py_file_map(t, platform):
+def get_pure_py_file_map(t, platform, dependencies):
     info = json.loads(t.extractfile('info/index.json').read().decode('utf-8'))
     try:
         paths = json.loads(t.extractfile('info/paths.json').read().decode('utf-8'))
@@ -234,6 +234,9 @@ def get_pure_py_file_map(t, platform):
     newinfo['arch'] = 'x86_64' if dest_arch == '64' else 'x86'
     newinfo['subdir'] = platform
 
+    if dependencies is not None:
+        newinfo['depends'] = dependencies
+
     pythons = list(filter(None, [pyver_re.match(p) for p in info['depends']]))
     pythons = list(set(p.group(1) for p in pythons))
 
@@ -410,8 +413,23 @@ def conda_convert(file_path, output_dir=".", show_imports=False, platforms=None,
         source_type = 'unix' if info['platform'] in {'osx', 'linux'} else 'win'
 
         if dependencies:
+            # split dependencies away from their version numbers since we need the names
+            # in order to evaluate duplication
+            dependency_names = set(dependency.split()[0] for dependency in dependencies)
+            index_dependency_names = set(index.split()[0] for index in info['depends'])
+
+            repeated_packages = index_dependency_names.intersection(dependency_names)
+
+            if len(repeated_packages) > 0:
+                for index_dependency in info['depends']:
+                    for dependency in repeated_packages:
+                        if index_dependency.startswith(dependency):
+                            info['depends'].remove(index_dependency)
+
             info['depends'].extend(dependencies)
 
+            dependencies = info['depends']
+
         nonpy_unix = False
         nonpy_win = False
 
@@ -453,7 +471,7 @@ def conda_convert(file_path, output_dir=".", show_imports=False, platforms=None,
                       (file_path, info['platform'], platform), file=sys.stderr)
                 continue
 
-            file_map = get_pure_py_file_map(t, platform)
+            file_map = get_pure_py_file_map(t, platform, dependencies)
 
             if dry_run:
                 if not quiet:


Test patch:
diff --git a/tests/test_api_convert.py b/tests/test_api_convert.py
--- a/tests/test_api_convert.py
+++ b/tests/test_api_convert.py
@@ -98,3 +98,64 @@ def test_convert_from_unix_to_win_creates_entry_points(testing_config):
         assert 'Scripts/test-script-setup-script.py' in has_prefix_files
         assert 'Scripts/test-script-manual-script.py' in has_prefix_files
         assert 'Scripts/test-script-manual-postfix-script.py' in has_prefix_files
+
+
+@pytest.mark.serial
+@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
+@pytest.mark.parametrize('package', [('anaconda-4.4.0', 'version.txt')])
+def test_convert_dependencies(testing_workdir, base_platform, package):
+    package_name, example_file = package
+    f = 'http://repo.continuum.io/pkgs/free/{}-64/{}-np112py36_0.tar.bz2'.format(base_platform,
+                                                                            package_name)
+    fn = "{}-np112py36_0.tar.bz2".format(package_name)
+    download(f, fn)
+
+    dependencies = ['numpy 1.7.1 py36_0', 'cryptography 1.7.0 py36_0']
+    expected_paths_json = package_has_file(fn, 'info/paths.json')
+    api.convert(fn, platforms='all', dependencies=dependencies, quiet=False, verbose=False)
+    for platform in ['osx-64', 'win-64', 'win-32', 'linux-64', 'linux-32']:
+        python_folder = 'lib/python3.6' if not platform.startswith('win') else 'Lib'
+        package = os.path.join(platform, fn)
+        assert package_has_file(package,
+                                '{}/{}'.format(python_folder, example_file))
+
+        with tarfile.open(package) as t:
+            info = json.loads(t.extractfile('info/index.json').read().decode('utf-8'))
+
+            assert 'numpy 1.7.1 py36_0' in info['depends']
+            assert 'numpy 1.12.1 py36_0' not in info['depends']
+            assert 'cryptography 1.7.0 py36_0' in info['depends']
+            assert 'cryptography 1.8.1 py36_0' not in info['depends']
+
+        if expected_paths_json:
+            assert package_has_file(package, 'info/paths.json')
+            assert_package_paths_matches_files(package)
+
+
+@pytest.mark.serial
+@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
+@pytest.mark.parametrize('package', [('anaconda-4.4.0', 'version.txt')])
+def test_convert_no_dependencies(testing_workdir, base_platform, package):
+    package_name, example_file = package
+    f = 'http://repo.continuum.io/pkgs/free/{}-64/{}-np112py36_0.tar.bz2'.format(base_platform,
+                                                                            package_name)
+    fn = "{}-np112py36_0.tar.bz2".format(package_name)
+    download(f, fn)
+
+    expected_paths_json = package_has_file(fn, 'info/paths.json')
+    api.convert(fn, platforms='all', dependencies=None, quiet=False, verbose=False)
+    for platform in ['osx-64', 'win-64', 'win-32', 'linux-64', 'linux-32']:
+        python_folder = 'lib/python3.6' if not platform.startswith('win') else 'Lib'
+        package = os.path.join(platform, fn)
+        assert package_has_file(package,
+                                '{}/{}'.format(python_folder, example_file))
+
+        with tarfile.open(package) as t:
+            info = json.loads(t.extractfile('info/index.json').read().decode('utf-8'))
+
+            assert 'numpy 1.12.1 py36_0' in info['depends']
+            assert 'cryptography 1.8.1 py36_0' in info['depends']
+
+        if expected_paths_json:
+            assert package_has_file(package, 'info/paths.json')
+            assert_package_paths_matches_files(package)