Repository: dj-stripe/dj-stripe

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. 



Discussion:
Good find. Interesting that that hasn't come up before. I'll look forward to your patch.


Resolving patch:
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=[


Test patch: