Repository: conda/conda-build

Issue:
wheel build ignores value of CONDA_PY
If I build a package that includes a wheel output then the resulting wheel is for the version of python in the base installation of python, not the version specified in `$CONDA_PY`. 



Discussion:
Good catch.  I'm going to hope to fix this for the 3.0 release.

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -778,9 +778,8 @@ def order(f):
 
 
 def bundle_wheel(output, metadata, env):
-    import pip
     with TemporaryDirectory() as tmpdir, utils.tmp_chdir(metadata.config.work_dir):
-        pip.main(['wheel', '--wheel-dir', tmpdir, '--no-deps', '.'])
+        utils.check_call_env(['pip', 'wheel', '--wheel-dir', tmpdir, '--no-deps', '.'], env=env)
         wheel_files = glob(os.path.join(tmpdir, "*.whl"))
         if not wheel_files:
             raise RuntimeError("Wheel creation failed.  Please see output above to debug.")
@@ -1048,7 +1047,8 @@ def build(m, post=None, need_source_download=True, need_reparse_in_env=False, bu
                     output_d['files'] = (utils.prefix_files(prefix=m.config.host_prefix) -
                                          initial_files)
 
-                assert m.final, "output metadata for {} is not finalized".format(m.dist())
+                assert output_d.get('type') != 'conda' or m.final, (
+                    "output metadata for {} is not finalized".format(m.dist()))
                 pkg_path = bldpkg_path(m)
                 if pkg_path not in built_packages and pkg_path not in new_pkgs:
                     if post is None:
diff --git a/conda_build/metadata.py b/conda_build/metadata.py
--- a/conda_build/metadata.py
+++ b/conda_build/metadata.py
@@ -543,7 +543,7 @@ def toposort(output_metadata_map, phase):
     # not sure that this is working...  not everything has 'name', and not sure how this pans out
     #    may end up excluding packages without the 'name' field
     keys.extend([k for pkgname in endorder for k in output_metadata_map.keys()
-                 if 'name' in k and k['name'] == pkgname])
+                 if ('name' in k and k['name'] == pkgname) or 'name' not in k])
     result = OrderedDict()
     for key in keys:
         result[key] = output_metadata_map[key]
@@ -1533,12 +1533,23 @@ def get_output_metadata_set(self, permit_undefined_jinja=False,
 
         # format here is {output_dict: metadata_object}
         render_order = toposort(out_metadata_map, phase='build')
+        check_circular_dependencies(render_order)
 
         conda_packages = OrderedDict()
         non_conda_packages = []
         for output_d, m in render_order.items():
             if not output_d.get('type') or output_d['type'] == 'conda':
                 conda_packages[m.name(), HashableDict(m.config.variant)] = (output_d, m)
+            elif output_d.get('type') == 'wheel':
+                if (not output_d.get('requirements', {}).get('build') or
+                        not any('wheel' in req for req in output_d['requirements']['build'])):
+                    build_reqs = output_d.get('requirements', {}).get('build', [])
+                    build_reqs.extend(['wheel', 'python {}'.format(m.config.variant['python'])])
+                    output_d['requirements'] = output_d.get('requirements', {})
+                    output_d['requirements']['build'] = build_reqs
+                    m.meta['requirements'] = m.meta.get('requirements', {})
+                    m.meta['requirements']['build'] = build_reqs
+                non_conda_packages.append((output_d, m))
             else:
                 # for wheels and other non-conda packages, just append them at the end.
                 #    no deduplication with hashes currently.
@@ -1547,8 +1558,6 @@ def get_output_metadata_set(self, permit_undefined_jinja=False,
                 #    obtain an exact match elsewhere
                 non_conda_packages.append((output_d, m))
 
-        check_circular_dependencies(render_order)
-
         # early stages don't need to do the finalization.  Skip it until the later stages
         #     when we need it.
         if not permit_undefined_jinja:


Test patch: