How to use the cppimport.config function in cppimport

To help you get started, we’ve selected a few cppimport examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tbenthompson / cppimport / cppimport / importer.py View on Github external
def load_module(module_data):
    if hasattr(sys, 'getdlopenflags'):
        old_flags = sys.getdlopenflags()
        new_flags = old_flags | cppimport.config.rtld_flags
        sys.setdlopenflags(new_flags)
        _load_module(module_data)
        sys.setdlopenflags(old_flags)
    else:
        _load_module(module_data)
github tbenthompson / cppimport / cppimport / find.py View on Github external
def _find_module_cpppath(modulename, opt_in = False):
    modulepath_without_ext = modulename.replace('.', os.sep)
    moduledir = os.path.dirname(modulepath_without_ext + '.throwaway')
    matching_dirs = find_matching_path_dirs(moduledir)
    matching_dirs = [os.getcwd() if d == '' else d for d in matching_dirs]
    matching_dirs = [
        d if os.path.isabs(d) else os.path.join(os.getcwd(), d) for d in matching_dirs
    ]

    for ext in cppimport.config.file_exts:
        modulefilename = os.path.basename(modulepath_without_ext + ext)
        outfilename = find_file_in_folders(modulefilename, matching_dirs, opt_in)
        if outfilename is not None:
            return outfilename

    return None
github tbenthompson / cppimport / cppimport / importer.py View on Github external
def check_checksum(module_data):
    if cppimport.config.should_force_rebuild:
        return False
    if not cppimport.checksum.is_checksum_current(module_data):
        return False
    quiet_print("Matching checksum for " + module_data['filepath'] + " --> not compiling")
    return True
github tbenthompson / cppimport / cppimport / build_module.py View on Github external
sources = (
            module_data['extra_source_filepaths'] +
            [module_data['rendered_src_filepath']]
        ),
        include_dirs = module_data['abs_include_dirs'],
        extra_compile_args = cfg.get('extra_compile_args', []),
        extra_link_args = cfg.get('extra_link_args', []),
        library_dirs = module_data['abs_library_dirs'],
        libraries = cfg.get('libraries', [])
    )

    args = ['build_ext', '--inplace']
    args.append('--build-temp=' + build_path)
    args.append('--build-lib=' + build_path)

    if cppimport.config.quiet:
        args.append('-q')
    else:
        args.append('-v')

    setuptools_args = dict(
        name = full_module_name,
        ext_modules = [ext],
        script_args = args,
        cmdclass = {
            'build_ext': BuildImportCppExt
        }
    )

    # Monkey patch in the parallel compiler if requested.
    py33orgreater = sys.version_info[0] >= 3 and sys.version_info[1] >= 3
    parallelize = cfg.get('parallel') and py33orgreater
github tbenthompson / cppimport / cppimport / build_module.py View on Github external
name = full_module_name,
        ext_modules = [ext],
        script_args = args,
        cmdclass = {
            'build_ext': BuildImportCppExt
        }
    )

    # Monkey patch in the parallel compiler if requested.
    py33orgreater = sys.version_info[0] >= 3 and sys.version_info[1] >= 3
    parallelize = cfg.get('parallel') and py33orgreater
    if parallelize:
        old_compile = distutils.ccompiler.CCompiler.compile
        distutils.ccompiler.CCompiler.compile = parallel_compile

    if cppimport.config.quiet:
        with stdchannel_redirected("stdout"):
            with stdchannel_redirected("stderr"):
                setuptools.setup(**setuptools_args)
    else:
        setuptools.setup(**setuptools_args)

    # Remove the parallel compiler to not corrupt the outside environment.
    if parallelize:
        distutils.ccompiler.CCompiler.compile = old_compile

    shutil.rmtree(build_path)