Show More
@@ -148,23 +148,28 b' def runcmd(cmd, env):' | |||
|
148 | 148 | out, err = p.communicate() |
|
149 | 149 | return p.returncode, out, err |
|
150 | 150 | |
|
151 | def runhg(cmd, env): | |
|
152 | returncode, out, err = runcmd(cmd, env) | |
|
153 | # 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 | |
|
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 | |
|
151 | class hgcommand(object): | |
|
152 | def __init__(self): | |
|
153 | self.cmd = [sys.executable, 'hg'] | |
|
154 | self.env = gethgenv() | |
|
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 | 174 | def gethgenv(): |
|
170 | 175 | # Execute hg out of this directory with a custom environment which takes |
@@ -180,13 +185,13 b' def gethgenv():' | |||
|
180 | 185 | # https://bugs.python.org/issue13524#msg148850 |
|
181 | 186 | env['SystemRoot'] = os.environ['SystemRoot'] |
|
182 | 187 | |
|
183 | env = gethgenv() | |
|
184 | 188 | version = '' |
|
185 | 189 | |
|
186 | 190 | if os.path.isdir('.hg'): |
|
187 | cmd = [sys.executable, 'hg', 'log', '-r', '.', '--template', '{tags}\n'] | |
|
188 | numerictags = [t for t in runhg(cmd, env).split() if t[0:1].isdigit()] | |
|
189 | hgid = runhg([sys.executable, 'hg', 'id', '-i'], env).strip() | |
|
191 | hg = hgcommand() | |
|
192 | cmd = ['log', '-r', '.', '--template', '{tags}\n'] | |
|
193 | numerictags = [t for t in hg.run(cmd).split() if t[0:1].isdigit()] | |
|
194 | hgid = hg.run(['id', '-i']).strip() | |
|
190 | 195 | if not hgid: |
|
191 | 196 | # Bail out if hg is having problems interacting with this repository, |
|
192 | 197 | # rather than falling through and producing a bogus version number. |
@@ -198,12 +203,10 b" if os.path.isdir('.hg'):" | |||
|
198 | 203 | if hgid.endswith('+'): # propagate the dirty status to the tag |
|
199 | 204 | version += '+' |
|
200 | 205 | else: # no tag found |
|
201 |
ltagcmd = [ |
|
|
202 | '{latesttag}'] | |
|
203 | ltag = runhg(ltagcmd, env) | |
|
204 | changessincecmd = [sys.executable, 'hg', 'log', '-T', 'x\n', '-r', | |
|
205 | "only(.,'%s')" % ltag] | |
|
206 | changessince = len(runhg(changessincecmd, env).splitlines()) | |
|
206 | ltagcmd = ['parents', '--template', '{latesttag}'] | |
|
207 | ltag = hg.run(ltagcmd) | |
|
208 | changessincecmd = ['log', '-T', 'x\n', '-r', "only(.,'%s')" % ltag] | |
|
209 | changessince = len(hg.run(changessincecmd).splitlines()) | |
|
207 | 210 | version = '%s+%s-%s' % (ltag, changessince, hgid) |
|
208 | 211 | if version.endswith('+'): |
|
209 | 212 | version += time.strftime('%Y%m%d') |
@@ -407,7 +410,7 b' class buildhgextindex(Command):' | |||
|
407 | 410 | # here no extension enabled, disabled() lists up everything |
|
408 | 411 | code = ('import pprint; from mercurial import extensions; ' |
|
409 | 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 | 414 | if err or returncode != 0: |
|
412 | 415 | raise DistutilsExecError(err) |
|
413 | 416 |
General Comments 0
You need to be logged in to leave comments.
Login now