Show More
@@ -148,23 +148,28 b' 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 | # If root is executing setup.py, but the repository is owned by |
|
153 | self.cmd = [sys.executable, 'hg'] | |
154 | # another user (as in "sudo python setup.py install") we will get |
|
154 | self.env = gethgenv() | |
155 | # trust warnings since the .hg/hgrc file is untrusted. That is |
|
|||
156 | # fine, we don't want to load it anyway. Python may warn about |
|
|||
157 | # a missing __init__.py in mercurial/locale, we also ignore that. |
|
|||
158 | err = [e for e in err.splitlines() |
|
|||
159 | if not e.startswith(b'not trusting file') \ |
|
|||
160 | and not e.startswith(b'warning: Not importing') \ |
|
|||
161 | and not e.startswith(b'obsolete feature not enabled')] |
|
|||
162 | if err or returncode != 0: |
|
|||
163 | printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr) |
|
|||
164 | printf(b'\n'.join([b' ' + e for e in err]), file=sys.stderr) |
|
|||
165 | return '' |
|
|||
166 | return out |
|
|||
167 |
|
155 | |||
|
156 | def run(self, args): | |||
|
157 | cmd = self.cmd + args | |||
|
158 | returncode, out, err = runcmd(cmd, self.env) | |||
|
159 | # If root is executing setup.py, but the repository is owned by | |||
|
160 | # another user (as in "sudo python setup.py install") we will get | |||
|
161 | # trust warnings since the .hg/hgrc file is untrusted. That is | |||
|
162 | # fine, we don't want to load it anyway. Python may warn about | |||
|
163 | # a missing __init__.py in mercurial/locale, we also ignore that. | |||
|
164 | err = [e for e in err.splitlines() | |||
|
165 | if not e.startswith(b'not trusting file') \ | |||
|
166 | and not e.startswith(b'warning: Not importing') \ | |||
|
167 | and not e.startswith(b'obsolete feature not enabled')] | |||
|
168 | if err or returncode != 0: | |||
|
169 | printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr) | |||
|
170 | printf(b'\n'.join([b' ' + e for e in err]), file=sys.stderr) | |||
|
171 | return '' | |||
|
172 | return out | |||
168 |
|
173 | |||
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 | |
@@ -180,13 +185,13 b' 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 b" 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 b' 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