def add_pyrobuf_module(dist, pyrobuf_module):
    parser = Parser()

    env = Environment(loader=PackageLoader('pyrobuf.protobuf', 'templates'))
    templ_pxd = env.get_template('proto_pxd.tmpl')
    templ_pyx = env.get_template('proto_pyx.tmpl')

    dir_name = "pyrobuf/_" + pyrobuf_module

    os.makedirs(dir_name, exist_ok=True)

    if os.path.isdir(pyrobuf_module):
        for spec in glob.glob(os.path.join(pyrobuf_module, '*.proto')):
            generate(spec, dir_name, parser, templ_pxd, templ_pyx)

        _, name = os.path.split(pyrobuf_module)
        pyx = os.path.join(dir_name, '*.pyx')

    else:
        name, _ = os.path.splitext(os.path.basename(pyrobuf_module))
        if not name:
            print("not a .proto file")
            return

        generate(pyrobuf_module, dir_name, parser, templ_pxd, templ_pyx)

        pyx = os.path.join(dir_name, "%s_proto.pyx" % name)

    if dist.ext_modules is None:
        dist.ext_modules = []
    dist.ext_modules.extend(cythonize([pyx],
                            include_path=[os.path.join(HERE, 'src'), dir_name]))
dataset/ETHPy150Open appnexus/pyrobuf/pyrobuf/setuptools_ext.py/add_pyrobuf_module/original