Show More
@@ -148,8 +148,14 def runcmd(cmd, env): | |||||
148 | out, err = p.communicate() |
|
148 | out, err = p.communicate() | |
149 | return p.returncode, out, err |
|
149 | return p.returncode, out, err | |
150 |
|
150 | |||
151 | def runhg(cmd, env): |
|
151 | class hgcommand(object): | |
152 | returncode, out, err = runcmd(cmd, env) |
|
152 | def __init__(self): | |
|
153 | self.cmd = [sys.executable, 'hg'] | |||
|
154 | self.env = gethgenv() | |||
|
155 | ||||
|
156 | def run(self, args): | |||
|
157 | cmd = self.cmd + args | |||
|
158 | returncode, out, err = runcmd(cmd, self.env) | |||
153 | # If root is executing setup.py, but the repository is owned by |
|
159 | # If root is executing setup.py, but the repository is owned by | |
154 | # another user (as in "sudo python setup.py install") we will get |
|
160 | # another user (as in "sudo python setup.py install") we will get | |
155 | # trust warnings since the .hg/hgrc file is untrusted. That is |
|
161 | # trust warnings since the .hg/hgrc file is untrusted. That is | |
@@ -165,7 +171,6 def runhg(cmd, env): | |||||
165 | return '' |
|
171 | return '' | |
166 | return out |
|
172 | return out | |
167 |
|
173 | |||
168 |
|
||||
169 | def gethgenv(): |
|
174 | def gethgenv(): | |
170 | # Execute hg out of this directory with a custom environment which takes |
|
175 | # Execute hg out of this directory with a custom environment which takes | |
171 | # care to not use any hgrc files and do no localization. |
|
176 | # care to not use any hgrc files and do no localization. | |
@@ -180,13 +185,13 def gethgenv(): | |||||
180 | # https://bugs.python.org/issue13524#msg148850 |
|
185 | # https://bugs.python.org/issue13524#msg148850 | |
181 | env['SystemRoot'] = os.environ['SystemRoot'] |
|
186 | env['SystemRoot'] = os.environ['SystemRoot'] | |
182 |
|
187 | |||
183 | env = gethgenv() |
|
|||
184 | version = '' |
|
188 | version = '' | |
185 |
|
189 | |||
186 | if os.path.isdir('.hg'): |
|
190 | if os.path.isdir('.hg'): | |
187 | cmd = [sys.executable, 'hg', 'log', '-r', '.', '--template', '{tags}\n'] |
|
191 | hg = hgcommand() | |
188 | numerictags = [t for t in runhg(cmd, env).split() if t[0:1].isdigit()] |
|
192 | cmd = ['log', '-r', '.', '--template', '{tags}\n'] | |
189 | hgid = runhg([sys.executable, 'hg', 'id', '-i'], env).strip() |
|
193 | numerictags = [t for t in hg.run(cmd).split() if t[0:1].isdigit()] | |
|
194 | hgid = hg.run(['id', '-i']).strip() | |||
190 | if not hgid: |
|
195 | if not hgid: | |
191 | # Bail out if hg is having problems interacting with this repository, |
|
196 | # Bail out if hg is having problems interacting with this repository, | |
192 | # rather than falling through and producing a bogus version number. |
|
197 | # rather than falling through and producing a bogus version number. | |
@@ -198,12 +203,10 if os.path.isdir('.hg'): | |||||
198 | if hgid.endswith('+'): # propagate the dirty status to the tag |
|
203 | if hgid.endswith('+'): # propagate the dirty status to the tag | |
199 | version += '+' |
|
204 | version += '+' | |
200 | else: # no tag found |
|
205 | else: # no tag found | |
201 |
ltagcmd = [ |
|
206 | ltagcmd = ['parents', '--template', '{latesttag}'] | |
202 | '{latesttag}'] |
|
207 | ltag = hg.run(ltagcmd) | |
203 | ltag = runhg(ltagcmd, env) |
|
208 | changessincecmd = ['log', '-T', 'x\n', '-r', "only(.,'%s')" % ltag] | |
204 | changessincecmd = [sys.executable, 'hg', 'log', '-T', 'x\n', '-r', |
|
209 | changessince = len(hg.run(changessincecmd).splitlines()) | |
205 | "only(.,'%s')" % ltag] |
|
|||
206 | changessince = len(runhg(changessincecmd, env).splitlines()) |
|
|||
207 | version = '%s+%s-%s' % (ltag, changessince, hgid) |
|
210 | version = '%s+%s-%s' % (ltag, changessince, hgid) | |
208 | if version.endswith('+'): |
|
211 | if version.endswith('+'): | |
209 | version += time.strftime('%Y%m%d') |
|
212 | version += time.strftime('%Y%m%d') | |
@@ -407,7 +410,7 class buildhgextindex(Command): | |||||
407 | # here no extension enabled, disabled() lists up everything |
|
410 | # here no extension enabled, disabled() lists up everything | |
408 | code = ('import pprint; from mercurial import extensions; ' |
|
411 | code = ('import pprint; from mercurial import extensions; ' | |
409 | 'pprint.pprint(extensions.disabled())') |
|
412 | 'pprint.pprint(extensions.disabled())') | |
410 | returncode, out, err = runcmd([sys.executable, '-c', code], env) |
|
413 | returncode, out, err = runcmd([sys.executable, '-c', code], gethgenv()) | |
411 | if err or returncode != 0: |
|
414 | if err or returncode != 0: | |
412 | raise DistutilsExecError(err) |
|
415 | raise DistutilsExecError(err) | |
413 |
|
416 |
General Comments 0
You need to be logged in to leave comments.
Login now