Repository: conda/conda-build

Issue:
build failing
I get this error every time I try to build my package from my git repository, If I download the source code from a tag it works just fine. If you need anymore info from my end feel free to email me at weinbe.58@gmail.com

Here is the traceback:

Traceback (most recent call last):
  File "/share/pkg/anaconda2/4.0.0/install/bin/conda-build", line 5, in <module>
    sys.exit(main())
  File "/share/pkg/anaconda2/4.0.0/install/lib/python2.7/site-packages/conda_build/main_build.py", line 134, in main
    args_func(args, p)
  File "/share/pkg/anaconda2/4.0.0/install/lib/python2.7/site-packages/conda_build/main_build.py", line 373, in args_func
    args.func(args, p)
  File "/share/pkg/anaconda2/4.0.0/install/lib/python2.7/site-packages/conda_build/main_build.py", line 320, in execute
    need_source_download=need_source_download)
  File "/share/pkg/anaconda2/4.0.0/install/lib/python2.7/site-packages/conda_build/build.py", line 543, in build
    include_recipe=bool(m.path) and include_recipe)
  File "/share/pkg/anaconda2/4.0.0/install/lib/python2.7/site-packages/conda_build/build.py", line 195, in create_info_files
    f.write("# " + source.get_repository_info(m.path) + "\n")
  File "/share/pkg/anaconda2/4.0.0/install/lib/python2.7/site-packages/conda_build/source.py", line 292, in get_repository_info
    origin = check_output(["git", "config", "--get", "remote.origin.url"])
  File "/share/pkg/anaconda2/4.0.0/install/lib/python2.7/subprocess.py", line 573, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['git', 'config', '--get', 'remote.origin.url']' returned non-zero exit status 1

Current conda install:

```
         platform : linux-64
    conda version : 4.0.7
```

  conda-build version : 1.20.3
       python version : 2.7.11.final.0
     requests version : 2.9.1
     root environment : /share/pkg/anaconda2/4.0.0/install  (read only)
  default environment : /usr3/graduate/weinbe58/.conda/envs/default
     envs directories : /usr3/graduate/weinbe58/.conda/envs
                        /usr3/graduate/weinbe58/envs
                        /share/pkg/anaconda2/4.0.0/install/envs
        package cache : /usr3/graduate/weinbe58/.conda/envs/.pkgs
                        /usr3/graduate/weinbe58/envs/.pkgs
                        /share/pkg/anaconda2/4.0.0/install/pkgs
         channel URLs : https://repo.continuum.io/pkgs/free/linux-64/
                        https://repo.continuum.io/pkgs/free/noarch/
                        https://repo.continuum.io/pkgs/pro/linux-64/
                        https://repo.continuum.io/pkgs/pro/noarch/
          config file : None
    is foreign system : False



Discussion:
What is your git repository?  It looks like conda-build is confused about the origin url.  Does your repo have an origin url?  What does

```
git config --get remote.origin.url
```

show for you?

What does

```
git remote -v 
```

show?

'git config --get remote.origin.url' returns:

https://weinbe58@github.com/weinbe58/exact_diag_py.git

'git remote -v' displays:
origin  https://weinbe58@github.com/weinbe58/exact_diag_py.git (fetch)
origin  https://weinbe58@github.com/weinbe58/exact_diag_py.git (push)

my repository is at github.com/weinbe58/exact_diag_py.git

But why does conda-build need my repository information in the first place? for the source I'm using the path to the local directory: path: ./ 

Not from my git repo.

I have no idea why it's barfing, but thanks for the info.  I haven't tested urls with @ in them much - maybe that's related.

one of the things that conda build does is rendering jinja2 templates.  People often pull git data into their recipe this way.  Conda build uses the origin information to record where it got the recipe template from, before "rendering" it - my aim was reproducibility.  Even though your recipe is pointed at local source, your git repo has a remote origin, and that's the info that conda-build wants.

This should not fail so poorly.  I'll add some error handling code.


Resolving patch:
diff --git a/conda_build/source.py b/conda_build/source.py
--- a/conda_build/source.py
+++ b/conda_build/source.py
@@ -1,11 +1,12 @@
 from __future__ import absolute_import, division, print_function
 
 import os
+import logging
 import re
 import sys
 from os.path import join, isdir, isfile, abspath, expanduser, basename
 from shutil import copytree, copy2
-from subprocess import check_call, Popen, PIPE, check_output
+from subprocess import check_call, Popen, PIPE, check_output, CalledProcessError
 import locale
 import time
 
@@ -17,13 +18,14 @@
 from conda_build.config import config
 from conda_build.utils import rm_rf, tar_xf, unzip, safe_print_unicode
 
-
 SRC_CACHE = join(config.croot, 'src_cache')
 GIT_CACHE = join(config.croot, 'git_cache')
 HG_CACHE = join(config.croot, 'hg_cache')
 SVN_CACHE = join(config.croot, 'svn_cache')
 WORK_DIR = join(config.croot, 'work')
 
+log = logging.getLogger(__file__)
+
 
 def get_dir():
     if not isdir(WORK_DIR):
@@ -288,20 +290,26 @@ def parse_bool(s):
 def get_repository_info(recipe_path):
     """This tries to get information about where a recipe came from.  This is different
     from the source - you can have a recipe in svn that gets source via git."""
-    if isdir(join(recipe_path, ".git")):
-        origin = check_output(["git", "config", "--get", "remote.origin.url"], cwd=recipe_path)
-        rev = check_output(["git", "rev-parse", "HEAD"], cwd=recipe_path)
-        return "Origin {}, commit {}".format(origin, rev)
-    elif isdir(join(recipe_path, ".hg")):
-        origin = check_output(["hg", "paths", "default"], cwd=recipe_path)
-        rev = check_output(["hg", "id"], cwd=recipe_path).split()[0]
-        return "Origin {}, commit {}".format(origin, rev)
-    elif isdir(join(recipe_path, ".svn")):
-        info = check_output(["svn", "info"], cwd=recipe_path)
-        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)
-    else:
+    try:
+        if isdir(join(recipe_path, ".git")):
+            origin = check_output(["git", "config", "--get", "remote.origin.url"], cwd=recipe_path)
+            rev = check_output(["git", "rev-parse", "HEAD"], cwd=recipe_path)
+            return "Origin {}, commit {}".format(origin, rev)
+        elif isdir(join(recipe_path, ".hg")):
+            origin = check_output(["hg", "paths", "default"], cwd=recipe_path)
+            rev = check_output(["hg", "id"], cwd=recipe_path).split()[0]
+            return "Origin {}, commit {}".format(origin, rev)
+        elif isdir(join(recipe_path, ".svn")):
+            info = check_output(["svn", "info"], cwd=recipe_path)
+            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)
+        else:
+            return "{}, last modified {}".format(recipe_path,
+                                             time.ctime(os.path.getmtime(
+                                                 join(recipe_path, "meta.yaml"))))
+    except CalledProcessError:
+        log.debug("Failed to checkout source in " + recipe_path)
         return "{}, last modified {}".format(recipe_path,
                                              time.ctime(os.path.getmtime(
                                                  join(recipe_path, "meta.yaml"))))


Test patch: