setup.py
branchstable
changeset 33598 f30714a55523
parent 33591 ee11d18fcd3c
child 33599 cfa08b06d8b5
equal deleted inserted replaced
33597:a3ac1ea611ce 33598:f30714a55523
   199         self.env = env
   199         self.env = env
   200 
   200 
   201     def run(self, args):
   201     def run(self, args):
   202         cmd = self.cmd + args
   202         cmd = self.cmd + args
   203         returncode, out, err = runcmd(cmd, self.env)
   203         returncode, out, err = runcmd(cmd, self.env)
   204         # If root is executing setup.py, but the repository is owned by
   204         err = filterhgerr(err)
   205         # another user (as in "sudo python setup.py install") we will get
       
   206         # trust warnings since the .hg/hgrc file is untrusted. That is
       
   207         # fine, we don't want to load it anyway.  Python may warn about
       
   208         # a missing __init__.py in mercurial/locale, we also ignore that.
       
   209         err = [e for e in err.splitlines()
       
   210                if not e.startswith(b'not trusting file') \
       
   211                   and not e.startswith(b'warning: Not importing') \
       
   212                   and not e.startswith(b'obsolete feature not enabled')]
       
   213         if err or returncode != 0:
   205         if err or returncode != 0:
   214             printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr)
   206             printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr)
   215             printf(b'\n'.join([b'  ' + e for e in err]), file=sys.stderr)
   207             printf(err, file=sys.stderr)
   216             return ''
   208             return ''
   217         return out
   209         return out
       
   210 
       
   211 def filterhgerr(err):
       
   212     # If root is executing setup.py, but the repository is owned by
       
   213     # another user (as in "sudo python setup.py install") we will get
       
   214     # trust warnings since the .hg/hgrc file is untrusted. That is
       
   215     # fine, we don't want to load it anyway.  Python may warn about
       
   216     # a missing __init__.py in mercurial/locale, we also ignore that.
       
   217     err = [e for e in err.splitlines()
       
   218            if (not e.startswith(b'not trusting file')
       
   219                and not e.startswith(b'warning: Not importing')
       
   220                and not e.startswith(b'obsolete feature not enabled'))]
       
   221     return b'\n'.join(b'  ' + e for e in err)
   218 
   222 
   219 def findhg():
   223 def findhg():
   220     """Try to figure out how we should invoke hg for examining the local
   224     """Try to figure out how we should invoke hg for examining the local
   221     repository contents.
   225     repository contents.
   222 
   226 
   237     check_cmd = ['log', '-r.', '-Ttest']
   241     check_cmd = ['log', '-r.', '-Ttest']
   238     try:
   242     try:
   239         retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
   243         retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
   240     except EnvironmentError:
   244     except EnvironmentError:
   241         retcode = -1
   245         retcode = -1
   242     if retcode == 0:
   246     if retcode == 0 and not filterhgerr(err):
   243         return hgcommand(hgcmd, hgenv)
   247         return hgcommand(hgcmd, hgenv)
   244 
   248 
   245     # Fall back to trying the local hg installation.
   249     # Fall back to trying the local hg installation.
   246     hgenv = localhgenv()
   250     hgenv = localhgenv()
   247     # Don't source any system hgrc files when using the local hg.
   251     # Don't source any system hgrc files when using the local hg.
   249     hgcmd = [sys.executable, 'hg']
   253     hgcmd = [sys.executable, 'hg']
   250     try:
   254     try:
   251         retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
   255         retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
   252     except EnvironmentError:
   256     except EnvironmentError:
   253         retcode = -1
   257         retcode = -1
   254     if retcode == 0:
   258     if retcode == 0 and not filterhgerr(err):
   255         return hgcommand(hgcmd, hgenv)
   259         return hgcommand(hgcmd, hgenv)
   256 
   260 
   257     raise SystemExit('Unable to find a working hg binary to extract the '
   261     raise SystemExit('Unable to find a working hg binary to extract the '
   258                      'version from the repository tags')
   262                      'version from the repository tags')
   259 
   263