Python Cython.Distutils 模块,build_ext() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用Cython.Distutils.build_ext()

项目:SMURFS-Superpixels    作者:imaluengo    | 项目源码 | 文件源码
def configuration(parent_package='', top_path=None):
    config = Configuration('smaxflow', parent_package, top_path,
                           cmdclass={'build_ext': build_ext})

    numpy_dirs = get_numpy_include_dirs()
    get_maxflow_source()

    files = ["graph.cpp", "maxflow.cpp"]
    files = [os.path.join(source_path, f) for f in files]
    files = ['_maxflow.pyx', 'smurfs_mf.cpp'] + files
    config.add_extension('_maxflow', sources=files, language='c++',
                         include_dirs=[source_path,
                                       get_numpy_include_dirs()],
                         library_dirs=[source_path],
                         extra_compile_args=["-fpermissive"],
                         extra_link_args=["-fpermissive"])

    return config
项目:SMURFS-Superpixels    作者:imaluengo    | 项目源码 | 文件源码
def configuration(parent_package='', top_path=None):
    config = Configuration('pysmurfs', parent_package, top_path,
                           cmdclass={'build_ext': build_ext})

    numpy_dirs = get_numpy_include_dirs()

    # Compile `_features.pyx`
    config.add_extension('_features', sources=['_features.pyx'],
                         include_dirs=numpy_dirs)

    # Compile `_split.pyx`
    config.add_extension('_split', sources=['_split.pyx'],
                         language='c++', include_dirs=numpy_dirs)

    # Compile `_relabel.pyx`
    config.add_extension('_merge', sources=['_merge.pyx'],
                         language='c++', include_dirs=numpy_dirs)

    return config
项目:spfeas    作者:jgrss    | 项目源码 | 文件源码
def setup_package():

    metadata = dict(name=spfeas_name,
                    maintainer=maintainer,
                    maintainer_email=maintainer_email,
                    description=description,
                    license=license_file,
                    version=__version__,
                    long_description=long_description,
                    author=author_file,
                    packages=get_packages(),
                    package_data=get_package_data(),
                    ext_modules=cythonize(get_pyx_list()),
                    include_dirs=[np.get_include()],
                    cmdclass=dict(build_ext=build_ext),
                    zip_safe=False,
                    download_url=git_url,
                    install_requires=required_packages,
                    entry_points=get_console_dict())

    setup(**metadata)
项目:zipline-chinese    作者:zhanghan1990    | 项目源码 | 文件源码
def __getitem__(self, key):
        if key != 'build_ext':
            return super(LazyBuildExtCommandClass, self).__getitem__(key)

        from Cython.Distutils import build_ext as cython_build_ext
        import numpy

        # Cython_build_ext isn't a new-style class in Py2.
        class build_ext(cython_build_ext, object):
            """
            Custom build_ext command that lazily adds numpy's include_dir to
            extensions.
            """
            def build_extensions(self):
                """
                Lazily append numpy's include directory to Extension includes.

                This is done here rather than at module scope because setup.py
                may be run before numpy has been installed, in which case
                importing numpy and calling `numpy.get_include()` will fail.
                """
                numpy_incl = numpy.get_include()
                for ext in self.extensions:
                    ext.include_dirs.append(numpy_incl)

                super(build_ext, self).build_extensions()
        return build_ext
项目:catalyst    作者:enigmampc    | 项目源码 | 文件源码
def __getitem__(self, key):
        if key != 'build_ext':
            return super(LazyBuildExtCommandClass, self).__getitem__(key)

        from Cython.Distutils import build_ext as cython_build_ext
        import numpy

        # Cython_build_ext isn't a new-style class in Py2.
        class build_ext(cython_build_ext, object):
            """
            Custom build_ext command that lazily adds numpy's include_dir to
            extensions.
            """

            def build_extensions(self):
                """
                Lazily append numpy's include directory to Extension includes.

                This is done here rather than at module scope because setup.py
                may be run before numpy has been installed, in which case
                importing numpy and calling `numpy.get_include()` will fail.
                """
                numpy_incl = numpy.get_include()
                for ext in self.extensions:
                    ext.include_dirs.append(numpy_incl)

                super(build_ext, self).build_extensions()

        return build_ext
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def command(self):
        command = [sys.executable, "setup.py", "build_ext", "--inplace"]
        return command
项目:vizgen    作者:uva-graphics    | 项目源码 | 文件源码
def compile_c_single_file(filename, vectorize=True):
    """
    Compile C source (excluding .c extension) in place to module.
    """
    c_filename = filename + '.c'

    # this is a temporary hack to force the use of GCC instead of clang
    if os.path.isfile("/usr/local/bin/gcc-5"):
        print("using gcc-5 compiler from homebrew...")
        os.environ["CC"] = os.environ["CXX"] = "gcc-5"
    else:
        os.environ["CC"] = os.environ["CXX"] = "gcc"

    if os.name == 'nt':
        extension = [
            Extension(
                filename,
                sources = [c_filename],
                include_dirs = [numpy.get_include()],
                extra_compile_args = '-openmp'.split(),
                extra_link_args = '-openmp'.split()
            )
        ]

    else:
        extension = [
            Extension(
                filename,
                sources = [c_filename],
                include_dirs = [numpy.get_include()],
                extra_compile_args = '-w -fopenmp'.split() + (['-fno-tree-vectorize'] if not vectorize else []),
                extra_link_args = '-fopenmp'.split()
            )
        ]

    setup(
        name = filename,
        cmdclass = {'build_ext' : build_ext}, 
        include_dirs = [numpy.get_include()],
        ext_modules = extension,
        script_args='build_ext --inplace'.split()
    )