def main(): """main cli entrypoint""" setuptools.setup( name='hashmap', version='0.1', description='hash tables and filters', author='jake wires', author_email='*****@*****.**', packages=setuptools.find_packages(exclude=['test.*']), install_requires=[ 'xxh', ], setup_requires=[ 'pytest-runner', 'pytest-pylint', 'pytest-flake8', ], tests_require=[ 'pytest', 'pylint', 'flake8', ], test_suite='setup.test_suite', ext_modules=Build.cythonize('hashmap/*.pyx'), )
def extension_modules(): if BUILD_WITH_CYTHON: plugin_sources = [os.path.join('grpc_tools', '_protoc_compiler.pyx')] else: plugin_sources = [os.path.join('grpc_tools', '_protoc_compiler.cpp')] plugin_sources += [ os.path.join('grpc_tools', 'main.cc'), os.path.join('grpc_root', 'src', 'compiler', 'python_generator.cc') ] + [os.path.join(CC_INCLUDE, cc_file) for cc_file in CC_FILES] plugin_ext = extension.Extension( name='grpc_tools._protoc_compiler', sources=plugin_sources, include_dirs=[ '.', 'grpc_root', os.path.join('grpc_root', 'include'), CC_INCLUDE, ], language='c++', define_macros=list(DEFINE_MACROS), extra_compile_args=list(EXTRA_COMPILE_ARGS), extra_link_args=list(EXTRA_LINK_ARGS), ) extensions = [plugin_ext] if BUILD_WITH_CYTHON: from Cython import Build return Build.cythonize(extensions) else: return extensions
def extension_modules(): if BUILD_WITH_CYTHON: plugin_sources = [os.path.join('grpc', 'tools', '_protoc_compiler.pyx')] else: plugin_sources = [os.path.join('grpc', 'tools', '_protoc_compiler.cpp')] plugin_sources += [ os.path.join('grpc', 'tools', 'main.cc'), os.path.join('grpc_root', 'src', 'compiler', 'python_generator.cc')] + [ os.path.join(CC_INCLUDE, cc_file) for cc_file in CC_FILES] plugin_ext = extension.Extension( name='grpc.tools._protoc_compiler', sources=plugin_sources, include_dirs=[ '.', 'grpc_root', os.path.join('grpc_root', 'include'), CC_INCLUDE, ], language='c++', define_macros=list(DEFINE_MACROS), extra_compile_args=list(EXTRA_COMPILE_ARGS), extra_link_args=list(EXTRA_LINK_ARGS), ) extensions = [plugin_ext] if BUILD_WITH_CYTHON: from Cython import Build return Build.cythonize(extensions) else: return extensions
def extension_modules(): if BUILD_WITH_CYTHON: plugin_sources = [os.path.join('grpc_tools', '_protoc_compiler.pyx')] else: plugin_sources = [os.path.join('grpc_tools', '_protoc_compiler.cpp')] plugin_sources += [ os.path.join('grpc_tools', 'main.cc'), os.path.join('grpc_root', 'src', 'compiler', 'python_generator.cc') ] #HACK: Substitute the embed.cc, which is a JS to C++ # preprocessor with the generated code. # The generated code should not be material # to the parts of protoc we use (it affects # the JavaScript code generator, supposedly), # but we need to be cautious about it. cc_files_clone = list(CC_FILES) embed_cc_file = os.path.normpath('google/protobuf/compiler/js/embed.cc') well_known_types_file = os.path.normpath( 'google/protobuf/compiler/js/well_known_types_embed.cc') if embed_cc_file in cc_files_clone: cc_files_clone.remove(embed_cc_file) if well_known_types_file in cc_files_clone: cc_files_clone.remove(well_known_types_file) plugin_sources += [ os.path.join('grpc_tools', 'protobuf_generated_well_known_types_embed.cc') ] plugin_sources += [ os.path.join(CC_INCLUDE, cc_file) for cc_file in cc_files_clone ] plugin_ext = extension.Extension( name='grpc_tools._protoc_compiler', sources=plugin_sources, include_dirs=[ '.', 'grpc_root', os.path.join('grpc_root', 'include'), CC_INCLUDE, ], language='c++', define_macros=list(DEFINE_MACROS), extra_compile_args=list(EXTRA_COMPILE_ARGS), extra_link_args=list(EXTRA_LINK_ARGS), ) extensions = [plugin_ext] if BUILD_WITH_CYTHON: from Cython import Build return Build.cythonize(extensions) else: return extensions
def compile_(self): """Translate cython code to C code and compile it.""" from Cython import Build argv = copy.deepcopy(sys.argv) sys.argv = [sys.argv[0], 'build_ext', '--build-lib=' + self.buildpath] exc_modules = [ distutils.extension.Extension('hydpy.cythons.autogen.' + self.cyname, [self.cyfilepath], extra_compile_args=['-O2']) ] distutils.core.setup(ext_modules=Build.cythonize(exc_modules), include_dirs=[numpy.get_include()]) sys.argv = argv
def main(): core.setup( ext_modules=Build.cythonize( # TODO: Use kwarg [ 'utils/proj_eul_math/combinatorics.py', 'utils/proj_eul_math/general.py', 'utils/proj_eul_math/lexical.py', 'utils/proj_eul_math/prime.py', ] + _get_all_run_problems( answer_dir=ANSWER_DIRECTORY, module_name=RUN_PROBLEM, ), include_path=[numpy.get_include()], compiler_directives={'language_level': 3}, ), include_dirs=[numpy.get_include()], )
def _load_module(self, module_path, define_macros, include_dirs, library_dirs, extra_compile_args, extra_link_args, libraries, code, lib_dir, module_name, runtime_library_dirs, compiler, key, sources): have_module = os.path.isfile(module_path) if not have_module: if define_macros is None: define_macros = [] if include_dirs is None: include_dirs = [] if library_dirs is None: library_dirs = [] if extra_compile_args is None: extra_compile_args = [] if extra_link_args is None: extra_link_args = [] if libraries is None: libraries = [] c_include_dirs = include_dirs if 'numpy' in code: import numpy c_include_dirs.append(numpy.get_include()) # TODO: We should probably have a special folder just for header # files that are shared between different codegen targets import brian2.synapses as synapses synapses_dir = os.path.dirname(synapses.__file__) c_include_dirs.append(synapses_dir) pyx_file = os.path.join(lib_dir, module_name + '.pyx') # ignore Python 3 unicode stuff for the moment #pyx_file = py3compat.cast_bytes_py2(pyx_file, encoding=sys.getfilesystemencoding()) #with io.open(pyx_file, 'w', encoding='utf-8') as f: # f.write(code) with open(pyx_file, 'w') as f: f.write(code) update_for_cross_compilation(library_dirs, extra_compile_args, extra_link_args, logger=logger) for source in sources: if not source.lower().endswith('.pyx'): raise ValueError('Additional Cython source files need to ' 'have an .pyx ending') # Copy source and header file (if present) to library directory shutil.copyfile( source, os.path.join(lib_dir, os.path.basename(source))) name_without_ext = os.path.splitext( os.path.basename(source))[0] header_name = name_without_ext + '.pxd' if os.path.exists( os.path.join(os.path.dirname(source), header_name)): shutil.copyfile( os.path.join(os.path.dirname(source), header_name), os.path.join(lib_dir, header_name)) final_sources = [ os.path.join(lib_dir, os.path.basename(source)) for source in sources ] extension = Extension(name=module_name, sources=[pyx_file], define_macros=define_macros, include_dirs=c_include_dirs, library_dirs=library_dirs, runtime_library_dirs=runtime_library_dirs, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, libraries=libraries, language='c++') build_extension = self._get_build_extension(compiler=compiler) try: opts = dict( quiet=True, annotate=False, force=True, ) # suppresses the output on stdout with std_silent(): build_extension.extensions = Cython_Build.cythonize( [extension] + final_sources, **opts) build_extension.build_temp = os.path.dirname(pyx_file) build_extension.build_lib = lib_dir build_extension.run() if prefs['codegen.runtime.cython.delete_source_files']: # we can delete the source files to save disk space cpp_file = os.path.join(lib_dir, module_name + '.cpp') try: os.remove(pyx_file) os.remove(cpp_file) temp_dir = os.path.join( lib_dir, os.path.dirname(pyx_file)[1:], module_name + '.*') for fname in glob.glob(temp_dir): os.remove(fname) except (OSError, IOError) as ex: logger.debug( 'Deleting Cython source files failed with error: %s' % str(ex)) except Cython_Compiler.Errors.CompileError: return # Temporarily insert the Cython directory to the Python path so that # code importing from an external module that was declared via # sources works sys.path.insert(0, lib_dir) spec = importlib.util.spec_from_file_location(module_name, module_path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) sys.path.pop(0) self._code_cache[key] = module return module
def _load_module(self, module_path, include_dirs, library_dirs, extra_compile_args, extra_link_args, libraries, code, lib_dir, module_name, runtime_library_dirs, compiler, key): have_module = os.path.isfile(module_path) if not have_module: if include_dirs is None: include_dirs = [] if library_dirs is None: library_dirs = [] if extra_compile_args is None: extra_compile_args = [] if extra_link_args is None: extra_link_args = [] if libraries is None: libraries = [] c_include_dirs = include_dirs if 'numpy' in code: import numpy c_include_dirs.append(numpy.get_include()) # TODO: We should probably have a special folder just for header # files that are shared between different codegen targets import brian2.synapses as synapses synapses_dir = os.path.dirname(synapses.__file__) c_include_dirs.append(synapses_dir) pyx_file = os.path.join(lib_dir, module_name + '.pyx') # ignore Python 3 unicode stuff for the moment #pyx_file = py3compat.cast_bytes_py2(pyx_file, encoding=sys.getfilesystemencoding()) #with io.open(pyx_file, 'w') as f:#, encoding='utf-8') as f: # f.write(code) open(pyx_file, 'w').write(code) if (platform.system() == 'Linux' and platform.architecture()[0] == '32bit' and platform.machine() == 'x86_64'): # We are cross-compiling to 32bit on a 64bit platform logger.info('Cross-compiling to 32bit on a 64bit platform, a set ' 'of standard compiler options will be appended for ' 'this purpose (note that you need to have a 32bit ' 'version of the standard library for this to work).', '64bit_to_32bit', once=True) library_dirs += ['/lib32', '/usr/lib32'] extra_compile_args += ['-m32'] extra_link_args += ['-m32'] extension = Extension( name=module_name, sources=[pyx_file], include_dirs=c_include_dirs, library_dirs=library_dirs, runtime_library_dirs=runtime_library_dirs, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, libraries=libraries, language='c++', ) build_extension = self._get_build_extension(compiler=compiler) try: opts = dict( quiet=True, annotate=False, force=True, ) # suppresses the output on stdout with std_silent(): build_extension.extensions = Cython_Build.cythonize([extension], **opts) build_extension.build_temp = os.path.dirname(pyx_file) build_extension.build_lib = lib_dir build_extension.run() except Cython_Compiler.Errors.CompileError: return module = imp.load_dynamic(module_name, module_path) self._code_cache[key] = module return module
def create_extension(self, code, force=False, name=None, include=None, library_dirs=None, compile_args=None, link_args=None, lib=None, ): if Cython is None: raise ImportError('Cython is not available') code = deindent(code) lib_dir = os.path.expanduser('~/.brian/cython_extensions') if not os.path.exists(lib_dir): os.makedirs(lib_dir) key = code, sys.version_info, sys.executable, Cython.__version__ if force: # Force a new module name by adding the current time to the # key which is hashed to determine the module name. key += time.time(), if key in self._code_cache: return self._code_cache[key] if name is not None: module_name = name#py3compat.unicode_to_str(args.name) else: module_name = "_cython_magic_" + hashlib.md5(str(key).encode('utf-8')).hexdigest() module_path = os.path.join(lib_dir, module_name + self.so_ext) have_module = os.path.isfile(module_path) if not have_module: if include is None: include = [] if library_dirs is None: library_dirs = [] if compile_args is None: compile_args = [] if link_args is None: link_args = [] if lib is None: lib = [] c_include_dirs = include if 'numpy' in code: import numpy c_include_dirs.append(numpy.get_include()) pyx_file = os.path.join(lib_dir, module_name + '.pyx') # ignore Python 3 unicode stuff for the moment #pyx_file = py3compat.cast_bytes_py2(pyx_file, encoding=sys.getfilesystemencoding()) #with io.open(pyx_file, 'w') as f:#, encoding='utf-8') as f: # f.write(code) open(pyx_file, 'w').write(code) extension = Extension( name=module_name, sources=[pyx_file], include_dirs=c_include_dirs, library_dirs=library_dirs, extra_compile_args=compile_args, extra_link_args=link_args, libraries=lib, language='c++', ) build_extension = self._get_build_extension() try: opts = dict( quiet=True, annotate=False, force=True, ) # suppresses the output on stdout with std_silent(): build_extension.extensions = Cython_Build.cythonize([extension], **opts) build_extension.build_temp = os.path.dirname(pyx_file) build_extension.build_lib = lib_dir build_extension.run() except Cython_Compiler.Errors.CompileError: return module = imp.load_dynamic(module_name, module_path) self._code_cache[key] = module return module
'You have an incompatible stl package installed' 'Please run "pip uninstall -y stl" first') sys.exit(1) except ImportError: pass if sys.version_info.major == 2 or sys.platform.lower() != 'win32': try: import numpy from Cython import Build setup_kwargs['ext_modules'] = Build.cythonize([ extension.Extension( 'stl._speedups', ['stl/_speedups.pyx'], include_dirs=[numpy.get_include()], ), ]) except ImportError: error('WARNING', 'Cython and Numpy is required for building extension.', 'Falling back to pure Python implementation.') # To prevent importing about and thereby breaking the coverage info we use this # exec hack about = {} with open('stl/__about__.py') as fh: exec(fh.read(), about)
def get_property(prop, project): result = re.search(r'{}\s*=\s*[\'"]([^\'"]*)[\'"]'.format(prop), open(project + '/__init__.py').read()) return result.group(1) extensions = [Extension( "radvel._kepler", ["src/_kepler.pyx"], )] reqs = [] for line in open('requirements.txt', 'r').readlines(): if not line.startswith('celerite'): reqs.append(line) setup(name="radvel", version=get_property('__version__', 'radvel'), author="BJ Fulton, Erik Petigura, Sarah Blunt", packages=find_packages(), ext_modules=cb.cythonize(extensions), include_dirs=[numpy.get_include()], data_files=[('radvel_example_data', [ 'example_data/164922_fixed.txt', 'example_data/epic203771098.csv', 'example_data/k2-131.txt' ])], entry_points={'console_scripts': ['radvel=radvel.cli:main']}, install_requires=reqs, include_package_data=True)
def _load_module(self, module_path, define_macros, include_dirs, library_dirs, extra_compile_args, extra_link_args, libraries, code, lib_dir, module_name, runtime_library_dirs, compiler, key): have_module = os.path.isfile(module_path) if not have_module: if define_macros is None: define_macros = [] if include_dirs is None: include_dirs = [] if library_dirs is None: library_dirs = [] if extra_compile_args is None: extra_compile_args = [] if extra_link_args is None: extra_link_args = [] if libraries is None: libraries = [] c_include_dirs = include_dirs if 'numpy' in code: import numpy c_include_dirs.append(numpy.get_include()) # TODO: We should probably have a special folder just for header # files that are shared between different codegen targets import brian2.synapses as synapses synapses_dir = os.path.dirname(synapses.__file__) c_include_dirs.append(synapses_dir) pyx_file = os.path.join(lib_dir, module_name + '.pyx') # ignore Python 3 unicode stuff for the moment #pyx_file = py3compat.cast_bytes_py2(pyx_file, encoding=sys.getfilesystemencoding()) #with io.open(pyx_file, 'w', encoding='utf-8') as f: # f.write(code) with open(pyx_file, 'w') as f: f.write(code) update_for_cross_compilation(library_dirs, extra_compile_args, extra_link_args, logger=logger) extension = Extension( name=module_name, sources=[pyx_file], define_macros=define_macros, include_dirs=c_include_dirs, library_dirs=library_dirs, runtime_library_dirs=runtime_library_dirs, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, libraries=libraries, language='c++', ) build_extension = self._get_build_extension(compiler=compiler) try: opts = dict( quiet=True, annotate=False, force=True, ) # suppresses the output on stdout with std_silent(): build_extension.extensions = Cython_Build.cythonize( [extension], **opts) build_extension.build_temp = os.path.dirname(pyx_file) build_extension.build_lib = lib_dir build_extension.run() except Cython_Compiler.Errors.CompileError: return module = imp.load_dynamic(module_name, module_path) self._code_cache[key] = module return module
def maybe_cythonize(exts): from Cython import Build return Build.cythonize(exts)
def _load_module(self, module_path, include_dirs, library_dirs, extra_compile_args, extra_link_args, libraries, code, lib_dir, module_name, runtime_library_dirs, compiler, key): have_module = os.path.isfile(module_path) if not have_module: if include_dirs is None: include_dirs = [] if library_dirs is None: library_dirs = [] if extra_compile_args is None: extra_compile_args = [] if extra_link_args is None: extra_link_args = [] if libraries is None: libraries = [] c_include_dirs = include_dirs if 'numpy' in code: import numpy c_include_dirs.append(numpy.get_include()) # TODO: We should probably have a special folder just for header # files that are shared between different codegen targets import brian2.synapses as synapses synapses_dir = os.path.dirname(synapses.__file__) c_include_dirs.append(synapses_dir) pyx_file = os.path.join(lib_dir, module_name + '.pyx') # ignore Python 3 unicode stuff for the moment #pyx_file = py3compat.cast_bytes_py2(pyx_file, encoding=sys.getfilesystemencoding()) #with io.open(pyx_file, 'w') as f:#, encoding='utf-8') as f: # f.write(code) open(pyx_file, 'w').write(code) extension = Extension( name=module_name, sources=[pyx_file], include_dirs=c_include_dirs, library_dirs=library_dirs, runtime_library_dirs=runtime_library_dirs, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, libraries=libraries, language='c++', ) build_extension = self._get_build_extension(compiler=compiler) try: opts = dict( quiet=True, annotate=False, force=True, ) # suppresses the output on stdout with std_silent(): build_extension.extensions = Cython_Build.cythonize([extension], **opts) build_extension.build_temp = os.path.dirname(pyx_file) build_extension.build_lib = lib_dir build_extension.run() except Cython_Compiler.Errors.CompileError: return module = imp.load_dynamic(module_name, module_path) self._code_cache[key] = module return module
import os import sys import warnings from setuptools import setup, extension from setuptools.command.build_ext import build_ext setup_kwargs = {} try: import numpy from Cython import Build setup_kwargs['ext_modules'] = Build.cythonize([ extension.Extension( 'stl._speedups', ['stl/_speedups.pyx'], include_dirs=[numpy.get_include()], ), ]) except ImportError: print('WARNING', file=sys.stderr) print('Cython and Numpy is required for building extension.', file=sys.stderr) print('Falling back to pure Python implementation.', file=sys.stderr) # To prevent importing about and thereby breaking the coverage info we use this # exec hack about = {} with open('stl/__about__.py') as fp: exec(fp.read(), about)
def _load_module(self, module_path, define_macros, include_dirs, library_dirs, extra_compile_args, extra_link_args, libraries, code, lib_dir, module_name, runtime_library_dirs, compiler, key, sources): have_module = os.path.isfile(module_path) if not have_module: if define_macros is None: define_macros = [] if include_dirs is None: include_dirs = [] if library_dirs is None: library_dirs = [] if extra_compile_args is None: extra_compile_args = [] if extra_link_args is None: extra_link_args = [] if libraries is None: libraries = [] c_include_dirs = include_dirs if 'numpy' in code: import numpy c_include_dirs.append(numpy.get_include()) # TODO: We should probably have a special folder just for header # files that are shared between different codegen targets import brian2.synapses as synapses synapses_dir = os.path.dirname(synapses.__file__) c_include_dirs.append(synapses_dir) pyx_file = os.path.join(lib_dir, module_name + '.pyx') # ignore Python 3 unicode stuff for the moment #pyx_file = py3compat.cast_bytes_py2(pyx_file, encoding=sys.getfilesystemencoding()) #with io.open(pyx_file, 'w', encoding='utf-8') as f: # f.write(code) with open(pyx_file, 'w') as f: f.write(code) update_for_cross_compilation(library_dirs, extra_compile_args, extra_link_args, logger=logger) for source in sources: if not source.lower().endswith('.pyx'): raise ValueError('Additional Cython source files need to ' 'have an .pyx ending') # Copy source and header file (if present) to library directory shutil.copyfile(source, os.path.join(lib_dir, os.path.basename(source))) name_without_ext = os.path.splitext(os.path.basename(source))[0] header_name = name_without_ext + '.pxd' if os.path.exists(os.path.join(os.path.dirname(source), header_name)): shutil.copyfile(os.path.join(os.path.dirname(source), header_name), os.path.join(lib_dir, header_name)) final_sources = [os.path.join(lib_dir, os.path.basename(source)) for source in sources] extension = Extension( name=module_name, sources=[pyx_file], define_macros=define_macros, include_dirs=c_include_dirs, library_dirs=library_dirs, runtime_library_dirs=runtime_library_dirs, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, libraries=libraries, language='c++') build_extension = self._get_build_extension(compiler=compiler) try: opts = dict( quiet=True, annotate=False, force=True, ) # suppresses the output on stdout with std_silent(): build_extension.extensions = Cython_Build.cythonize([extension] + final_sources, **opts) build_extension.build_temp = os.path.dirname(pyx_file) build_extension.build_lib = lib_dir build_extension.run() if prefs['codegen.runtime.cython.delete_source_files']: # we can delete the source files to save disk space cpp_file = os.path.join(lib_dir, module_name + '.cpp') try: os.remove(pyx_file) os.remove(cpp_file) temp_dir = os.path.join(lib_dir, os.path.dirname(pyx_file)[1:], module_name + '.*') for fname in glob.glob(temp_dir): os.remove(fname) except (OSError, IOError) as ex: logger.debug('Deleting Cython source files failed with error: %s' % str(ex)) except Cython_Compiler.Errors.CompileError: return # Temporarily insert the Cython directory to the Python path so that # code importing from an external module that was declared via # sources works sys.path.insert(0, lib_dir) module = imp.load_dynamic(module_name, module_path) sys.path.pop(0) self._code_cache[key] = module return module