Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9.2, 0.9.3, and 1.0

stable setup: update version detection code

Fixes #832

Changeset cadd0b29698d

Parent 9e6c172dbfa8

by Steve Borho

Changes to one file · Browse files at cadd0b29698d Showing diff from parent 9e6c172dbfa8 Diff from another changeset...

Change 1 of 2 Show Entire File setup.py Stacked
 
159
160
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
163
164
165
 
 
 
 
 
166
167
168
 
170
171
172
173
174
 
 
 
175
176
177
178
 
 
 
 
 
 
 
 
 
179
180
181
182
 
 
183
184
185
186
 
 
187
188
 
 
189
190
191
192
193
194
 
195
196
197
 
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
 
 
178
179
180
181
182
183
184
185
 
187
188
189
 
 
190
191
192
193
194
 
 
195
196
197
198
199
200
201
202
203
204
 
 
 
205
206
207
208
209
 
210
211
212
213
214
215
216
217
218
219
220
 
221
222
223
224
@@ -159,10 +159,27 @@
  (scripts, packages, data_files, extra) = setup_posix()   desc='TortoiseHg dialogs for Mercurial VCS'   +def runcmd(cmd, env): + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, env=env) + out, err = p.communicate() + # If root is executing setup.py, but the repository is owned by + # another user (as in "sudo python setup.py install") we will get + # trust warnings since the .hg/hgrc file is untrusted. That is + # fine, we don't want to load it anyway. + err = [e for e in err.splitlines() + if not e.startswith('Not trusting file')] + if err: + return '' + return out +  version = ''   -try: - l = os.popen('hg -R . id -i -t').read().split() +if os.path.isdir('.hg'): + env = os.environ + env.update({'HGRCPATH': '', 'LANGUAGE': 'C'}) + cmd = ['hg', 'id', '-i', '-t'] + l = runcmd(cmd, env).split()   while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags   l.pop()   if len(l) > 1: # tag found @@ -170,28 +187,38 @@
  if l[0].endswith('+'): # propagate the dirty status to the tag   version += '+'   elif len(l) == 1: # no tag found - cmd = 'hg parents --template {latesttag}+{latesttagdistance}-' - version = os.popen(cmd).read() + l[0] + cmd = ['hg', 'parents', '--template', + '{latesttag}+{latesttagdistance}-'] + version = runcmd(cmd, env) + l[0]   if version.endswith('+'):   version += time.strftime('%Y%m%d') -except OSError: - version = "unknown" +elif os.path.exists('.hg_archival.txt'): + kw = dict([t.strip() for t in l.split(':', 1)] + for l in open('.hg_archival.txt')) + if 'tag' in kw: + version = kw['tag'] + elif 'latesttag' in kw: + version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw + else: + version = kw.get('node', '')[:12]   -verfile = os.path.join('tortoisehg', 'util', '__version__.py') -if version != 'unknown' or not os.path.exists(verfile): - f = file(verfile, "w") +if version: + f = open("tortoisehg/util/__version__.py", "w")   f.write('# this file is autogenerated by setup.py\n')   f.write('version = "%s"\n' % version)   f.close() -else: + +try:   import tortoisehg.util.__version__   version = tortoisehg.util.__version__.version +except ImportError: + version = 'unknown'    setup(name="tortoisehg",   version=version,   author='Steve Borho',   author_email='steve@borho.org', - url='http://tortoisehg.bitbucket.org', + url='http://tortoisehg.org',   description=desc,   license='GNU GPL2',   scripts=scripts,