Commits

Germano Gabbianelli committed 6851e0d

Fixed version utils.

  • Participants
  • Parent commits 6c471b6

Comments (0)

Files changed (2)

autocomplete/__init__.py

-def get_installed_version(version='unknown'):
-    import os
+__version__ = '1.0'
+
+def get_installed_version():
     import pkg_resources
-    path = os.path.join(__path__[0], os.pardir)
     try:
-        pkg = list(pkg_resources.find_distributions(path, True))[0]
-    except IndexError:
-        return version
-    return pkg.version
+        autocomplete = pkg_resources.get_distribution('django-autocomplete')
+    except pkg_resources.DistributionNotFound:
+        return __version__
+    return autocomplete.version
 
-
-def get_version(version='unknown'):
+def get_version(installed=True):
     import os
     path = os.path.join(__path__[0], os.pardir)
     try:
         from mercurial.hg import repository
         from mercurial.ui import ui
         from mercurial import node, error
-    except ImportError:
-        return get_installed_version(version)
-    try:
+
         repo = repository(ui(), path)
-    except error.RepoError:
-        return get_installed_version(version)
+    except:
+        if installed:
+            return get_installed_version()
+        return __version__
     tip = repo.changelog.tip()
     rev = repo.changelog.rev(tip)
-    return '%s.dev%d' % (version, rev)
-
-__version__ = get_version('1.0')
+    return '%s.dev%d' % (__version__, rev)
 
 setup(
     name = 'django-autocomplete',
-    version = autocomplete.__version__,
+    version = autocomplete.get_version(installed=False),
     description = 'autocomplete utilities for django',
     author = 'Germano Gabbianelli',
     author_email = 'tyrion.mx@gmail.com',