prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  importing djstripe within setup.py causes race condition when installing from repo
  Trying to install dj-stripe from a repo runs into a race condition at setup.py:
  
  ``` bash
  pip install -e git://github.com/pydanny/dj-stripe.git#egg=djstripe                                                           
  Obtaining djstripe from git+git://github.com/pydanny/dj-stripe.git#egg=djstripe
    Cloning git://github.com/pydanny/dj-stripe.git to ./v/test_djstripe/src/djstripe
      Complete output from command python setup.py egg_info:
      Traceback (most recent call last):
        File "<string>", line 20, in <module>
        File "/home/dave/v/test_djstripe/src/djstripe/setup.py", line 6, in <module>
          import djstripe
        File "/home/dave/v/test_djstripe/src/djstripe/djstripe/__init__.py", line 4, in <module>
          from django import get_version as get_django_version
      ImportError: No module named 'django'
  
      ----------------------------------------
  ```
  
  There are a few ways to fix this. I would suggest the, for example, get_version(package) methods used in https://github.com/pydanny/django-admin2/blob/master/setup.py
  
  This is a trivial fix, I'll get a patch together soon. 
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `setup.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 
  3 import os
  4 import sys
  5 
  6 import djstripe
  7 
  8 version = djstripe.__version__
  9 
  10 try:
  11     from setuptools import setup
  12 except ImportError:
  13     from distutils.core import setup
  14 
  15 if sys.argv[-1] == 'publish':
  16     os.system('python setup.py sdist upload')
  17     os.system('python setup.py bdist_wheel upload')
  18     sys.exit()
  19 
  20 if sys.argv[-1] == 'tag':
  21     print("Tagging the version on github:")
  22     os.system("git tag -a %s -m 'version %s'" % (version, version))
  23     os.system("git push --tags")
  24     sys.exit()
  25 
  26 readme = open('README.rst').read()
  27 history = open('HISTORY.rst').read().replace('.. :changelog:', '')
  28 
  29 INSTALL_REQUIRES = [
  30     'django>=1.7',
  31     'stripe>=1.22.2',
  32     'django-model-utils>=2.2',
  33     'django-braces>=1.8.0',
  34     'jsonfield>=1.0.3',
  35     'pytz>=2015.4'
  36 ]
  37 
  38 setup(
  39     name='dj-stripe',
  40     version=version,
  41     description=djstripe.__summary__,
  42     long_description=readme + '\n\n' + history,
  43     author=djstripe.__author__,
  44     author_email=djstripe.__email__,
  45     url=djstripe.__uri__,
  46     packages=[
  47         'djstripe',
  48     ],
  49     package_dir={'djstripe': 'djstripe'},
  50     include_package_data=True,
  51     install_requires=INSTALL_REQUIRES,
  52     license=djstripe.__license__,
  53     zip_safe=False,
  54     keywords='stripe django',
  55     classifiers=[
  56         'Development Status :: 4 - Beta',
  57         'Environment :: Web Environment',
  58         'Framework :: Django',
  59         'Framework :: Django :: 1.7',
  60         'Framework :: Django :: 1.8',
  61         'Intended Audience :: Developers',
  62         'License :: OSI Approved :: BSD License',
  63         'Natural Language :: English',
  64         "Programming Language :: Python :: 2",
  65         'Programming Language :: Python :: 2.7',
  66         'Programming Language :: Python :: 3',
  67         'Programming Language :: Python :: 3.3',
  68         'Programming Language :: Python :: 3.4',
  69         'Programming Language :: Python :: 3.5'
  70     ],
  71 )
  72
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/setup.py b/setup.py
  --- a/setup.py
  +++ b/setup.py
  @@ -1,11 +1,37 @@
   #!/usr/bin/env python
   
  +import ast
   import os
   import sys
   
  -import djstripe
   
  -version = djstripe.__version__
  +class MetadataFinder(ast.NodeVisitor):
  +    def __init__(self):
  +        self.version = None
  +        self.summary = None
  +        self.author = None
  +        self.email = None
  +        self.uri = None
  +        self.licence = None
  +
  +    def visit_Assign(self, node):
  +        if node.targets[0].id == '__version__':
  +            self.version = node.value.s
  +        elif node.targets[0].id == '__summary__':
  +            self.summary = node.value.s
  +        elif node.targets[0].id == '__author__':
  +            self.author = node.value.s
  +        elif node.targets[0].id == '__email__':
  +            self.email = node.value.s
  +        elif node.targets[0].id == '__uri__':
  +            self.uri = node.value.s
  +        elif node.targets[0].id == '__license__':
  +            self.license = node.value.s
  +
  +
  +with open(os.path.join('djstripe', '__init__.py')) as open_file:
  +    finder = MetadataFinder()
  +    finder.visit(ast.parse(open_file.read()))
   
   try:
       from setuptools import setup
  @@ -19,7 +45,8 @@
   
   if sys.argv[-1] == 'tag':
       print("Tagging the version on github:")
  -    os.system("git tag -a %s -m 'version %s'" % (version, version))
  +    os.system("git tag -a %s -m 'version %s'" % (finder.version,
  +                                                 finder.version))
       os.system("git push --tags")
       sys.exit()
   
  @@ -37,19 +64,19 @@
   
   setup(
       name='dj-stripe',
  -    version=version,
  -    description=djstripe.__summary__,
  +    version=finder.version,
  +    description=finder.summary,
       long_description=readme + '\n\n' + history,
  -    author=djstripe.__author__,
  -    author_email=djstripe.__email__,
  -    url=djstripe.__uri__,
  +    author=finder.author,
  +    author_email=finder.email,
  +    url=finder.uri,
       packages=[
           'djstripe',
       ],
       package_dir={'djstripe': 'djstripe'},
       include_package_data=True,
       install_requires=INSTALL_REQUIRES,
  -    license=djstripe.__license__,
  +    license=finder.license,
       zip_safe=False,
       keywords='stripe django',
       classifiers=[
  
verification_info: {"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -1,11 +1,37 @@\n #!/usr/bin/env python\n \n+import ast\n import os\n import sys\n \n-import djstripe\n \n-version = djstripe.__version__\n+class MetadataFinder(ast.NodeVisitor):\n+    def __init__(self):\n+        self.version = None\n+        self.summary = None\n+        self.author = None\n+        self.email = None\n+        self.uri = None\n+        self.licence = None\n+\n+    def visit_Assign(self, node):\n+        if node.targets[0].id == '__version__':\n+            self.version = node.value.s\n+        elif node.targets[0].id == '__summary__':\n+            self.summary = node.value.s\n+        elif node.targets[0].id == '__author__':\n+            self.author = node.value.s\n+        elif node.targets[0].id == '__email__':\n+            self.email = node.value.s\n+        elif node.targets[0].id == '__uri__':\n+            self.uri = node.value.s\n+        elif node.targets[0].id == '__license__':\n+            self.license = node.value.s\n+\n+\n+with open(os.path.join('djstripe', '__init__.py')) as open_file:\n+    finder = MetadataFinder()\n+    finder.visit(ast.parse(open_file.read()))\n \n try:\n     from setuptools import setup\n@@ -19,7 +45,8 @@\n \n if sys.argv[-1] == 'tag':\n     print(\"Tagging the version on github:\")\n-    os.system(\"git tag -a %s -m 'version %s'\" % (version, version))\n+    os.system(\"git tag -a %s -m 'version %s'\" % (finder.version,\n+                                                 finder.version))\n     os.system(\"git push --tags\")\n     sys.exit()\n \n@@ -37,19 +64,19 @@\n \n setup(\n     name='dj-stripe',\n-    version=version,\n-    description=djstripe.__summary__,\n+    version=finder.version,\n+    description=finder.summary,\n     long_description=readme + '\\n\\n' + history,\n-    author=djstripe.__author__,\n-    author_email=djstripe.__email__,\n-    url=djstripe.__uri__,\n+    author=finder.author,\n+    author_email=finder.email,\n+    url=finder.uri,\n     packages=[\n         'djstripe',\n     ],\n     package_dir={'djstripe': 'djstripe'},\n     include_package_data=True,\n     install_requires=INSTALL_REQUIRES,\n-    license=djstripe.__license__,\n+    license=finder.license,\n     zip_safe=False,\n     keywords='stripe django',\n     classifiers=[\n", "issue": "importing djstripe within setup.py causes race condition when installing from repo\nTrying to install dj-stripe from a repo runs into a race condition at setup.py:\n\n``` bash\npip install -e git://github.com/pydanny/dj-stripe.git#egg=djstripe                                                           \nObtaining djstripe from git+git://github.com/pydanny/dj-stripe.git#egg=djstripe\n  Cloning git://github.com/pydanny/dj-stripe.git to ./v/test_djstripe/src/djstripe\n    Complete output from command python setup.py egg_info:\n    Traceback (most recent call last):\n      File \"<string>\", line 20, in <module>\n      File \"/home/dave/v/test_djstripe/src/djstripe/setup.py\", line 6, in <module>\n        import djstripe\n      File \"/home/dave/v/test_djstripe/src/djstripe/djstripe/__init__.py\", line 4, in <module>\n        from django import get_version as get_django_version\n    ImportError: No module named 'django'\n\n    ----------------------------------------\n```\n\nThere are a few ways to fix this. I would suggest the, for example, get_version(package) methods used in https://github.com/pydanny/django-admin2/blob/master/setup.py\n\nThis is a trivial fix, I'll get a patch together soon. \n\n", "before_files": [{"content": "#!/usr/bin/env python\n\nimport os\nimport sys\n\nimport djstripe\n\nversion = djstripe.__version__\n\ntry:\n    from setuptools import setup\nexcept ImportError:\n    from distutils.core import setup\n\nif sys.argv[-1] == 'publish':\n    os.system('python setup.py sdist upload')\n    os.system('python setup.py bdist_wheel upload')\n    sys.exit()\n\nif sys.argv[-1] == 'tag':\n    print(\"Tagging the version on github:\")\n    os.system(\"git tag -a %s -m 'version %s'\" % (version, version))\n    os.system(\"git push --tags\")\n    sys.exit()\n\nreadme = open('README.rst').read()\nhistory = open('HISTORY.rst').read().replace('.. :changelog:', '')\n\nINSTALL_REQUIRES = [\n    'django>=1.7',\n    'stripe>=1.22.2',\n    'django-model-utils>=2.2',\n    'django-braces>=1.8.0',\n    'jsonfield>=1.0.3',\n    'pytz>=2015.4'\n]\n\nsetup(\n    name='dj-stripe',\n    version=version,\n    description=djstripe.__summary__,\n    long_description=readme + '\\n\\n' + history,\n    author=djstripe.__author__,\n    author_email=djstripe.__email__,\n    url=djstripe.__uri__,\n    packages=[\n        'djstripe',\n    ],\n    package_dir={'djstripe': 'djstripe'},\n    include_package_data=True,\n    install_requires=INSTALL_REQUIRES,\n    license=djstripe.__license__,\n    zip_safe=False,\n    keywords='stripe django',\n    classifiers=[\n        'Development Status :: 4 - Beta',\n        'Environment :: Web Environment',\n        'Framework :: Django',\n        'Framework :: Django :: 1.7',\n        'Framework :: Django :: 1.8',\n        'Intended Audience :: Developers',\n        'License :: OSI Approved :: BSD License',\n        'Natural Language :: English',\n        \"Programming Language :: Python :: 2\",\n        'Programming Language :: Python :: 2.7',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.3',\n        'Programming Language :: Python :: 3.4',\n        'Programming Language :: Python :: 3.5'\n    ],\n)\n", "path": "setup.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\nimport ast\nimport os\nimport sys\n\n\nclass MetadataFinder(ast.NodeVisitor):\n    def __init__(self):\n        self.version = None\n        self.summary = None\n        self.author = None\n        self.email = None\n        self.uri = None\n        self.licence = None\n\n    def visit_Assign(self, node):\n        if node.targets[0].id == '__version__':\n            self.version = node.value.s\n        elif node.targets[0].id == '__summary__':\n            self.summary = node.value.s\n        elif node.targets[0].id == '__author__':\n            self.author = node.value.s\n        elif node.targets[0].id == '__email__':\n            self.email = node.value.s\n        elif node.targets[0].id == '__uri__':\n            self.uri = node.value.s\n        elif node.targets[0].id == '__license__':\n            self.license = node.value.s\n\n\nwith open(os.path.join('djstripe', '__init__.py')) as open_file:\n    finder = MetadataFinder()\n    finder.visit(ast.parse(open_file.read()))\n\ntry:\n    from setuptools import setup\nexcept ImportError:\n    from distutils.core import setup\n\nif sys.argv[-1] == 'publish':\n    os.system('python setup.py sdist upload')\n    os.system('python setup.py bdist_wheel upload')\n    sys.exit()\n\nif sys.argv[-1] == 'tag':\n    print(\"Tagging the version on github:\")\n    os.system(\"git tag -a %s -m 'version %s'\" % (finder.version,\n                                                 finder.version))\n    os.system(\"git push --tags\")\n    sys.exit()\n\nreadme = open('README.rst').read()\nhistory = open('HISTORY.rst').read().replace('.. :changelog:', '')\n\nINSTALL_REQUIRES = [\n    'django>=1.7',\n    'stripe>=1.22.2',\n    'django-model-utils>=2.2',\n    'django-braces>=1.8.0',\n    'jsonfield>=1.0.3',\n    'pytz>=2015.4'\n]\n\nsetup(\n    name='dj-stripe',\n    version=finder.version,\n    description=finder.summary,\n    long_description=readme + '\\n\\n' + history,\n    author=finder.author,\n    author_email=finder.email,\n    url=finder.uri,\n    packages=[\n        'djstripe',\n    ],\n    package_dir={'djstripe': 'djstripe'},\n    include_package_data=True,\n    install_requires=INSTALL_REQUIRES,\n    license=finder.license,\n    zip_safe=False,\n    keywords='stripe django',\n    classifiers=[\n        'Development Status :: 4 - Beta',\n        'Environment :: Web Environment',\n        'Framework :: Django',\n        'Framework :: Django :: 1.7',\n        'Framework :: Django :: 1.8',\n        'Intended Audience :: Developers',\n        'License :: OSI Approved :: BSD License',\n        'Natural Language :: English',\n        \"Programming Language :: Python :: 2\",\n        'Programming Language :: Python :: 2.7',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.3',\n        'Programming Language :: Python :: 3.4',\n        'Programming Language :: Python :: 3.5'\n    ],\n)\n", "path": "setup.py"}]}