Repository: conda/conda-build

Issue:
"TypeError: cannot use a string pattern on a bytes-like object" in get_repository_info ".svn" dir, Py3
When the input directory contains a ".svn" dir, with Python 3,  conda-build-3.16.0 and later, fails:

conda-build --output-folder $outputdir $inputdir

The Python stack and the output are:

```
Recent conda-build version with ".svn" directories trigger this error:
Fixing permissions
Traceback (most recent call last):
  File "CondaInstall/bin/conda-build", line 11, in <module>
    sys.exit(main())
  File "CondaInstall/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 439, in main
    execute(sys.argv[1:])
  File "CondaInstall/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 430, in execute
    verify=args.verify, variants=args.variants)
  File "CondaInstall/lib/python3.6/site-packages/conda_build/api.py", line 201, in build
    notest=notest, need_source_download=need_source_download, variants=variants)
  File "CondaInstall/lib/python3.6/site-packages/conda_build/build.py", line 2234, in build_tree
    notest=notest,
  File "CondaInstall/lib/python3.6/site-packages/conda_build/build.py", line 1625, in build
    built_package = bundlers[output_d.get('type', 'conda')](output_d, m, env, stats)
  File "CondaInstall/lib/python3.6/site-packages/conda_build/build.py", line 969, in bundle_conda
    output['checksums'] = create_info_files(metadata, files, prefix=metadata.config.host_prefix)
  File "CondaInstall/lib/python3.6/site-packages/conda_build/build.py", line 662, in create_info_files
    copy_recipe(m)
  File "CondaInstall/lib/python3.6/site-packages/conda_build/build.py", line 327, in copy_recipe
    f.write("# " + source.get_repository_info(m.path) + "\n")
  File "CondaInstall/lib/python3.6/site-packages/conda_build/source.py", line 464, in get_repository_info
    server = re.search("Repository Root: (.*)$", info, flags=re.M).group(1)
  File "CondaInstall/lib/python3.6/re.py", line 182, in search
    return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object
```

The reason is that:
* subprocess.check_output() returns a byte string
* ... which is returned by _func_defaulting_env_to_os_environ() then check_output_env() in utils.py 
* ... the result is then passed to re.search in get_repository_info() which expects a string (File source.py, line 464).

The fix is to convert the byte string "info" into a unicode string, if Python 3.

It happens only with ".svn" directories and Python 3.


Discussion:
Since you have identified the problem so well, do you mind submitting a PR?  You should get credit for your work.

Resolving patch:
diff --git a/conda_build/source.py b/conda_build/source.py
--- a/conda_build/source.py
+++ b/conda_build/source.py
@@ -461,6 +461,7 @@ def get_repository_info(recipe_path):
             return "Origin {}, commit {}".format(origin, rev)
         elif isdir(join(recipe_path, ".svn")):
             info = check_output_env(["svn", "info"], cwd=recipe_path)
+            info = info.decode("utf-8") # Py3 returns a byte string, but re needs unicode or str.
             server = re.search("Repository Root: (.*)$", info, flags=re.M).group(1)
             revision = re.search("Revision: (.*)$", info, flags=re.M).group(1)
             return "{}, Revision {}".format(server, revision)


Test patch: