def cython(pyx_files, working_path=''): """Use Cython to convert the given files to C. Parameters ---------- pyx_files : list of str The input .pyx files. """ # Do not build cython files if target is clean if len(sys.argv) >= 2 and sys.argv[1] == 'clean': return try: from Cython.Build import cythonize except ImportError: # If cython is not found, we do nothing -- the build will make use of # the distributed .c files print("Cython not found; falling back to pre-built %s" \ % " ".join([f.replace('.pyx', '.c') for f in pyx_files])) else: for pyxfile in [os.path.join(working_path, f) for f in pyx_files]: # if the .pyx file stayed the same, we don't need to recompile if not _changed(pyxfile): continue cythonize(pyxfile)
def _setup_extensions(self): # We defer extension setup until this command to leveraage 'setup_requires' pulling in Cython before we # attempt to import anything self.extensions = [] if try_murmur3: self.extensions.append(murmur3_ext) if try_libev: self.extensions.append(libev_ext) if try_cython: try: from Cython.Build import cythonize cython_candidates = ['cluster', 'concurrent', 'connection', 'cqltypes', 'metadata', 'pool', 'protocol', 'query', 'util'] compile_args = [] if is_windows else ['-Wno-unused-function'] self.extensions.extend(cythonize( [Extension('cassandra.%s' % m, ['cassandra/%s.py' % m], extra_compile_args=compile_args) for m in cython_candidates], nthreads=build_concurrency, exclude_failures=True)) self.extensions.extend(cythonize(NoPatchExtension("*", ["cassandra/*.pyx"], extra_compile_args=compile_args), nthreads=build_concurrency)) except Exception: sys.stderr.write("Failed to cythonize one or more modules. These will not be compiled as extensions (optional).\n")
def run(self): from Cython.Build import cythonize from _ExtMaker.GlobalMaker import Maker def regenApi(api, version): stuff = Maker(glazeAbsPath, specsAbsPath, gladAbsPath, api, {api: version}, self.announce, self.extensions, self.profile, self.force_spec_dl) stuff.create() for api in self.apis: regenApi(api, self.versions.get(api)) cythonizables = [] for file in os.listdir(glazeAbsPath): file = os.path.join(glazeAbsPath, file) if os.path.splitext(file)[1] == '.pyx': cythonizables.append(file) if not os.path.isfile(file) and os.path.basename(file) != 'glad': for file2 in os.listdir(file): file2 = os.path.join(file, file2) if os.path.isfile(file2): if os.path.splitext(file2)[1] == '.pyx': cythonizables.append(file2) cythonize(cythonizables, language='c++', # compile_time_env={'LIBRARY': b'default'}, nthreads=self.jobs, ) self.announce('Done. Now you can build_ext / install / develop', log.INFO)
def do_setup(cython=False): if 'USE_CYTHON' in os.environ: if os.environ['USE_CYTHON'] == "false": cython = False packages = ['freeze'] if cython: print("Installing with cython\n") from Cython.Build import cythonize if version > 2: ext_modules = cythonize([ "freeze/xfreeze.py", "freeze/fpprint.py", ]) else: ext_modules = cythonize([ "freeze/xfreeze.py", ]) else: print("Installing without cython\n") ext_modules = [] setup( name = "freeze", version = __version__, packages = packages, ext_modules = ext_modules, install_requires = ['six'], author = "Adfinis-SyGroup", author_email = "https://adfinis-sygroup.ch/", description = "Freeze - dump / hash / sort / compare / diff anything", long_description = """ Freeze the state of data-structures and objects for data-analysis or testing (diffing data-structures). Frozen data-structures consist of only tuples and these are comparable/sortable/hashable. The freeze() function can be used for many purposes for example implement __hash__() for your complex object very fast. dump() is intended for testing and analysis.""", keywords = "freeze state hash sort compare unittest", url = "https://github.com/adfinis-sygroup/freeze", classifiers = [ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Education", "Intended Audience :: Information Technology", "License :: OSI Approved :: " "GNU Affero General Public License v3", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development :: Libraries", "Topic :: Scientific/Engineering :: Information Analysis", "Topic :: Software Development :: Testing", ] )
def check_extensions(): #Cythonize main modules ext_list = cythonize(["assimulo"+O.path.sep+"*.pyx"], include_path=[".","assimulo"],include_dirs=[N.get_include()],pyrex_gdb=debug) #Cythonize Euler ext_list = ext_list + cythonize(["assimulo"+O.path.sep+"solvers"+O.path.sep+"euler.pyx"], include_path=[".","assimulo"],include_dirs=[N.get_include()],pyrex_gdb=debug) for i in ext_list: i.include_dirs = [N.get_include()] #Debug if debug: i.extra_compile_args = ["-g","-fno-strict-aliasing"] i.extra_link_args = ["-g"] else: i.extra_compile_args = ["-O2", "-fno-strict-aliasing"] #If Sundials if O.path.exists(O.path.join(O.path.join(incdirs,'cvodes'), 'cvodes.h')): ext_list = ext_list + cythonize(["assimulo"+O.path.sep+"solvers"+O.path.sep+"sundials.pyx"], include_path=[".","assimulo","assimulo"+O.sep+"lib"],include_dirs=[N.get_include()],pyrex_gdb=debug) ext_list[-1].include_dirs = [N.get_include(), "assimulo","assimulo"+O.sep+"lib", incdirs] ext_list[-1].library_dirs = [libdirs] ext_list[-1].extra_link_args = ["-lsundials_cvodes", "-lsundials_nvecserial", "-lsundials_idas"] if debug: ext_list[-1].extra_compile_args = ["-g", "-fno-strict-aliasing"] else: ext_list[-1].extra_compile_args = ["-O2", "-fno-strict-aliasing"] #Sundials found if O.path.exists(O.path.join(O.path.join(incdirs,'cvodes'), 'cvodes.h')): cordir = O.path.join(O.path.join('assimulo','lib'),'sundials_core.pyx') cordir_KINSOL_wSLU = O.path.join(O.path.join('assimulo','lib'),'sundials_kinsol_core_wSLU.pyx') cordir_KINSOL = O.path.join(O.path.join('assimulo','lib'),'sundials_kinsol_core.pyx') cordir_KINSOL_jmod_wSLU = O.path.join(O.path.join('assimulo','lib'),'kinsol_jmod_wSLU.c') cordir_KINSOL_jmod = O.path.join(O.path.join('assimulo','lib'),'kinsol_jmod.c') cordir_kinpinv = O.path.join(O.path.join('assimulo','lib'),'kinpinv.c') cordir_kinslug = O.path.join(O.path.join('assimulo','lib'),'kinslug.c') cordir_reg_routines = O.path.join(O.path.join('assimulo','lib'),'reg_routines.c') wSLU = check_wSLU() if wSLU: SLUincdir = O.path.join(SLUdir,'SRC') SLUlibdir = O.path.join(SLUdir,'lib') ext_list = ext_list + [Extension('assimulo.lib.sundials_kinsol_core_wSLU', [cordir_KINSOL_wSLU,cordir_KINSOL_jmod_wSLU,cordir_kinpinv,cordir_kinslug,cordir_reg_routines], include_dirs=[incdirs, N.get_include(),SLUincdir], library_dirs=[libdirs,SLUlibdir,BLASdir], libraries=['sundials_kinsol','sundials_nvecserial','superlu_4.1',BLASname])] else: ext_list = ext_list + [Extension('assimulo.lib.sundials_kinsol_core', [cordir_KINSOL,cordir_KINSOL_jmod,cordir_kinpinv], include_dirs=[incdirs, N.get_include()], library_dirs=[libdirs], libraries=['sundials_kinsol','sundials_nvecserial'])] return ext_list
def run(self): # this is already imported, but the import might have failed. If so, raise an ImportError now. from Cython.Build import cythonize # Make sure the compiled Cython files in the distribution are up-to-date cythonize(['voropy/_voro.pyx']) _sdist.run(self)
def my_cythonize(extensions, **_ignore): #newextensions = [] for extension in extensions: print(extension.sources) should_cythonize = False sources = [] for sfile in extension.sources: path, ext = os.path.splitext(sfile) if ext in ('.pyx', '.py'): should_cythonize = True if not cython_present: # if extension.language == 'c++': ext = '.cpp' #else: # ext = '.c' if sfile == 'PyDeepCL.c': ext = '.cpp' # hack for now... not sure how to fix this cleanly # yet sfile = path + ext if sfile.startswith('..'): # use mysrc instead basename = os.path.basename(sfile) sfile = 'mysrc/' + basename sources.append(sfile) #print(should_cythonize) if should_cythonize and cython_present: print('cythonizing...') cythonize(extension) extension.sources[:] = sources #newextensions.append( extension ) return extensions
def compile_cython(self): global cython_sources try: from Cython.Build import cythonize cythonize(cython_sources) except ImportError: pass
def cython(pyx_files, working_path=''): """Use Cython to convert the given files to C. Parameters ---------- pyx_files : list of str The input .pyx files. """ # Do not build cython files if target is clean if len(sys.argv) >= 2 and sys.argv[1] == 'clean': return try: from Cython.Build import cythonize except ImportError: raise ImportError("Cython not found.") else: for pyxfile in [os.path.join(working_path, f) for f in pyx_files]: # if the .pyx file stayed the same, we don't need to recompile if not _changed(pyxfile): continue cythonize(pyxfile)
def run(self): cythonize( ext_cython_modules, include_path=cython_include_path, force=(not self.timestamps), annotate=self.annotate, compiler_directives=self.directive )
def run(self): # Make sure the compiled Cython files in the distribution are up-to-date from Cython.Build import cythonize cythonize(['_pysndfile.pyx']) shutil.move("setup.cfg", "setup.cfg.default") shutil.copy2("setup.cfg.dist", "setup.cfg") sdist.run(self) shutil.move("setup.cfg.default", "setup.cfg")
def cythonize_extensions(self): from Cython.Build import cythonize cythonize( self.extensions, compiler_directives={'embedsignature': True, 'language_level': 3}, force=True )
def run(self): from Cython.Build import cythonize for ext in self.distribution.ext_modules: sources = list(s for s in ext.sources if s.endswith('.pyx')) cythonize(sources) sdist_.run(self)
def run(self): import Cython from Cython.Build import cythonize assert float(Cython.__version__) >= 0.22 cythonize(define_extensions('.pyx'))
def cythonize_wrapper(modules, **kwargs): """ Calls cythonize, filtering useless warnings """ if not modules: return with CythonFilter() as cython_filter: with redirect_stdout(cython_filter): cythonize(modules, **kwargs)
def run(self): try: from Cython.Build import cythonize cythonize(os.path.join('pyhsmm','**','*.pyx')) except: warn('Failed to generate extension files from Cython sources') finally: _sdist.run(self)
def run(self): cythonize(extensions) for ext in extensions: for src in ext.sources: if not os.path.exists(src): raise Exception( "Cython-generated file '{0}' not found. " "Run 'python setup.py --usage' for details.".format(src, usage)) sdist.run(self)
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('models', parent_package, top_path) include = os.path.join(get_python_lib(), 'compmech', 'include') lib = os.path.join(get_python_lib(), 'compmech', 'lib') if os.name == 'nt': runtime_library_dirs = None if os.environ.get('CONDA_DEFAULT_ENV') is not None: #NOTE removing openmp to compile in MiniConda args_linear = ['-O0'] args_nonlinear = ['-O0'] else: args_linear = ['/openmp'] args_nonlinear = ['/openmp', '/fp:fast'] else: runtime_library_dirs = [lib] if os.environ.get('CONDA_DEFAULT_ENV') is not None: #NOTE removing openmp to compile in MiniConda args_linear = ['-O0'] args_nonlinear = ['-O0'] else: args_linear = ['-fopenmp'] args_nonlinear = ['-fopenmp', '-ffast-math'] config.add_extension('bladestiff1d_clt_donnell_bardell', ['bladestiff1d_clt_donnell_bardell.pyx'], extra_compile_args=args_linear, runtime_library_dirs=runtime_library_dirs, include_dirs=[include], libraries=['bardell_functions', 'bardell'], library_dirs=[lib]) config.add_extension('bladestiff2d_clt_donnell_bardell', ['bladestiff2d_clt_donnell_bardell.pyx'], extra_compile_args=args_linear, runtime_library_dirs=runtime_library_dirs, include_dirs=[include], libraries=['bardell_functions', 'bardell'], library_dirs=[lib]) config.add_extension('tstiff2d_clt_donnell_bardell', ['tstiff2d_clt_donnell_bardell.pyx'], extra_compile_args=args_linear, runtime_library_dirs=runtime_library_dirs, include_dirs=[include], libraries=['bardell_functions', 'bardell', 'bardell_12', 'bardell_c0c1'], library_dirs=[lib]) cythonize(config.ext_modules) config.make_config_py() return config
def run(self): from Cython.Build import cythonize self.generate_pyx() cythonize([Extension("lightfm._lightfm_fast_no_openmp", ['lightfm/_lightfm_fast_no_openmp.pyx']), Extension("lightfm._lightfm_fast_openmp", ['lightfm/_lightfm_fast_openmp.pyx'], extra_link_args=['-fopenmp'])])
def compile_pyx(): ext_modules = list() cparser = cythonize('pyrox/http/parser.pyx')[0] cparser.sources.insert(0, 'include/http_el.c') ext_modules.append(cparser) ext_modules.extend(cythonize('pyrox/http/model_util.pyx')) return ext_modules
def run(self): try: from Cython.Build import cythonize cythonize([ module.replace('.', '/') + '.pyx' for module in cython_modules ]) except ImportError: pass _sdist.run(self)
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('science_features', parent_package, top_path) cythonize(os.path.join(base_path, '_lomb_scargle.pyx')) config.add_extension('_lomb_scargle', '_lomb_scargle.c', include_dirs=[np.get_include()]) return config
def run(self): build_ext = self.reinitialize_command('build_ext') build_ext.ensure_finalized() # generate cython extensions if any exist extensions = list(cython_pyx()) if extensions: from Cython.Build import cythonize cythonize(extensions, nthreads=cpu_count()) dst_sdist.sdist.run(self)
def cythonize_cpp_wrapper(modules, nthreads): """ Calls cythonize, filtering useless warnings """ from Cython.Build import cythonize from contextlib import redirect_stdout if not modules: return with CythonFilter() as cython_filter: with redirect_stdout(cython_filter): cythonize(modules, language='c++', nthreads=nthreads)
def run(self): # only run if .git is present if not os.path.exists('.git'): return try: from Cython.Build import cythonize cythonize(extensions()) except ImportError: warnings.warn('at sdist cythonize failed') return versioneer.cmd_sdist.run(self)
def run(self): build_ext = self.reinitialize_command('build_ext') build_ext.ensure_finalized() # generate cython extensions if any exist cython = any( os.path.splitext(f)[1] == '.pyx' for e in build_ext.extensions for f in e.sources) if cython: from Cython.Build import cythonize cythonize(build_ext.extensions) dst_sdist.sdist.run(self)
def run(self): # ensure that the platform checks were performed self.run_command('config') # only regenerate cython extensions if requested or required use_cython = ( os.environ.get('USE_CYTHON', False) or any(not os.path.exists(x) for ext in self.no_cythonize() for x in ext.sources)) if use_cython: from Cython.Build import cythonize cythonize(self.extensions, nthreads=cpu_count()) self.extensions = self.no_cythonize() return dst_build_ext.build_ext.run(self)
def finalize_options(self): from Cython.Build import cythonize self.distribution.ext_modules[:] = cythonize( self.distribution.ext_modules, compiler_directives={'embedsignature': True}, ) _build_ext.finalize_options(self)
def get_extensions(): from distutils.extension import Extension common_extension_args = { 'include_dirs': get_include_dirs(), 'library_dirs': get_library_dirs(), 'libraries': get_libraries()} try: from Cython.Build import cythonize sources = [os.path.join(os.getcwd(), 'pyfftw', 'pyfftw.pyx')] have_cython = True except ImportError as e: # no cython sources = [os.path.join(os.getcwd(), 'pyfftw', 'pyfftw.c')] if not os.path.exists(sources[0]): raise ImportError( str(e) + '. ' + 'Cython is required to build the initial .c file.') have_cython = False ext_modules = [ Extension('pyfftw.pyfftw', sources=sources, **common_extension_args)] if have_cython: return cythonize(ext_modules) else: return ext_modules
def configuration(parent_package='',top_path=None): from numpy.distutils.misc_util import Configuration if os.name == 'nt': if os.environ.get('CONDA_DEFAULT_ENV') is not None: #NOTE removing openmp to compile in MiniConda compile_args = [] else: compile_args = ['/openmp'] else: if os.environ.get('CONDA_DEFAULT_ENV') is not None: #NOTE removing openmp to compile in MiniConda compile_args = [] else: compile_args = ['-fopenmp'] config = Configuration('imperfections', parent_package, top_path) config.add_extension('mgi', sources=['mgi.pyx'], ) cythonize(config.ext_modules) config.make_config_py() return config