We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
parsl installed from pip tries to determine its version using git
Every time I run parsl I get:

```
kacperk@dxl1: /dpool/kacperk/arxiv $ python scraper_parsl.py
fatal: Not a git repository: '/home/kacperk/.local/lib/python3.6/site-packages/.git'
```

and in logs:

```
2018-07-15 12:54:06 parsl.utils:24 [ERROR]  Unable to determine code state
Traceback (most recent call last):
  File "/home/kacperk/.local/lib/python3.6/site-packages/parsl/utils.py", line 19, in get_version
    head = subprocess.check_output(cmd, env=env).strip().decode('utf-8')
  File "/home/kacperk/miniconda3/lib/python3.6/subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "/home/kacperk/miniconda3/lib/python3.6/subprocess.py", line 418, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['git', 'rev-parse', '--short', 'HEAD']' returned non-zero exit status 128.
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `parsl/utils.py`
Content:
```
1 import logging
2 import os
3 import shlex
4 import subprocess
5 import threading
6 import time
7 from contextlib import contextmanager
8 from functools import wraps
9 
10 import parsl
11 from parsl.version import VERSION
12 
13 logger = logging.getLogger(__name__)
14 
15 
16 def get_version():
17     version = parsl.__version__
18     work_tree = os.path.dirname(os.path.dirname(__file__))
19     git_dir = os.path.join(work_tree, '.git')
20     env = {'GIT_WORK_TREE': work_tree, 'GIT_DIR': git_dir}
21     try:
22         cmd = shlex.split('git rev-parse --short HEAD')
23         head = subprocess.check_output(cmd, env=env).strip().decode('utf-8')
24         diff = subprocess.check_output(shlex.split('git diff HEAD'), env=env)
25         status = 'dirty' if diff else 'clean'
26         version = '{v}-{head}-{status}'.format(v=VERSION, head=head, status=status)
27     except Exception as e:
28         pass
29 
30     return version
31 
32 
33 def get_all_checkpoints(rundir="runinfo"):
34     """Finds the checkpoints from all last runs.
35 
36     Note that checkpoints are incremental, and this helper will not find
37     previous checkpoints from earlier than the most recent run. It probably
38     should be made to do so.
39 
40     Kwargs:
41        - rundir(str) : Path to the runinfo directory
42 
43     Returns:
44        - a list suitable for the checkpointFiles parameter of DataFlowKernel
45          constructor
46 
47     """
48 
49     if(not(os.path.isdir(rundir))):
50         return []
51 
52     dirs = sorted(os.listdir(rundir))
53 
54     checkpoints = []
55 
56     for runid in dirs:
57 
58         checkpoint = os.path.abspath('{}/{}/checkpoint'.format(rundir, runid))
59 
60         if(os.path.isdir(checkpoint)):
61             checkpoints.append(checkpoint)
62 
63     return checkpoints
64 
65 
66 def get_last_checkpoint(rundir="runinfo"):
67     """Finds the checkpoint from the last run, if one exists.
68 
69     Note that checkpoints are incremental, and this helper will not find
70     previous checkpoints from earlier than the most recent run. It probably
71     should be made to do so.
72 
73     Kwargs:
74        - rundir(str) : Path to the runinfo directory
75 
76     Returns:
77      - a list suitable for checkpointFiles parameter of DataFlowKernel
78        constructor, with 0 or 1 elements
79 
80     """
81 
82     if(not(os.path.isdir(rundir))):
83         return []
84 
85     dirs = sorted(os.listdir(rundir))
86 
87     if(len(dirs) == 0):
88         return []
89 
90     last_runid = dirs[-1]
91     last_checkpoint = os.path.abspath('{}/{}/checkpoint'.format(rundir, last_runid))
92 
93     if(not(os.path.isdir(last_checkpoint))):
94         return []
95 
96     return [last_checkpoint]
97 
98 
99 def timeout(seconds=None):
100     def decorator(func, *args, **kwargs):
101         @wraps(func)
102         def wrapper(*args, **kwargs):
103             t = threading.Thread(target=func, args=args, kwargs=kwargs)
104             t.start()
105             result = t.join(seconds)
106             if t.is_alive():
107                 raise RuntimeError('timed out in {}'.format(func))
108             return result
109         return wrapper
110     return decorator
111 
112 
113 @contextmanager
114 def wait_for_file(path, seconds=10):
115     for i in range(0, int(seconds * 100)):
116         time.sleep(seconds / 100.)
117         if os.path.exists(path):
118             break
119     yield
120 
121 
122 @contextmanager
123 def time_limited_open(path, mode, seconds=1):
124     wait_for_file(path, seconds)
125 
126     f = open(path, mode)
127     yield f
128     f.close()
129
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/parsl/utils.py b/parsl/utils.py
--- a/parsl/utils.py
+++ b/parsl/utils.py
@@ -17,15 +17,16 @@
     version = parsl.__version__
     work_tree = os.path.dirname(os.path.dirname(__file__))
     git_dir = os.path.join(work_tree, '.git')
-    env = {'GIT_WORK_TREE': work_tree, 'GIT_DIR': git_dir}
-    try:
-        cmd = shlex.split('git rev-parse --short HEAD')
-        head = subprocess.check_output(cmd, env=env).strip().decode('utf-8')
-        diff = subprocess.check_output(shlex.split('git diff HEAD'), env=env)
-        status = 'dirty' if diff else 'clean'
-        version = '{v}-{head}-{status}'.format(v=VERSION, head=head, status=status)
-    except Exception as e:
-        pass
+    if os.path.exists(git_dir):
+        env = {'GIT_WORK_TREE': work_tree, 'GIT_DIR': git_dir}
+        try:
+            cmd = shlex.split('git rev-parse --short HEAD')
+            head = subprocess.check_output(cmd, env=env).strip().decode('utf-8')
+            diff = subprocess.check_output(shlex.split('git diff HEAD'), env=env)
+            status = 'dirty' if diff else 'clean'
+            version = '{v}-{head}-{status}'.format(v=VERSION, head=head, status=status)
+        except Exception as e:
+            pass
 
     return version

{"golden_diff": "diff --git a/parsl/utils.py b/parsl/utils.py\n--- a/parsl/utils.py\n+++ b/parsl/utils.py\n@@ -17,15 +17,16 @@\n     version = parsl.__version__\n     work_tree = os.path.dirname(os.path.dirname(__file__))\n     git_dir = os.path.join(work_tree, '.git')\n-    env = {'GIT_WORK_TREE': work_tree, 'GIT_DIR': git_dir}\n-    try:\n-        cmd = shlex.split('git rev-parse --short HEAD')\n-        head = subprocess.check_output(cmd, env=env).strip().decode('utf-8')\n-        diff = subprocess.check_output(shlex.split('git diff HEAD'), env=env)\n-        status = 'dirty' if diff else 'clean'\n-        version = '{v}-{head}-{status}'.format(v=VERSION, head=head, status=status)\n-    except Exception as e:\n-        pass\n+    if os.path.exists(git_dir):\n+        env = {'GIT_WORK_TREE': work_tree, 'GIT_DIR': git_dir}\n+        try:\n+            cmd = shlex.split('git rev-parse --short HEAD')\n+            head = subprocess.check_output(cmd, env=env).strip().decode('utf-8')\n+            diff = subprocess.check_output(shlex.split('git diff HEAD'), env=env)\n+            status = 'dirty' if diff else 'clean'\n+            version = '{v}-{head}-{status}'.format(v=VERSION, head=head, status=status)\n+        except Exception as e:\n+            pass\n \n     return version\n", "issue": "parsl installed from pip tries to determine its version using git\nEvery time I run parsl I get:\r\n\r\n```\r\nkacperk@dxl1: /dpool/kacperk/arxiv $ python scraper_parsl.py\r\nfatal: Not a git repository: '/home/kacperk/.local/lib/python3.6/site-packages/.git'\r\n```\r\n\r\nand in logs:\r\n\r\n```\r\n2018-07-15 12:54:06 parsl.utils:24 [ERROR]  Unable to determine code state\r\nTraceback (most recent call last):\r\n  File \"/home/kacperk/.local/lib/python3.6/site-packages/parsl/utils.py\", line 19, in get_version\r\n    head = subprocess.check_output(cmd, env=env).strip().decode('utf-8')\r\n  File \"/home/kacperk/miniconda3/lib/python3.6/subprocess.py\", line 336, in check_output\r\n    **kwargs).stdout\r\n  File \"/home/kacperk/miniconda3/lib/python3.6/subprocess.py\", line 418, in run\r\n    output=stdout, stderr=stderr)\r\nsubprocess.CalledProcessError: Command '['git', 'rev-parse', '--short', 'HEAD']' returned non-zero exit status 128.\r\n```\n", "before_files": [{"content": "import logging\nimport os\nimport shlex\nimport subprocess\nimport threading\nimport time\nfrom contextlib import contextmanager\nfrom functools import wraps\n\nimport parsl\nfrom parsl.version import VERSION\n\nlogger = logging.getLogger(__name__)\n\n\ndef get_version():\n    version = parsl.__version__\n    work_tree = os.path.dirname(os.path.dirname(__file__))\n    git_dir = os.path.join(work_tree, '.git')\n    env = {'GIT_WORK_TREE': work_tree, 'GIT_DIR': git_dir}\n    try:\n        cmd = shlex.split('git rev-parse --short HEAD')\n        head = subprocess.check_output(cmd, env=env).strip().decode('utf-8')\n        diff = subprocess.check_output(shlex.split('git diff HEAD'), env=env)\n        status = 'dirty' if diff else 'clean'\n        version = '{v}-{head}-{status}'.format(v=VERSION, head=head, status=status)\n    except Exception as e:\n        pass\n\n    return version\n\n\ndef get_all_checkpoints(rundir=\"runinfo\"):\n    \"\"\"Finds the checkpoints from all last runs.\n\n    Note that checkpoints are incremental, and this helper will not find\n    previous checkpoints from earlier than the most recent run. It probably\n    should be made to do so.\n\n    Kwargs:\n       - rundir(str) : Path to the runinfo directory\n\n    Returns:\n       - a list suitable for the checkpointFiles parameter of DataFlowKernel\n         constructor\n\n    \"\"\"\n\n    if(not(os.path.isdir(rundir))):\n        return []\n\n    dirs = sorted(os.listdir(rundir))\n\n    checkpoints = []\n\n    for runid in dirs:\n\n        checkpoint = os.path.abspath('{}/{}/checkpoint'.format(rundir, runid))\n\n        if(os.path.isdir(checkpoint)):\n            checkpoints.append(checkpoint)\n\n    return checkpoints\n\n\ndef get_last_checkpoint(rundir=\"runinfo\"):\n    \"\"\"Finds the checkpoint from the last run, if one exists.\n\n    Note that checkpoints are incremental, and this helper will not find\n    previous checkpoints from earlier than the most recent run. It probably\n    should be made to do so.\n\n    Kwargs:\n       - rundir(str) : Path to the runinfo directory\n\n    Returns:\n     - a list suitable for checkpointFiles parameter of DataFlowKernel\n       constructor, with 0 or 1 elements\n\n    \"\"\"\n\n    if(not(os.path.isdir(rundir))):\n        return []\n\n    dirs = sorted(os.listdir(rundir))\n\n    if(len(dirs) == 0):\n        return []\n\n    last_runid = dirs[-1]\n    last_checkpoint = os.path.abspath('{}/{}/checkpoint'.format(rundir, last_runid))\n\n    if(not(os.path.isdir(last_checkpoint))):\n        return []\n\n    return [last_checkpoint]\n\n\ndef timeout(seconds=None):\n    def decorator(func, *args, **kwargs):\n        @wraps(func)\n        def wrapper(*args, **kwargs):\n            t = threading.Thread(target=func, args=args, kwargs=kwargs)\n            t.start()\n            result = t.join(seconds)\n            if t.is_alive():\n                raise RuntimeError('timed out in {}'.format(func))\n            return result\n        return wrapper\n    return decorator\n\n\n@contextmanager\ndef wait_for_file(path, seconds=10):\n    for i in range(0, int(seconds * 100)):\n        time.sleep(seconds / 100.)\n        if os.path.exists(path):\n            break\n    yield\n\n\n@contextmanager\ndef time_limited_open(path, mode, seconds=1):\n    wait_for_file(path, seconds)\n\n    f = open(path, mode)\n    yield f\n    f.close()\n", "path": "parsl/utils.py"}], "after_files": [{"content": "import logging\nimport os\nimport shlex\nimport subprocess\nimport threading\nimport time\nfrom contextlib import contextmanager\nfrom functools import wraps\n\nimport parsl\nfrom parsl.version import VERSION\n\nlogger = logging.getLogger(__name__)\n\n\ndef get_version():\n    version = parsl.__version__\n    work_tree = os.path.dirname(os.path.dirname(__file__))\n    git_dir = os.path.join(work_tree, '.git')\n    if os.path.exists(git_dir):\n        env = {'GIT_WORK_TREE': work_tree, 'GIT_DIR': git_dir}\n        try:\n            cmd = shlex.split('git rev-parse --short HEAD')\n            head = subprocess.check_output(cmd, env=env).strip().decode('utf-8')\n            diff = subprocess.check_output(shlex.split('git diff HEAD'), env=env)\n            status = 'dirty' if diff else 'clean'\n            version = '{v}-{head}-{status}'.format(v=VERSION, head=head, status=status)\n        except Exception as e:\n            pass\n\n    return version\n\n\ndef get_all_checkpoints(rundir=\"runinfo\"):\n    \"\"\"Finds the checkpoints from all last runs.\n\n    Note that checkpoints are incremental, and this helper will not find\n    previous checkpoints from earlier than the most recent run. It probably\n    should be made to do so.\n\n    Kwargs:\n       - rundir(str) : Path to the runinfo directory\n\n    Returns:\n       - a list suitable for the checkpointFiles parameter of DataFlowKernel\n         constructor\n\n    \"\"\"\n\n    if(not(os.path.isdir(rundir))):\n        return []\n\n    dirs = sorted(os.listdir(rundir))\n\n    checkpoints = []\n\n    for runid in dirs:\n\n        checkpoint = os.path.abspath('{}/{}/checkpoint'.format(rundir, runid))\n\n        if(os.path.isdir(checkpoint)):\n            checkpoints.append(checkpoint)\n\n    return checkpoints\n\n\ndef get_last_checkpoint(rundir=\"runinfo\"):\n    \"\"\"Finds the checkpoint from the last run, if one exists.\n\n    Note that checkpoints are incremental, and this helper will not find\n    previous checkpoints from earlier than the most recent run. It probably\n    should be made to do so.\n\n    Kwargs:\n       - rundir(str) : Path to the runinfo directory\n\n    Returns:\n     - a list suitable for checkpointFiles parameter of DataFlowKernel\n       constructor, with 0 or 1 elements\n\n    \"\"\"\n\n    if(not(os.path.isdir(rundir))):\n        return []\n\n    dirs = sorted(os.listdir(rundir))\n\n    if(len(dirs) == 0):\n        return []\n\n    last_runid = dirs[-1]\n    last_checkpoint = os.path.abspath('{}/{}/checkpoint'.format(rundir, last_runid))\n\n    if(not(os.path.isdir(last_checkpoint))):\n        return []\n\n    return [last_checkpoint]\n\n\ndef timeout(seconds=None):\n    def decorator(func, *args, **kwargs):\n        @wraps(func)\n        def wrapper(*args, **kwargs):\n            t = threading.Thread(target=func, args=args, kwargs=kwargs)\n            t.start()\n            result = t.join(seconds)\n            if t.is_alive():\n                raise RuntimeError('timed out in {}'.format(func))\n            return result\n        return wrapper\n    return decorator\n\n\n@contextmanager\ndef wait_for_file(path, seconds=10):\n    for i in range(0, int(seconds * 100)):\n        time.sleep(seconds / 100.)\n        if os.path.exists(path):\n            break\n    yield\n\n\n@contextmanager\ndef time_limited_open(path, mode, seconds=1):\n    wait_for_file(path, seconds)\n\n    f = open(path, mode)\n    yield f\n    f.close()\n", "path": "parsl/utils.py"}]}