Repository: conda/conda-build

Issue:
conda-convert: TypeError: "delimiter" must be string, not unicode
_From @H0R5E on March 2, 2017 10:43_

Hi, I encountered a bug when issuing the command "conda convert -p win-64 path/to/win-32/package"

```
Traceback (most recent call last):
  File "C:\Anaconda\Scripts\conda-convert-script.py", line 5, in 
    <module>sys.exit(conda_build.cli.main_convert.main())
  File "C:\Anaconda\lib\site-packages\conda_build\cli\main_convert.py", line 129, in main
    return execute(sys.argv[1:])
  File "C:\Anaconda\lib\site-packages\conda_build\cli\main_convert.py", line 125, in execute
    api.convert(f, **args.__dict__)
  File "C:\Anaconda\lib\site-packages\conda_build\api.py", line 231, in convert
    dry_run=dry_run, dependencies=dependencies)
  File "C:\Anaconda\lib\site-packages\conda_build\convert.py", line 444, in conda_convert
    file_map = get_pure_py_file_map(t, platform)
  File "C:\Anaconda\lib\site-packages\conda_build\convert.py", line 271, in get_pure_py_file_map
    dialect=csv_dialect)
  File "C:\Anaconda\lib\csv.py", line 79, in __init__
    self.reader = reader(f, dialect, *args, **kwds)
TypeError: "delimiter" must be string, not unicode
```

conda info:

```
Current conda install:

               platform : win-32
          conda version : 4.3.13
       conda is private : False
      conda-env version : 4.3.13
    conda-build version : 2.1.5
         python version : 2.7.12.final.0
       requests version : 2.13.0
       root environment : C:\Anaconda  (writable)
    default environment : C:\Anaconda
       envs directories : C:\Anaconda\envs
                          C:\Users\Winston\AppData\Local\conda\conda\envs
                          C:\Users\Winston\.conda\envs
          package cache : C:\Anaconda\pkgs
                          C:\Users\Winston\AppData\Local\conda\conda\pkgs
           channel URLs : https://repo.continuum.io/pkgs/free/win-32
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/win-32
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/win-32
                          https://repo.continuum.io/pkgs/pro/noarch
                          https://repo.continuum.io/pkgs/msys2/win-32
                          https://repo.continuum.io/pkgs/msys2/noarch
                          https://conda.anaconda.org/conda-forge/win-32
                          https://conda.anaconda.org/conda-forge/noarch
                          https://conda.anaconda.org/dataonlygreater/win-32
                          https://conda.anaconda.org/dataonlygreater/noarch
            config file : C:\Users\Winston\.condarc
           offline mode : False
             user-agent : conda/4.3.13 requests/2.13.0 CPython/2.7.12 Windows/Vista Windows/6.0.6002
```

_Copied from original issue: conda/conda#4781_


Discussion:

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -56,7 +56,6 @@
 import conda_build.os_utils.external as external
 from conda_build.post import (post_process, post_build,
                               fix_permissions, get_build_metadata)
-from conda_build.metadata import build_string_from_metadata
 from conda_build.index import update_index
 from conda_build.create_test import (create_files, create_shell_files,
                                      create_py_files, create_pl_files)
@@ -881,15 +880,11 @@ def bundle_conda(output, metadata, config, env, **kw):
 
     files = post_process_files(metadata, initial_files)
 
-    tmp_metadata = copy.deepcopy(metadata)
-    tmp_metadata.meta['package']['name'] = output['name']
-    tmp_metadata.meta['requirements'] = {'run': output.get('requirements', [])}
-
     output_filename = ('-'.join([output['name'], metadata.version(),
-                                 build_string_from_metadata(tmp_metadata)]) + '.tar.bz2')
+                                 metadata.build_id()]) + '.tar.bz2')
     # first filter is so that info_files does not pick up ignored files
     files = filter_files(files, prefix=config.build_prefix)
-    create_info_files(tmp_metadata, files, config=config, prefix=config.build_prefix)
+    create_info_files(metadata, files, config=config, prefix=config.build_prefix)
     test_dest_path = os.path.join(config.info_dir, 'recipe', 'run_test.py')
     if output.get('test', {}).get('script'):
         utils.copy_into(os.path.join(metadata.path, output['test']['script']),
diff --git a/conda_build/convert.py b/conda_build/convert.py
--- a/conda_build/convert.py
+++ b/conda_build/convert.py
@@ -267,6 +267,11 @@ def get_pure_py_file_map(t, platform):
         fieldnames = ['prefix', 'type', 'path']
         csv_dialect = csv.Sniffer().sniff(has_prefix_files)
         csv_dialect.lineterminator = '\n'
+        for attr in ('delimiter', 'quotechar'):
+            if PY3 and hasattr(getattr(csv_dialect, attr), 'decode'):
+                setattr(csv_dialect, attr, getattr(csv_dialect, attr).decode())
+            elif not PY3 and hasattr(getattr(csv_dialect, attr), 'encode'):
+                setattr(csv_dialect, attr, getattr(csv_dialect, attr).encode())
         has_prefix_files = csv.DictReader(has_prefix_files.splitlines(), fieldnames=fieldnames,
                                           dialect=csv_dialect)
         # convenience: store list of dictionaries as map by path
diff --git a/conda_build/metadata.py b/conda_build/metadata.py
--- a/conda_build/metadata.py
+++ b/conda_build/metadata.py
@@ -379,7 +379,7 @@ def build_string_from_metadata(metadata):
                     ('perl', 'pl'), ('lua', 'lua'),
                     ('r', 'r'), ('r-base', 'r')):
         for ms in metadata.ms_depends():
-            if ms.name == name:
+            if ms.name.split(' ')[0] == name:
                 try:
                     v = ms.spec.split()[1]
                 except IndexError:
@@ -966,8 +966,9 @@ def get_output_metadata_set(self, files, permit_undefined_jinja=False):
                 for out in outputs:
                     if (self.name() == out.get('name', '') and not (out.get('files') or
                                                                     out.get('script'))):
-                        out['files'] = files
-                        requirements = requirements
+                        if files:
+                            out['files'] = files
+                        out['requirements'] = requirements
                     metadata = [self.get_output_metadata(output) for output in outputs]
         except SystemExit:
             if not permit_undefined_jinja:


Test patch: