pypy-effect-analysis / pypy / tool / version.py

import py
import os
from subprocess import Popen, PIPE
import pypy
pypydir = os.path.dirname(os.path.abspath(pypy.__file__))


def get_mercurial_info():
    '''Obtain Mercurial version information by invoking the 'hg' command.'''
    # TODO: support extracting from .hg_archival.txt

    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')):
        env = dict(os.environ)
        # get Mercurial into scripting mode
        env['HGPLAIN'] = '1'
        # disable user configuration, extensions, etc.
        env['HGRCPATH'] = os.devnull

        p = Popen([str(hgexe), 'id', '-i', pypyroot], stdout=PIPE, env=env)
        hgid = p.stdout.read().strip()

        p = Popen([str(hgexe), 'id', '-t', pypyroot], stdout=PIPE, env=env)
        hgtag = p.stdout.read().strip().split()[0]

        if hgtag == 'tip':
            # use the branch instead
            p = Popen([str(hgexe), 'id', '-b', pypyroot], stdout=PIPE, env=env)
            hgtag = p.stdout.read().strip()

        return 'PyPy', hgtag, hgid
    else:
        return None
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.