Repository: conda/conda-build

Issue:
Output environment not activated on Windows
Tried to build conda and wheel packages in PR ( https://github.com/conda-forge/numcodecs-feedstock/pull/17 ). However it seems that on Windows, despite creating an environment with the needed dependencies, `setuptools` still tries to download `setuptools_scm`. Looking at the traceback that follows, it looks like the output packaging step is being run in `root` instead of the environment with `setuptools_scm`, which would explain it. Guessing activation of the environment used for the output packaging step does not occur on Windows? Log linked below. This problem does not occur on Unix.

ref: https://ci.appveyor.com/project/conda-forge/numcodecs-feedstock/build/1.0.34/job/9d4u18qv7k6rjkcx


Discussion:
I need to write the docs for this.  There are a few conditions that lead to the packaging env being activated:

https://github.com/conda/conda-build/blob/master/conda_build/metadata.py#L2022
https://github.com/conda/conda-build/blob/master/conda_build/build.py#L813

To summarize, output envs are not activated by default.  This is for speed reasons - activation is slow.  Using compilers in the build or host requirements will activate them because our compiler packages all depend on activation.  Otherwise, you need to set the

```
  - name: myoutput
    build:
      activate_in_script: True
```

for any output that you want to be activated.
Thanks for the advice Mike. Gave that a try, but it still seems to not be activating the environment. That said, I'm new at this and could be making a mistake somewhere. Same PR, but a newer commit at the end. One of the logs is linked below. Any thoughts you might have would be appreciated.

ref: https://ci.appveyor.com/project/conda-forge/numcodecs-feedstock/build/1.0.36/job/r9ajndf1bbidowab
I think the problem is that env activation is done in a way that doesn't affect wheels right now (only works for packaging conda packages).  That should be pretty easy to fix.

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -1001,8 +1001,31 @@ def order(f):
 
 
 def bundle_wheel(output, metadata, env, stats):
+    ext = ".bat" if utils.on_win else ".sh"
     with TemporaryDirectory() as tmpdir, utils.tmp_chdir(metadata.config.work_dir):
-        utils.check_call_env(['pip', 'wheel', '--wheel-dir', tmpdir, '--no-deps', '.'], env=env)
+        dest_file = os.path.join(metadata.config.work_dir, 'wheel_output' + ext)
+        with open(dest_file, 'w') as f:
+            f.write('\n')
+            f.write('pip wheel --wheel-dir {} --no-deps .'.format(tmpdir))
+            f.write('\n')
+        if metadata.activate_build_script:
+            _write_activation_text(dest_file, metadata)
+
+        # run the appropriate script
+        env = environ.get_dict(config=metadata.config, m=metadata).copy()
+        env['TOP_PKG_NAME'] = env['PKG_NAME']
+        env['TOP_PKG_VERSION'] = env['PKG_VERSION']
+        env['PKG_VERSION'] = metadata.version()
+        env['PKG_NAME'] = metadata.get_value('package/name')
+        interpreter_and_args = guess_interpreter(dest_file)
+
+        bundle_stats = {}
+        utils.check_call_env(interpreter_and_args + [dest_file],
+                             cwd=metadata.config.work_dir, env=env, stats=bundle_stats)
+        log_stats(bundle_stats, "bundling wheel {}".format(metadata.name()))
+        if stats is not None:
+            stats[stats_key(metadata, 'bundle_wheel_{}'.format(metadata.name()))] = bundle_stats
+
         wheel_files = glob(os.path.join(tmpdir, "*.whl"))
         if not wheel_files:
             raise RuntimeError("Wheel creation failed.  Please see output above to debug.")


Test patch: