Repository: conda/conda-build

Issue:
Underscore substitution breaks pin_run_as_build
<!--
Thanks for opening an issue! A few things to keep in mind:

- This issue tracker is for issues with or enhancements for conda-build.

For conda issues, you should open an issue at https://github.com/conda/conda/issues
For Anaconda issues, you should open an issue at https://github.com/ContinuumIO/anaconda-issues/issues
For an issue with a particular conda-forge package, you should open an issue on the 
corresponding feedstock: https://github.com/conda-forge
-->

### Actual Behavior

My builds are preaking with `conda-build` 3.9. This happens when a package name contains `-` and is included in `pin_run_as_build`.

### Steps to Reproduce

```
/t/rec $ conda build --version
conda-build 3.9.1
/t/rec $ cat conda_build_config.yaml 
pin_run_as_build:
    pkg-config: x.x
/t/rec $ cat meta.yaml 
package:
    name: echo
    version: '1'



requirements:
    build:
      - pkg-config
    run:
      - pkg-config

build:
    command: echo
```

Building this I get:

```python-traceback
$ conda build .
Adding in variants from internal_defaults
INFO:conda_build.variants:Adding in variants from internal_defaults
Adding in variants from /tmp/rec/conda_build_config.yaml
INFO:conda_build.variants:Adding in variants from /tmp/rec/conda_build_config.yaml
Attempting to finalize metadata for echo
INFO:conda_build.metadata:Attempting to finalize metadata for echo
Solving environment: ...working... done
Solving environment: ...working... done
Traceback (most recent call last):
  File "/home/zah/anaconda3/bin/conda-build", line 11, in <module>
    sys.exit(main())
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 420, in main
    execute(sys.argv[1:])
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 411, in execute
    verify=args.verify)
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/api.py", line 199, in build
    notest=notest, need_source_download=need_source_download, variants=variants)
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/build.py", line 2117, in build_tree
    notest=notest,
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/build.py", line 1169, in build
    output_metas = expand_outputs([(m, need_source_download, need_reparse_in_env)])
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/render.py", line 703, in expand_outputs
    for (output_dict, m) in _m.get_output_metadata_set(permit_unsatisfiable_variants=False):
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/metadata.py", line 1873, in get_output_metadata_set
    permit_unsatisfiable_variants=permit_unsatisfiable_variants)
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/metadata.py", line 683, in finalize_outputs_pass
    fm = finalize_metadata(om, permit_unsatisfiable_variants=permit_unsatisfiable_variants)
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/render.py", line 526, in finalize_metadata
    for dep in run_deps]
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/render.py", line 526, in <listcomp>
    for dep in run_deps]
  File "/home/zah/anaconda3/lib/python3.6/site-packages/conda_build/render.py", line 158, in get_pin_from_build
    pin_cfg = m.config.variant['pin_run_as_build'][dep_name.replace('-', '_')]
KeyError: 'pkg_config'
```

This worked fine in previous versions.




##### `Output of conda info`
<!-- Between the ticks below, paste the output of 'conda info' -->
```
    active environment : None
            shell level : 0
       user config file : /home/zah/.condarc
 populated config files : /home/zah/.condarc
          conda version : 4.5.1
    conda-build version : 3.9.1
         python version : 3.6.3.final.0
       base environment : /home/zah/anaconda3  (writable)
           channel URLs : https://zigzah.com/static/conda-pkgs-private/linux-64
                          https://zigzah.com/static/conda-pkgs-private/noarch
                          https://zigzah.com/static/conda-pkgs/linux-64
                          https://zigzah.com/static/conda-pkgs/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/linux-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/pro/linux-64
                          https://repo.anaconda.com/pkgs/pro/noarch
                          https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /home/zah/anaconda3/pkgs
                          /home/zah/.conda/pkgs
       envs directories : /home/zah/anaconda3/envs
                          /home/zah/.conda/envs
               platform : linux-64
             user-agent : conda/4.5.1 requests/2.18.4 CPython/3.6.3 Linux/4.15.0-15-generic linuxmint/18.3 glibc/2.23
                UID:GID : 1000:1000
             netrc file : /home/zah/.netrc
           offline mode : False

```




Discussion:
Thanks for reporting.  This was caused by https://github.com/conda/conda-build/pull/2830

I'll work to find a different way - probably split up initialization of the default values, since that was really why I needed to force the underscore.

Resolving patch:
diff --git a/conda_build/render.py b/conda_build/render.py
--- a/conda_build/render.py
+++ b/conda_build/render.py
@@ -155,7 +155,7 @@ def get_pin_from_build(m, dep, build_dep_versions):
     if (version and dep_name in m.config.variant.get('pin_run_as_build', {}) and
             not (dep_name == 'python' and (m.noarch or m.noarch_python)) and
             dep_name in build_dep_versions):
-        pin_cfg = m.config.variant['pin_run_as_build'][dep_name.replace('-', '_')]
+        pin_cfg = m.config.variant['pin_run_as_build'][dep_name]
         if isinstance(pin_cfg, str):
             # if pin arg is a single 'x.x', use the same value for min and max
             pin_cfg = dict(min_pin=pin_cfg, max_pin=pin_cfg)
diff --git a/conda_build/variants.py b/conda_build/variants.py
--- a/conda_build/variants.py
+++ b/conda_build/variants.py
@@ -27,13 +27,15 @@
     'lua': '5',
     'r_base': '3.4',
     'cpu_optimization_target': 'nocona',
-    'pin_run_as_build': OrderedDict(python=OrderedDict(min_pin='x.x', max_pin='x.x'),
-                                    r_base=OrderedDict(min_pin='x.x.x', max_pin='x.x.x')),
+    'pin_run_as_build': OrderedDict(python=OrderedDict(min_pin='x.x', max_pin='x.x')),
     'ignore_version': [],
     'ignore_build_only_deps': ['python'],
     'extend_keys': ['pin_run_as_build', 'ignore_version', 'ignore_build_only_deps'],
 }
 
+# set this outside the initialization because of the dash in the key
+DEFAULT_VARIANTS['pin_run_as_build']['r-base'] = OrderedDict(min_pin='x.x.x', max_pin='x.x.x')
+
 # map python version to default compiler on windows, to match upstream python
 #    This mapping only sets the "native" compiler, and can be overridden by specifying a compiler
 #    in the conda-build variant configuration


Test patch: