Commits

Dan Villiom Podlaski Christiansen committed ce73833

Better Mercurial identification patch.

Comments (0)

Files changed (1)

sys-mercurial.diff

 +    '''Obtain Mercurial version information by invoking the 'hg' command.'''
 +    # TODO: support extracting from .hg_archival.txt
 +    import py
++    from subprocess import Popen, PIPE
 +
 +    pypyroot = os.path.abspath(os.path.join(pypydir, '..'))
 +    hgexe = py.path.local.sysfind('hg')
 +
 +    if hgexe and os.path.isdir(os.path.join(pypyroot, '.hg')):
-+        os.putenv('HGPLAIN', '1')
-+        fp = os.popen('%s id -i "%s"' % (hgexe, os.path.join(pypydir, '..')))
-+        hgid = fp.read().strip()
-+        fp.close()
++        env = dict(os.environ)
++        env['HGPLAIN'] = '1'
++        p = Popen([str(hgexe), 'id', '-i', pypyroot], stdout=PIPE, env=env)
++        hgid = p.stdout.read().strip()
 +
-+        fp = os.popen('%s id -t "%s"' % (hgexe, os.path.join(pypydir, '..')))
-+        hgtags = fp.read().strip()
-+        fp.close()
++        p = Popen([str(hgexe), 'id', '-t', pypyroot], stdout=PIPE, env=env)
++        hgtags = p.stdout.read().strip()
 +
 +        return space.newtuple([space.wrap('PyPy'),
 +                               space.wrap(hgtags),