Repository: conda/conda-build

Issue:
conda build crash
Using conda-build 2.1.3:

We're using `requirements.txt` and `__conda_buildnum__.txt`/`__conda_version__.txt`, in case that's relevant (I suspect it's the former causing problems).

```
Traceback (most recent call last):
  File "/home/ubuntu/miniconda2/bin/conda-build", line 6, in <module>
    sys.exit(conda_build.cli.main_build.main())
  File "/home/ubuntu/miniconda2/lib/python2.7/site-packages/conda_build/cli/main_build.py", line 322, in main
    execute(sys.argv[1:])
  File "/home/ubuntu/miniconda2/lib/python2.7/site-packages/conda_build/cli/main_build.py", line 313, in execute
    noverify=args.no_verify)
  File "/home/ubuntu/miniconda2/lib/python2.7/site-packages/conda_build/api.py", line 97, in build
    need_source_download=need_source_download, config=config)
  File "/home/ubuntu/miniconda2/lib/python2.7/site-packages/conda_build/build.py", line 1480, in build_tree
    config=config)
  File "/home/ubuntu/miniconda2/lib/python2.7/site-packages/conda_build/build.py", line 1132, in build
    built_package = bundlers[output.get('type', 'conda')](output, m, config, env)
  File "/home/ubuntu/miniconda2/lib/python2.7/site-packages/conda_build/build.py", line 825, in bundle_conda
    info_files = create_info_files(tmp_metadata, files, config=config, prefix=config.build_prefix)
  File "/home/ubuntu/miniconda2/lib/python2.7/site-packages/conda_build/build.py", line 489, in create_info_files
    write_info_json(m, config)  # actually index.json
  File "/home/ubuntu/miniconda2/lib/python2.7/site-packages/conda_build/build.py", line 436, in write_info_json
    for dist in sorted(dists + [m.dist()]):
  File "/home/ubuntu/miniconda2/lib/python2.7/site-packages/conda/models/dist.py", line 230, in __gt__
    assert isinstance(other, self.__class__)
AssertionError

conda build conda.recipe returned exit code 1

Action failed: conda build conda.recipe
```

Let me know if you need any additional information.


Discussion:
Thanks.  This has also been reported on flowdock, I think.  It's a conda 4.3 incompatibility.  Downgrading to conda 4.2 should fix it for you.  I'll fix this in conda-build for the next bugfix release.

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -47,7 +47,7 @@
 from .conda_interface import CrossPlatformStLink
 from .conda_interface import PathType, FileMode
 from .conda_interface import EntityEncoder
-from .conda_interface import dist_str_in_index
+from .conda_interface import dist_str_in_index, Dist
 
 from conda_build import __version__
 from conda_build import environ, source, tarcheck, utils
@@ -436,7 +436,10 @@ def write_info_json(m, config):
 # It can be used to create the runtime environment of this package using:
 # $ conda create --name <env> --file <this file>
 """ % (m.dist(), config.subdir))
-            for dist in sorted(dists + [m.dist()]):
+            dist = m.dist()
+            if hasattr(dists[0], 'version'):
+                dist = Dist(dist)
+            for dist in sorted(dists + [dist]):
                 fo.write('%s\n' % '='.join(dist.split('::', 1)[-1].rsplit('-', 2)))
         if pin_depends == 'strict':
             info_index['depends'] = [' '.join(dist.split('::', 1)[-1].rsplit('-', 2))
diff --git a/conda_build/conda_interface.py b/conda_build/conda_interface.py
--- a/conda_build/conda_interface.py
+++ b/conda_build/conda_interface.py
@@ -158,6 +158,7 @@ def which_prefix(path):
     from conda.exports import CrossPlatformStLink
     CrossPlatformStLink = CrossPlatformStLink
     from conda.exports import dist_str_in_index
+    from conda.models.dist import Dist
 else:
     from json import JSONEncoder
     from os import lstat
@@ -165,6 +166,9 @@ def which_prefix(path):
 
     dist_str_in_index = lambda index, dist_str: dist_str in index
 
+    class Dist(object):
+        pass
+
     class PathType(Enum):
         """
         Refers to if the file in question is hard linked or soft linked. Originally designed to be
diff --git a/conda_build/environ.py b/conda_build/environ.py
--- a/conda_build/environ.py
+++ b/conda_build/environ.py
@@ -64,12 +64,12 @@ def verify_git_repo(git_dir, git_url, config, expected_rev='HEAD'):
     env['GIT_DIR'] = git_dir
     try:
         # Verify current commit matches expected commit
-        current_commit = subprocess.check_output(["git", "log", "-n1", "--format=%H"],
-                                      env=env, stderr=stderr)
+        current_commit = utils.check_output_env(["git", "log", "-n1", "--format=%H"],
+                                                env=env, stderr=stderr)
         current_commit = current_commit.decode('utf-8')
-        expected_tag_commit = subprocess.check_output(["git", "log", "-n1", "--format=%H",
-                                            expected_rev],
-                                            env=env, stderr=stderr)
+        expected_tag_commit = utils.check_output_env(["git", "log", "-n1", "--format=%H",
+                                                      expected_rev],
+                                                     env=env, stderr=stderr)
         expected_tag_commit = expected_tag_commit.decode('utf-8')
 
         if current_commit != expected_tag_commit:
@@ -77,8 +77,8 @@ def verify_git_repo(git_dir, git_url, config, expected_rev='HEAD'):
 
         # Verify correct remote url. Need to find the git cache directory,
         # and check the remote from there.
-        cache_details = subprocess.check_output(["git", "remote", "-v"], env=env,
-                                     stderr=stderr)
+        cache_details = utils.check_output_env(["git", "remote", "-v"], env=env,
+                                               stderr=stderr)
         cache_details = cache_details.decode('utf-8')
         cache_dir = cache_details.split('\n')[0].split()[1]
 
@@ -87,13 +87,13 @@ def verify_git_repo(git_dir, git_url, config, expected_rev='HEAD'):
             cache_dir = cache_dir.encode(sys.getfilesystemencoding() or 'utf-8')
 
         try:
-            remote_details = subprocess.check_output(["git", "--git-dir", cache_dir,
-                                                      "remote", "-v"],
+            remote_details = utils.check_output_env(["git", "--git-dir", cache_dir,
+                                                     "remote", "-v"],
                                                      env=env, stderr=stderr)
         except subprocess.CalledProcessError:
             if sys.platform == 'win32' and cache_dir.startswith('/'):
                 cache_dir = utils.convert_unix_path_to_win(cache_dir)
-            remote_details = subprocess.check_output(["git", "--git-dir", cache_dir,
+            remote_details = utils.check_output_env(["git", "--git-dir", cache_dir,
                                                       "remote", "-v"],
                                                      env=env, stderr=stderr)
         remote_details = remote_details.decode('utf-8')
@@ -152,7 +152,7 @@ def get_git_info(repo, config):
     keys = ["GIT_DESCRIBE_TAG", "GIT_DESCRIBE_NUMBER", "GIT_DESCRIBE_HASH"]
 
     try:
-        output = subprocess.check_output(["git", "describe", "--tags", "--long", "HEAD"],
+        output = utils.check_output_env(["git", "describe", "--tags", "--long", "HEAD"],
                                          env=env, cwd=os.path.dirname(repo),
                                          stderr=stderr).splitlines()[0]
         output = output.decode('utf-8')
@@ -162,7 +162,7 @@ def get_git_info(repo, config):
             d.update(dict(zip(keys, parts)))
 
         # get the _full_ hash of the current HEAD
-        output = subprocess.check_output(["git", "rev-parse", "HEAD"],
+        output = utils.check_output_env(["git", "rev-parse", "HEAD"],
                                          env=env, cwd=os.path.dirname(repo),
                                          stderr=stderr).splitlines()[0]
         output = output.decode('utf-8')
@@ -191,7 +191,7 @@ def get_hg_build_info(repo):
     cmd = ["hg", "log", "--template",
            "{rev}|{node|short}|{latesttag}|{latesttagdistance}|{branch}",
            "--rev", "."]
-    output = subprocess.check_output(cmd, env=env, cwd=os.path.dirname(repo))
+    output = utils.check_output_env(cmd, env=env, cwd=os.path.dirname(repo))
     output = output.decode('utf-8')
     rev, short_id, tag, distance, branch = output.split('|')
     if tag != 'null':


Test patch:
diff --git a/tests/test_api_build.py b/tests/test_api_build.py
--- a/tests/test_api_build.py
+++ b/tests/test_api_build.py
@@ -882,3 +882,8 @@ def test_recursion_layers(test_config):
     """go two 'hops' - try to build a, but a needs b, so build b first, then come back to a"""
     recipe = os.path.join(metadata_dir, '_recursive-build-two-layer')
     api.build(recipe, config=test_config)
+
+
+def test_pin_depends(test_metadata):
+    test_metadata.meta['build']['pin_depends'] = 'record'
+    api.build(test_metadata)