Commits

Germano Gabbianelli committed 1daaf1e

Fixed version utils.
Now the correct version should be displayed when installing from an "official"
release.

Comments (0)

Files changed (2)

autocomplete/__init__.py

         return __version__
     return autocomplete.version
 
-def get_version(installed=True):
+
+def get_mercurial_version():
     import os
     path = os.path.join(__path__[0], os.pardir)
     try:
 
         repo = repository(ui(), path)
     except:
-        if installed:
-            return get_installed_version()
-        return __version__
+        return None
     tip = repo.changelog.tip()
     rev = repo.changelog.rev(tip)
     return '%s.dev%d' % (__version__, rev)
+
+
+def get_version():
+    return get_mercurial_version() or get_installed_version()
+
 from setuptools import setup
+import pkg_resources
 import autocomplete
 
+
+def get_metadata_version():
+    """
+    Tries to get the version from the django_autocomplete.egg-info directory.
+    """
+    try:
+        pkg = list(pkg_resources.find_distributions('.', True))[0]
+    except IndexError:
+        return autocomplete.__version__
+    return pkg.version
+
+version = autocomplete.get_mercurial_version() or get_metadata_version()
+
 setup(
     name = 'django-autocomplete',
-    version = autocomplete.get_version(installed=False),
+    version = version,
     description = 'autocomplete utilities for django',
     author = 'Germano Gabbianelli',
     author_email = 'tyrion.mx@gmail.com',
-    url = 'http://bitbucket.org/tyrion/django-autocomplete2',
-    download_url = 'http://bitbucket.org/tyrion/django-autocomplete2/downloads',
+    url = 'http://bitbucket.org/tyrion/django-autocomplete',
+    download_url = 'http://bitbucket.org/tyrion/django-autocomplete/downloads',
     packages = ['autocomplete'],
     include_package_data = True,
     classifiers = [