human
Complete this python program:
def git_prebuild(pkg_dir, build_cmd=build_py):
assistant
#Here is the Python code you requested.

    """Return extended build or sdist command class for recording commit
    records git commit in IPython.utils._sysinfo.commit
    for use in IPython.utils.sysinfo.sys_info() calls after installation.
    """
    class MyBuildPy(build_cmd, ):
        '    Subclass    to    write    commit    data    into    installation    tree    '
        def run(self):
            print 'check    version    number'
            loose_pep440re = re.compile('^(\\d+)\\.(\\d+)\\.(\\d+((a|b|rc)\\d+)?)(\\.post\\d+)?(\\.dev\\d*)?$')
            if (not loose_pep440re.match(version)):
                raise ValueError(("Version    number    '%s'    is    not    valid    (should    match    [N!]N(.N)*[{a|b|rc}N][.postN][.devN])" % version))
            build_cmd.run(self)
            if hasattr(self, 'build_lib'):
                self._record_commit(self.build_lib)
        def make_release_tree(self, base_dir, files):
            build_cmd.make_release_tree(self, base_dir, files)
            self._record_commit(base_dir)
        def _record_commit(self, base_dir):
            import subprocess
            proc = subprocess.Popen('git    rev-parse    --short    HEAD', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
            (repo_commit, _) = proc.communicate()
            repo_commit = repo_commit.strip().decode('ascii')
            out_pth = pjoin(base_dir, pkg_dir, 'utils', '_sysinfo.py')
            if (os.path.isfile(out_pth) and (not repo_commit)):
                return
            print ("writing    git    commit    '%s'    to    %s" % (repo_commit, out_pth))
            try:
                os.remove(out_pth)
            except (IOError, OSError):
                pass
            with open(out_pth, 'w') as out_file:
                out_file.writelines(['#    GENERATED    BY    setup.py\n', ('commit    =    u"%s"\n' % repo_commit)])
    return MyBuildPy