comparison setup.py @ 82:ae90caf26224

Support for installing from Git.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 01 Sep 2014 14:54:34 -0700
parents fdb08d986384
children f49fcf9448df
comparison
equal deleted inserted replaced
81:d64e4703f5e6 82:ae90caf26224
53 53
54 54
55 def generate_version(): 55 def generate_version():
56 """ Generate a version file from the source control information. 56 """ Generate a version file from the source control information.
57 (this is loosely based on what Mercurial does)""" 57 (this is loosely based on what Mercurial does)"""
58 if not os.path.isdir(os.path.join(os.path.dirname(__file__), '.hg')): 58 if os.path.isdir(os.path.join(os.path.dirname(__file__), '.hg')):
59 return generate_version_from_mercurial()
60 elif os.path.isdir(os.path.join(os.path.dirname(__file__), '.git')):
61 return generate_version_from_git()
62 else:
59 raise Exception("Can't generate version number: this is not a " 63 raise Exception("Can't generate version number: this is not a "
60 "Mercurial repository.") 64 "Mercurial repository.")
61 65
66 def generate_version_from_mercurial():
62 try: 67 try:
63 # Get the version we're currently on. Also see if we have local 68 # Get the version we're currently on. Also see if we have local
64 # changes. 69 # changes.
65 cmd = ['hg', 'id', '-i'] 70 cmd = ['hg', 'id', '-i']
66 hgid, err = runcmd(cmd) 71 hgid, err = runcmd(cmd)
86 if dist == '1': 91 if dist == '1':
87 # We're on the commit that created the tag in the first place. 92 # We're on the commit that created the tag in the first place.
88 # Let's just do as if we were on the tag. 93 # Let's just do as if we were on the tag.
89 version = tag 94 version = tag
90 else: 95 else:
91 version = '%s-%s.%s' % (tag, dist, hgid) 96 version = '%s-%s-%s' % (tag, dist, hgid)
92 97
93 if has_local_changes: 98 if has_local_changes:
94 version += time.strftime('+%Y%m%d') 99 version += time.strftime('+%Y%m%d')
95 100
96 return version 101 return version
97 except OSError: 102 except OSError:
98 raise Exception("Can't generate version number: Mercurial isn't " 103 raise Exception("Can't generate version number: Mercurial isn't "
99 "installed, or in the PATH.") 104 "installed, or in the PATH.")
105 except Exception as ex:
106 raise Exception("Can't generate version number: %s" % ex)
107
108
109 def generate_version_from_git():
110 try:
111 cmd = ['git', 'describe', '--tags', '--dirty=+']
112 version, err = runcmd(cmd)
113 version = version.decode('utf8').strip()
114 if version.endswith('+'):
115 version += time.strftime('%Y%m%d')
116 return version
117 except OSError:
118 raise Exception("Can't generate version number: Git isn't installed, "
119 "or in the PATH.")
100 except Exception as ex: 120 except Exception as ex:
101 raise Exception("Can't generate version number: %s" % ex) 121 raise Exception("Can't generate version number: %s" % ex)
102 122
103 123
104 def write_version(version): 124 def write_version(version):