def build_extensions(self): for _pxifile in _pxifiles: # build pxifiles first, template extention must be .pxi.in assert _pxifile.endswith(".pxi.in") pxifile = pjoin(_pxipath, _pxifile) outfile = pxifile[:-3] if os.path.exists(outfile) and os.stat(pxifile).st_mtime < os.stat(outfile).st_mtime: # if .pxi.in is not updated, no need to output .pxi continue with open(pxifile, "r") as f: tmpl = f.read() pyxcontent = tempita.sub(tmpl) with open(outfile, "w") as f: f.write(pyxcontent) numpy_incl = pkg_resources.resource_filename("numpy", "core/include") for ext in self.extensions: if hasattr(ext, "include_dirs") and not numpy_incl in ext.include_dirs: ext.include_dirs.append(numpy_incl) _build_ext.build_extensions(self)
def build_extensions(self): # if builing from c files, don't need to # generate template output if cython: for pxifile in _pxifiles: # build pxifiles first, template extension must be .pxi.in assert pxifile.endswith('.pxi.in') outfile = pxifile[:-3] if (os.path.exists(outfile) and os.stat(pxifile).st_mtime < os.stat(outfile).st_mtime): # if .pxi.in is not updated, no need to output .pxi continue with open(pxifile, "r") as f: tmpl = f.read() pyxcontent = tempita.sub(tmpl) with open(outfile, "w") as f: f.write(pyxcontent) numpy_incl = pkg_resources.resource_filename('numpy', 'core/include') for ext in self.extensions: if (hasattr(ext, 'include_dirs') and numpy_incl not in ext.include_dirs): ext.include_dirs.append(numpy_incl) _build_ext.build_extensions(self)
def process_tempita_pyx(fromfile, tofile): try: try: from Cython import Tempita as tempita except ImportError: import tempita except ImportError: raise Exception("Building Statsmodels requires Tempita: " "pip install --user Tempita") with open(fromfile, "r") as f: tmpl = f.read() pyxcontent = tempita.sub(tmpl) assert fromfile.endswith(".pyx.in") pyxfile = fromfile[: -len(".pyx.in")] + ".pyx" with open(pyxfile, "w") as f: f.write(pyxcontent) process_pyx(pyxfile, tofile)
def process_tempita_pxi(fromfile, tofile): try: try: from Cython import Tempita as tempita except ImportError: import tempita except ImportError: raise Exception('Building %s requires Tempita: ' 'pip install --user Tempita' % VENDOR) assert fromfile.endswith('.pxi.in') assert tofile.endswith('.pxi') with open(fromfile, "r") as f: tmpl = f.read() pyxcontent = tempita.sub(tmpl) with open(tofile, "w") as f: f.write(pyxcontent)
def process_tempita_pyx(fromfile, tofile): try: try: from Cython import Tempita as tempita except ImportError: import tempita except ImportError: raise Exception('Building DismalPy requires Tempita: ' 'pip install --user Tempita') with open(fromfile, "r") as f: tmpl = f.read() pyxcontent = tempita.sub(tmpl) assert fromfile.endswith('.pyx.in') pyxfile = fromfile[:-len('.pyx.in')] + '.pyx' with open(pyxfile, "w") as f: f.write(pyxcontent) process_pyx(pyxfile, tofile)
def render_templates(cls, pxifiles): for pxifile in pxifiles: # build pxifiles first, template extension must be .pxi.in assert pxifile.endswith('.pxi.in') outfile = pxifile[:-3] if (os.path.exists(outfile) and os.stat(pxifile).st_mtime < os.stat(outfile).st_mtime): # if .pxi.in is not updated, no need to output .pxi continue with open(pxifile, "r") as f: tmpl = f.read() pyxcontent = tempita.sub(tmpl) with open(outfile, "w") as f: f.write(pyxcontent)
def process_tempita(source_name): """Runs pyx.in files through tempita is needed""" if source_name.endswith('pyx.in'): with open(source_name, 'r') as templated: pyx_template = templated.read() pyx = Tempita.sub(pyx_template) pyx_filename = source_name[:-3] with open(pyx_filename, 'w') as pyx_file: pyx_file.write(pyx) file_stats = os.stat(source_name) try: os.utime(pyx_filename, ns=(file_stats.st_atime_ns, file_stats.st_mtime_ns)) except AttributeError: os.utime(pyx_filename, (file_stats.st_atime, file_stats.st_mtime)) source_name = pyx_filename return source_name
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('linear_model', parent_package, top_path) libraries = [] if os.name == 'posix': libraries.append('m') config.add_extension('cd_fast', sources=['cd_fast.pyx'], include_dirs=numpy.get_include(), libraries=libraries) config.add_extension('sgd_fast', sources=['sgd_fast.pyx'], include_dirs=numpy.get_include(), libraries=libraries) config.add_extension('proj_sgd_fast', sources=['proj_sgd_fast.pyx'], include_dirs=numpy.get_include(), libraries=libraries) # generate sag_fast from template sag_cython_file = 'sklearn/linear_model/sag_fast.pyx.tp' sag_file = sag_cython_file.replace('.tp', '') if not (os.path.exists(sag_file) and os.stat(sag_cython_file).st_mtime < os.stat(sag_file).st_mtime): with open(sag_cython_file, "r") as f: tmpl = f.read() tmpl_ = Tempita.sub(tmpl) with open(sag_file, "w") as f: f.write(tmpl_) config.add_extension('sag_fast', sources=['sag_fast.pyx'], include_dirs=numpy.get_include()) # add other directories config.add_subpackage('tests') return config
def process_tempita_pyx(fromfile, tofile, cwd): try: try: from Cython import Tempita as tempita except ImportError: import tempita except ImportError as e: raise Exception('Building SciPy requires Tempita: ' 'pip install --user Tempita') from e with open(os.path.join(cwd, fromfile), mode='r') as f_in: template = f_in.read() pyxcontent = tempita.sub(template) assert fromfile.endswith('.pyx.in') pyxfile = fromfile[:-len('.in')] with open(os.path.join(cwd, pyxfile), "w", encoding='utf8') as f_out: f_out.write(pyxcontent) process_pyx(pyxfile, tofile, cwd)
def gen_from_templates(templates, top_path): """Generate cython files from a list of templates""" # Lazy import because cython is not a runtime dependency. from Cython import Tempita for template in templates: outfile = template.replace('.tp', '') # if the template is not updated, no need to output the cython file if not (os.path.exists(outfile) and os.stat(template).st_mtime < os.stat(outfile).st_mtime): with open(template, "r") as f: tmpl = f.read() tmpl_ = Tempita.sub(tmpl) with open(outfile, "w") as f: f.write(tmpl_)
def generate_code(templates): """Generate code from template files""" for template in templates: # template extention must be .in assert template.endswith('.in') outfile = template[:-3] if (os.path.exists(outfile) and (not os.path.exists(template) or os.stat(template).st_mtime < os.stat(outfile).st_mtime)): # If output is present but template isn't, or if template is not # updated no need to generate continue with open(template, "r") as f: tmpl = f.read() output = tempita.sub(tmpl) with open(outfile, "w") as f: f.write(output)
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('linear_model', parent_package, top_path) libraries = [] if os.name == 'posix': libraries.append('m') config.add_extension('cd_fast', sources=['cd_fast.pyx'], include_dirs=numpy.get_include(), libraries=libraries) config.add_extension('sgd_fast', sources=['sgd_fast.pyx'], include_dirs=numpy.get_include(), libraries=libraries) # generate sag_fast from template sag_cython_file = 'sklearn/linear_model/sag_fast.pyx.tp' sag_file = sag_cython_file.replace('.tp', '') if not (os.path.exists(sag_file) and os.stat(sag_cython_file).st_mtime < os.stat(sag_file).st_mtime): with open(sag_cython_file, "r") as f: tmpl = f.read() tmpl_ = Tempita.sub(tmpl) with open(sag_file, "w") as f: f.write(tmpl_) config.add_extension('sag_fast', sources=['sag_fast.pyx'], include_dirs=numpy.get_include()) # add other directories config.add_subpackage('tests') return config
def configuration(parent_package='', top_path=None): import numpy from numpy.distutils.misc_util import Configuration from Cython import Tempita config = Configuration('utils', parent_package, top_path) libraries = [] if os.name == 'posix': libraries.append('m') config.add_extension('sparsefuncs_fast', sources=['sparsefuncs_fast.pyx'], libraries=libraries) config.add_extension('_cython_blas', sources=['_cython_blas.pyx'], libraries=libraries) config.add_extension('arrayfuncs', sources=['arrayfuncs.pyx'], include_dirs=[numpy.get_include()], libraries=libraries) config.add_extension( 'murmurhash', sources=['murmurhash.pyx', join('src', 'MurmurHash3.cpp')], include_dirs=['src']) config.add_extension('graph_shortest_path', sources=['graph_shortest_path.pyx'], include_dirs=[numpy.get_include()]) config.add_extension('fast_dict', sources=['fast_dict.pyx'], language="c++", include_dirs=[numpy.get_include()], libraries=libraries) # generate files from a template pyx_templates = [ 'sklearn/utils/seq_dataset.pyx.tp', 'sklearn/utils/seq_dataset.pxd.tp' ] for pyxfiles in pyx_templates: outfile = pyxfiles.replace('.tp', '') # if .pyx.tp is not updated, no need to output .pyx if (os.path.exists(outfile) and os.stat(pyxfiles).st_mtime < os.stat(outfile).st_mtime): continue with open(pyxfiles, "r") as f: tmpl = f.read() pyxcontent = Tempita.sub(tmpl) with open(outfile, "w") as f: f.write(pyxcontent) config.add_extension('seq_dataset', sources=['seq_dataset.pyx'], include_dirs=[numpy.get_include()]) config.add_extension('weight_vector', sources=['weight_vector.pyx'], include_dirs=[numpy.get_include()], libraries=libraries) config.add_extension("_random", sources=["_random.pyx"], include_dirs=[numpy.get_include()], libraries=libraries) config.add_extension("_logistic_sigmoid", sources=["_logistic_sigmoid.pyx"], include_dirs=[numpy.get_include()], libraries=libraries) config.add_subpackage('tests') return config
from Cython.Build import cythonize rngs = [ 'RNG_PCG32', 'RNG_PCG64', 'RNG_MT19937', 'RNG_XORSHIFT128', 'RNG_XORSHIFT1024', 'RNG_MRG32K3A', 'RNG_MLFG_1279_861' ] files = glob.glob('./*.in') for templated_file in files: output_file_name = os.path.splitext(templated_file)[0] if os.path.exists(output_file_name): if os.path.getmtime(templated_file) < os.path.getmtime( output_file_name): continue with open(templated_file, 'r') as source_file: template = tempita.Template(source_file.read()) with open(output_file_name, 'w') as output_file: output_file.write(template.substitute()) with open('config.pxi', 'w') as config: config.write('# Autogenerated\n\n') config.write("DEF RS_RNG_MOD_NAME='mt19937'\n") pwd = getcwd() sources = [ join(pwd, 'randomstate.pyx'), join(pwd, 'src', 'common', 'entropy.c'), join(pwd, 'distributions.c') ]
try: from Cython import Tempita as tempita except ImportError: import tempita except ImportError: notempita_msg = ("# tempita needed to finish setup. run:\n\n" + " $ pip install tempita # or easy_install tempita\n") sys.exit(notempita_msg) # DOC: Tempita create pyx files code_cdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "affine") for folder, subdirs, files in os.walk(code_cdir): for fil in files: if fil.endswith(".pyx.in"): with open(os.path.join(folder, fil), "r") as f: cython_file = tempita.sub(f.read()) with open(os.path.join(folder, os.path.splitext(fil)[0]), "w") as f: f.write(cython_file) extensions = [ Extension('affine.model.Cython_extensions', ['affine/extensions/Cython_extensions.pyx']) ] setup( name='affine', author='Barton Baker', version='0.3', packages=find_packages(), description='This package offers a solver class for affine ' \
def configuration(parent_package='', top_path=None): import numpy from numpy.distutils.misc_util import Configuration from Cython import Tempita config = Configuration('utils', parent_package, top_path) libraries = [] if os.name == 'posix': libraries.append('m') config.add_extension('sparsefuncs_fast', sources=['sparsefuncs_fast.pyx'], libraries=libraries) config.add_extension('_cython_blas', sources=['_cython_blas.pyx'], libraries=libraries) config.add_extension('arrayfuncs', sources=['arrayfuncs.pyx'], include_dirs=[numpy.get_include()], libraries=libraries) config.add_extension('murmurhash', sources=['murmurhash.pyx', join( 'src', 'MurmurHash3.cpp')], include_dirs=['src']) config.add_extension('lgamma', sources=['lgamma.pyx', join('src', 'gamma.c')], include_dirs=['src'], libraries=libraries) config.add_extension('graph_shortest_path', sources=['graph_shortest_path.pyx'], include_dirs=[numpy.get_include()]) config.add_extension('fast_dict', sources=['fast_dict.pyx'], language="c++", include_dirs=[numpy.get_include()], libraries=libraries) # generate files from a template pyx_templates = ['sklearn/utils/seq_dataset.pyx.tp', 'sklearn/utils/seq_dataset.pxd.tp'] for pyxfiles in pyx_templates: outfile = pyxfiles.replace('.tp', '') # if .pyx.tp is not updated, no need to output .pyx if (os.path.exists(outfile) and os.stat(pyxfiles).st_mtime < os.stat(outfile).st_mtime): continue with open(pyxfiles, "r") as f: tmpl = f.read() pyxcontent = Tempita.sub(tmpl) with open(outfile, "w") as f: f.write(pyxcontent) config.add_extension('seq_dataset', sources=['seq_dataset.pyx'], include_dirs=[numpy.get_include()]) config.add_extension('weight_vector', sources=['weight_vector.pyx'], include_dirs=[numpy.get_include()], libraries=libraries) config.add_extension("_random", sources=["_random.pyx"], include_dirs=[numpy.get_include()], libraries=libraries) config.add_extension("_logistic_sigmoid", sources=["_logistic_sigmoid.pyx"], include_dirs=[numpy.get_include()], libraries=libraries) config.add_subpackage('tests') return config
try: from Cython import Tempita as tempita except ImportError: import tempita except ImportError: notempita_msg = ("# tempita needed to finish setup. run:\n\n" + " $ pip install tempita # or easy_install tempita\n") sys.exit(notempita_msg) # DOC: Tempita create pyx files code_cdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "affine") for folder, subdirs, files in os.walk(code_cdir): for fil in files: if fil.endswith(".pyx.in"): with open(os.path.join(folder, fil), "r") as f: cython_file = tempita.sub(f.read()) with open(os.path.join(folder, os.path.splitext(fil)[0]), "w") as f: f.write(cython_file) extensions = [Extension('affine.model.Cython_extensions', ['affine/extensions/Cython_extensions.pyx'])] setup( name='affine', author='Barton Baker', version='0.3', packages=find_packages(), description='This package offers a solver class for affine ' \ + 'term structure models.', author_email="*****@*****.**", use_2to3=True,