changeset 82:ae90caf26224

Support for installing from Git.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 01 Sep 2014 14:54:34 -0700
parents d64e4703f5e6
children f9f67086415c b3ce11b2cf36
files .gitignore setup.py
diffstat 2 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Mon Sep 01 14:54:34 2014 -0700
@@ -0,0 +1,8 @@
+*.pyc
+venv/
+build/lib
+build/messages/_cache
+dist/
+piecrust.egg-info/
+piecrust/__version__.py
+
--- a/setup.py	Sun Aug 31 23:48:18 2014 -0700
+++ b/setup.py	Mon Sep 01 14:54:34 2014 -0700
@@ -55,10 +55,15 @@
 def generate_version():
     """ Generate a version file from the source control information.
         (this is loosely based on what Mercurial does)"""
-    if not os.path.isdir(os.path.join(os.path.dirname(__file__), '.hg')):
+    if os.path.isdir(os.path.join(os.path.dirname(__file__), '.hg')):
+        return generate_version_from_mercurial()
+    elif os.path.isdir(os.path.join(os.path.dirname(__file__), '.git')):
+        return generate_version_from_git()
+    else:
         raise Exception("Can't generate version number: this is not a "
                         "Mercurial repository.")
 
+def generate_version_from_mercurial():
     try:
         # Get the version we're currently on. Also see if we have local
         # changes.
@@ -88,7 +93,7 @@
                 # Let's just do as if we were on the tag.
                 version = tag
             else:
-                version = '%s-%s.%s' % (tag, dist, hgid)
+                version = '%s-%s-%s' % (tag, dist, hgid)
 
         if has_local_changes:
             version += time.strftime('+%Y%m%d')
@@ -101,6 +106,21 @@
         raise Exception("Can't generate version number: %s" % ex)
 
 
+def generate_version_from_git():
+    try:
+        cmd = ['git', 'describe', '--tags', '--dirty=+']
+        version, err = runcmd(cmd)
+        version = version.decode('utf8').strip()
+        if version.endswith('+'):
+            version += time.strftime('%Y%m%d')
+        return version
+    except OSError:
+        raise Exception("Can't generate version number: Git isn't installed, "
+                        "or in the PATH.")
+    except Exception as ex:
+        raise Exception("Can't generate version number: %s" % ex)
+
+
 def write_version(version):
     if not version:
         raise Exception("No version to write!")