Repository: DataBiosphere/toil

Issue:
Can't install from tarball on GitHub
```
$ pip install https://github.com/BD2KGenomics/toil/archive/3.14.0.tar.gz
Collecting https://github.com/BD2KGenomics/toil/archive/3.14.0.tar.gz
  Downloading https://github.com/BD2KGenomics/toil/archive/3.14.0.tar.gz
     - 7.0MB 40.4MB/s
    Complete output from command python setup.py egg_info:
    fatal: Not a git repository (or any of the parent directories): .git
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-l5WfLH-build/setup.py", line 152, in <module>
        version = importVersion()
      File "/tmp/pip-l5WfLH-build/setup.py", line 132, in importVersion
        new = version_template.expand_()
      File "version_template.py", line 131, in expand_
        return ''.join("%s = %s\n" % (k, repr(resolve(k))) for k, v in variables.items())
      File "version_template.py", line 131, in <genexpr>
        return ''.join("%s = %s\n" % (k, repr(resolve(k))) for k, v in variables.items())
      File "version_template.py", line 127, in resolve
        v = v()
      File "version_template.py", line 85, in dockerShortTag
        return shortVersion()
      File "version_template.py", line 46, in shortVersion
        return _version(shorten=True)
      File "version_template.py", line 51, in _version
        currentCommit()[:7 if shorten else None],
      File "version_template.py", line 111, in currentCommit
        return check_output('git log --pretty=oneline -n 1 -- $(pwd)', shell=True).split()[0]
      File "/usr/lib/python2.7/subprocess.py", line 223, in check_output
        raise CalledProcessError(retcode, cmd, output=output)
    subprocess.CalledProcessError: Command 'git log --pretty=oneline -n 1 -- $(pwd)' returned non-zero exit status 128
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-l5WfLH-build/
```


Discussion:
Toil uses a customized code to automatically set versions for setup.py using version_template.py. This code coordinates tags between pypi and docker so that the code correctly calls the corresponding container when running in the cloud. Development versions are labeled with the git commit hash, which is found with a call to commit. Released code does not package .git, which is causing the failure in this case.
Thanks @ejacox, that is what I had guessed as well. I recommend making a release script that uploads a correct tarball to GitHub.

You benefit from having more consistent releases as it'll be a good time to automate other aspects like always building and uploading a wheel to PyPI.
This isn't an arbitrary issue, I had to manually add the version file for the package of Toil I'm making for Debian.

Resolving patch:
diff --git a/version_template.py b/version_template.py
--- a/version_template.py
+++ b/version_template.py
@@ -108,13 +108,21 @@ def buildNumber():
 
 def currentCommit():
     from subprocess import check_output
-    return check_output('git log --pretty=oneline -n 1 -- $(pwd)', shell=True).split()[0]
+    try:
+        output = check_output('git log --pretty=oneline -n 1 -- $(pwd)', shell=True).split()[0]
+    except:
+        # Return this we are not in a git environment.
+        return '000'
+    return output
 
 
 def dirty():
     from subprocess import call
-    return 0 != call('(git diff --exit-code '
-                     '&& git diff --cached --exit-code) > /dev/null', shell=True)
+    try:
+        return 0 != call('(git diff --exit-code '
+                         '&& git diff --cached --exit-code) > /dev/null', shell=True)
+    except:
+        return False # In case the git call fails.
 
 
 def expand_(name=None):


Test patch: