Repository: conda/conda-build

Issue:
TypeError: when rendering recipe with 3.13.0
<!--
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

Upgraded to conda-build 3.13.0 and hit a TypeError that I didn't hit before with 3.12.1:
```
% conda build -s gtest
Adding in variants from internal_defaults                                              
INFO:conda_build.variants:Adding in variants from internal_defaults                    
Adding in variants from /sarc/spa/users/tsnyder/conda_build_config.yaml                
INFO:conda_build.variants:Adding in variants from /sarc/spa/users/tsnyder/conda_build_config.yaml
Attempting to finalize metadata for gtest                                                        
INFO:conda_build.metadata:Attempting to finalize metadata for gtest                              
Solving environment: ...working... done                                                          
Traceback (most recent call last):                                                               
  File "/sarc/spa/users/tsnyder/miniconda3/bin/conda-build", line 11, in <module>                
    sys.exit(main())                                                                             
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 424, in main
    execute(sys.argv[1:])                                                                                               
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 411, in execute
    outputs = [action(recipe, config) for recipe in args.recipe]                                                           
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 411, in <listcomp>
    outputs = [action(recipe, config) for recipe in args.recipe]                                                              
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 328, in source_action
    metadata = api.render(recipe, config=config)[0][0]                                                                           
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/api.py", line 51, in render                   
    bypass_env_check=bypass_env_check):                                                                                          
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/metadata.py", line 1974, in get_output_metadata_set
    bypass_env_check=bypass_env_check)                                                                                                
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/metadata.py", line 701, in finalize_outputs_pass   
    permit_unsatisfiable_variants=permit_unsatisfiable_variants)                                                                      
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/render.py", line 460, in finalize_metadata         
    exclude_pattern)                                                                                                                  
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/render.py", line 333, in add_upstream_pins         
    permit_unsatisfiable_variants, exclude_pattern)                                                                                   
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/render.py", line 324, in _read_upstream_pin_files  
    extra_run_specs = get_upstream_pins(m, actions, env)                                                                              
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/render.py", line 312, in get_upstream_pins         
    specs = _read_specs_from_package(loc, dist)                                                                                       
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda/exports.py", line 181, in __call__                       
    value = self.func(*args, **kw)                                                                                                    
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/render.py", line 227, in _read_specs_from_package  
    specs = {'weak': [spec.rstrip() for spec in legacy_specs.splitlines()                                                             
  File "/sarc/spa/users/tsnyder/miniconda3/lib/python3.5/site-packages/conda_build/render.py", line 228, in <listcomp>                
    if not spec.startswith(pkg_dist.rsplit('-', 2)[0])]}                                                                              
TypeError: startswith first arg must be bytes or a tuple of bytes, not str        
```

<!-- What actually happens? -->

### Expected Behavior

Should be able to render my recipe without the TypeError.  Reverting to 3.12.1, I'm able to render.

<!-- What do you think should happen? -->

### Steps to Reproduce

<!-- Steps to reproduce issue. -->

#### contents of gtest/meta.yaml
```
{% set version="1.8.1" %}

package:
  name: gtest
  version: {{ version }}

source:
  git_rev: release-{{ version }}
  git_url: https://github.com/google/googletest.git

build:
  # If this is a new build for the same version, increment the build
  # number. If you do not include this key, it defaults to 0.
  # number: 1

requirements:
  build:
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - cmake
  #host:
  #  - libunwind
  #run:
  #  - libunwind

about:
  home: https://github.com/google/googletest
  summary: "Google's C++ Test Framework"
  license: BSD
```


##### `Output of conda info`
<!-- Between the ticks below, paste the output of 'conda info' -->
```
% conda info

     active environment : base
    active env location : /sarc/spa/users/tsnyder/miniconda3
            shell level : 1                                 
       user config file : /sarc/spa/users/tsnyder/.condarc  
 populated config files : /sarc/spa/users/tsnyder/miniconda3/.condarc
                          /sarc/spa/users/tsnyder/.condarc           
          conda version : 4.5.11                                     
    conda-build version : 3.13.0                                     
         python version : 3.5.4.final.0                              
       base environment : /sarc/spa/users/tsnyder/miniconda3  (writable)
           channel URLs : http://anaconda.spa.sarc.samsung.com/conda/spa/linux-64
                          http://anaconda.spa.sarc.samsung.com/conda/spa/noarch  
                          http://anaconda.spa.sarc.samsung.com/conda/SPA/linux-64
                          http://anaconda.spa.sarc.samsung.com/conda/SPA/noarch  
                          http://anaconda.spa.sarc.samsung.com/conda/anaconda/linux-64
                          http://anaconda.spa.sarc.samsung.com/conda/anaconda/noarch  
                          http://anaconda.spa.sarc.samsung.com/conda/r-channel/linux-64
                          http://anaconda.spa.sarc.samsung.com/conda/r-channel/noarch  
                          https://conda.anaconda.org/t/<TOKEN>/anaconda-nb-extensions/linux-64
                          https://conda.anaconda.org/t/<TOKEN>/anaconda-nb-extensions/noarch  
                          https://conda.anaconda.org/t/<TOKEN>/anaconda-server/linux-64       
                          https://conda.anaconda.org/t/<TOKEN>/anaconda-server/noarch         
                          https://conda.anaconda.org/t/<TOKEN>/binstar/linux-64               
                          https://conda.anaconda.org/t/<TOKEN>/binstar/noarch                 
          package cache : /sarc/spa/users/tsnyder/miniconda3/pkgs                             
                          /sarc/spa/users/tsnyder/.conda/pkgs                                 
       envs directories : /sarc/spa/users/tsnyder/miniconda3/envs                             
                          /sarc/spa/users/tsnyder/.conda/envs                                 
               platform : linux-64                                                            
             user-agent : conda/4.5.11 requests/2.12.4 CPython/3.5.4 Linux/2.6.32-642.1.1.el6.x86_64.debug rhel/6.7 glibc/2.12
                UID:GID : 12025:801                                                                                           
             netrc file : None                                                                                                
           offline mode : False                                                                                               
```



Discussion:
Sorry Tim, I could not reproduce this.  It seems like it's probably some subtle type conversion error, though I'm surprised to see that with python 3.5.  If you have any more info on this, please let me know.

Resolving patch:
diff --git a/conda_build/index.py b/conda_build/index.py
--- a/conda_build/index.py
+++ b/conda_build/index.py
@@ -588,6 +588,8 @@ def _augment_repodata(subdirs, patched_repodata, patch_instructions):
 
 def _cache_post_install_details(loaded_json_text, all_paths, post_install_cache_path):
     post_install_details_json = {'binary_prefix': False, 'text_prefix': False}
+    if hasattr(loaded_json_text, "decode"):
+        loaded_json_text = loaded_json_text.decode("utf-8")
     # get embedded prefix data from paths.json
     for f in json.loads(loaded_json_text).get('paths', []):
         if f.get('prefix_placeholder'):
diff --git a/conda_build/render.py b/conda_build/render.py
--- a/conda_build/render.py
+++ b/conda_build/render.py
@@ -208,7 +208,7 @@ def find_pkg_dir_or_file_in_pkgs_dirs(pkg_dist, m, files_only=False):
 @memoized
 def _read_specs_from_package(pkg_loc, pkg_dist):
     specs = {}
-    if os.path.isdir(pkg_loc):
+    if pkg_loc and os.path.isdir(pkg_loc):
         downstream_file = os.path.join(pkg_loc, 'info/run_exports')
         if os.path.isfile(downstream_file):
             with open(downstream_file) as f:
@@ -232,8 +232,15 @@ def _read_specs_from_package(pkg_loc, pkg_dist):
             legacy_specs = utils.package_has_file(pkg_loc, 'info/run_exports')
             # exclude packages pinning themselves (makes no sense)
             if legacy_specs:
-                specs = {'weak': [spec.rstrip() for spec in legacy_specs.splitlines()
-                                if not spec.startswith(pkg_dist.rsplit('-', 2)[0])]}
+                weak_specs = set()
+                if hasattr(pkg_dist, "decode"):
+                    pkg_dist = pkg_dist.decode("utf-8")
+                for spec in legacy_specs.splitlines():
+                    if hasattr(spec, "decode"):
+                        spec = spec.decode("utf-8")
+                    if not spec.startswith(pkg_dist.rsplit('-', 2)[0]):
+                        weak_specs.add(spec.rstrip())
+                specs = {'weak': sorted(list(weak_specs))}
     return specs
 
 


Test patch: