Ejemplo n.º 1
0
def cythonize_all(relpath):
    """Cythonize all Cython modules in relative path"""
    from Cython.Compiler import Main

    for fname in os.listdir(relpath):
        if osp.splitext(fname)[1] == ".pyx":
            Main.compile(osp.join(relpath, fname))
Ejemplo n.º 2
0
def cycompile(input_file, options=()):
    from Cython.Compiler import Version, CmdLine, Main
    options, sources = CmdLine.parse_command_line(list(options or ()) + ['--embed', input_file])
    _debug('Using Cython %s to compile %s', Version.version, input_file)
    result = Main.compile(sources, options)
    if result.num_errors > 0:
        sys.exit(1)
Ejemplo n.º 3
0
def PyrexCompile ( Errors, Main, source, pxdDirectories = None ):
    """Convert a Pyrex file to C."""
    options = Main.default_options
    # . Change for Pyrex version 0.9.6: options is now a dictionary not a CompilationOptions object so convert to a CompilationOptions object.
    if isinstance ( options, dict ): options = Main.CompilationOptions ( options )
    if pxdDirectories is not None: options.include_path.extend ( pxdDirectories )
    context = Main.Context ( options.include_path, {} )
    try:
        result = Main.compile ( source, options )
        failed = ( result.num_errors > 0 )
    except Errors.PyrexError as e:
        print ( e )
        failed = True
    if failed: raise ValueError ( "There was a Pyrex compiler error." )
Ejemplo n.º 4
0
def compile_file(pyfile):
	in_file_name = pyfile
	source = open(in_file_name).read()
	out_file_name = in_file_name.replace('.py', '.out')

	temp_py_file = tempfile.NamedTemporaryFile(suffix='.py', delete=False)
	temp_py_file.write(source.encode())
	temp_py_file.flush()

	Main.Options.embed = 'main'
	res = Main.compile(temp_py_file.name, Main.CompilationOptions(), '')

	gcc_cmd = 'gcc -fPIC -O2 %s -I/usr/include/python3.6 -L/usr/lib/python3.6 -lpython3.6m -o %s' % (res.c_file, out_file_name)

	print(gcc_cmd)
	assert 0 == subprocess.check_call(gcc_cmd.split(' '))
Ejemplo n.º 5
0
    def generate_c_from_cython(extension, build_dir):
        if not sys.platform == 'darwin':
            print('No %s will be built for this platform.' % extension.name)
            return
        from distutils.dep_util import newer_group
        name = extension.name.split('.')[-1]
        source = extension.depends[0]
        target = os.path.join(build_dir, name + '.c')

        if newer_group(extension.depends, target):
            from Cython.Compiler import Main
            options = Main.CompilationOptions(defaults=Main.default_options,
                                              output_file=target)
            cython_result = Main.compile(source, options=options)
            if cython_result.num_errors != 0:
                raise RuntimeError("%d errors in Cython compile" %
                                   cython_result.num_errors)
        return target
Ejemplo n.º 6
0
Archivo: setup.py Proyecto: pib/enable
    def generate_c_from_cython(extension, build_dir):
        if not sys.platform == 'darwin':
            print 'No %s will be built for this platform.' % (extension.name)
            return
        from distutils.dep_util import newer_group
        name = extension.name.split('.')[-1]
        source = extension.depends[0]
        target = os.path.join(build_dir, name+'.c')

        if newer_group(extension.depends, target):
            from Cython.Compiler import Main
            options = Main.CompilationOptions(
                defaults=Main.default_options,
                output_file=target)
            cython_result = Main.compile(source, options=options)
            if cython_result.num_errors != 0:
                raise RuntimeError("%d errors in Cython compile" %
                    cython_result.num_errors)
        return target
Ejemplo n.º 7
0
    cmdclass['build_ext'] = build_pyx
else:
    ext.sources[0] = 'fplib.cpp'

# This silly hack, inspired by the pymt setup.py, runs Cython if we're
# doing a source distribution. The MANIFEST.in file ensures that the
# C++ source is included in the tarball also.
if 'sdist' in sys.argv:
    if not HAVE_CYTHON:
        print('We need Cython to build a source distribution.')
        sys.exit(1)
    from Cython.Compiler import Main
    source = ext.sources[0] # hacky!
    Main.compile(
        source,
        cplus = True,
        full_module_name = ext.name,
    )

setup(
    name = 'pylastfp',
    version = '0.6',
    description = "bindings for Last.fm's acoustic fingerprinting (fplib)",
    author = 'Adrian Sampson',
    author_email = '*****@*****.**',
    url = 'http://github.com/sampsyo/pylastfp/',
    license = 'LGPL',
    platforms = 'ALL',
    long_description = _read('README.rst'),
    classifiers = [
        'Topic :: Multimedia :: Sound/Audio :: Analysis',
Ejemplo n.º 8
0
except ImportError:
    from distutils.core import setup, Extension

have_cython = True
try:
    import Cython.Compiler.Main as cython_compiler
except ImportError:
    have_cython = False

cchardet_dir = 'src/cchardet/'
uchardet_dir = 'src/ext/uchardet/src'

if have_cython:
    pyx_sources = glob.glob(cchardet_dir + '*.pyx')
    sys.stderr.write('cythonize: %r\n' % (pyx_sources,))
    cython_compiler.compile(
        pyx_sources, options=cython_compiler.CompilationOptions(cplus=True, compiler_directives={"language_level": 3}))

cchardet_sources = glob.glob(cchardet_dir + '*.cpp')
sources = cchardet_sources

uchardet_sources = [
    os.path.join(uchardet_dir, 'CharDistribution.cpp'),
    os.path.join(uchardet_dir, 'JpCntx.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangArabicModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangBulgarianModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangCroatianModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangCzechModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangEsperantoModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangEstonianModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangFinnishModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangFrenchModel.cpp'),
Ejemplo n.º 9
0
 def __init__(self, *args, **kwargs):
     for src in glob('attic/*.pyx'):
         cython_compiler.compile(glob('attic/*.pyx'),
                                 cython_compiler.default_options)
     versioneer.cmd_sdist.__init__(self, *args, **kwargs)
Ejemplo n.º 10
0
def cython_extension(srcfile):
    options = Main.CompilationOptions(include_path=[os.path.join(os.path.abspath(os.path.dirname(__file__)), 'include')])
    Main.compile(srcfile, options=options)
Ejemplo n.º 11
0
 def __init__(self, *args, **kwargs):
   for src in glob('timeuuid/*.pyx'):
     print src
     Main.compile(glob('timeuuid/*.pyx'),
                  Main.default_options)
   sdist.__init__(self, *args, **kwargs)
Ejemplo n.º 12
0
def cythonize_all(relpath):
    """Cythonize all Cython modules in relative path"""
    from Cython.Compiler import Main
    for fname in os.listdir(relpath):
        if osp.splitext(fname)[1] == '.pyx':
            Main.compile(osp.join(relpath, fname))
Ejemplo n.º 13
0
def cythonize(src):
  sys.stderr.write("cythonize: %r\n" % (src,))
  cython_compiler.compile([src])
Ejemplo n.º 14
0
 def __init__(self, *args, **kwargs):
     for src in cython_sources:
         cython_compiler.compile(src, cython_compiler.default_options)
     super().__init__(*args, **kwargs)
Ejemplo n.º 15
0
import Cython.Compiler.Main as main
import os, glob, sys

nargs = len(sys.argv)

# If getenv does not work, set the pCore directory manually, for example:
# pdynamo_pcore = "/home/mikolaj/local/opt/pDynamo-1.8.0/pCore-1.8.0"
if nargs < 2:
    pdynamo_pcore = os.getenv("PDYNAMO_PCORE")
else:
    pdynamo_pcore = sys.argv[1]

current_directory = os.getcwd()
pxd_directories = [
    current_directory,
    os.path.join(pdynamo_pcore, "extensions/pyrex")
]

# Decide between taking all files in the current directory or the files from the command line
if nargs > 2:
    sources = [os.path.abspath(filename) for filename in sys.argv[2:]]
else:
    sources = glob.glob(os.path.join(current_directory, "*.pyx"))

# Now compile
for source in sources:
    options = main.CompilationOptions(main.default_options)
    options.include_path.extend(pxd_directories)
    main.compile(source, options)
Ejemplo n.º 16
0
def cythonize(src):
    sys.stderr.write("cythonize: %r\n" % (src,))
    cython_compiler.compile([src], cplus=True, emit_linenums=True)
Ejemplo n.º 17
0
except ImportError:
    from distutils.core import setup, Extension

have_cython = True
try:
    import Cython.Compiler.Main as cython_compiler
except ImportError:
    have_cython = False

cchardet_dir = 'src/cchardet/'
uchardet_dir = 'src/ext/uchardet/src'

if have_cython:
    pyx_sources = glob.glob(cchardet_dir + '*.pyx')
    sys.stderr.write('cythonize: %r\n' % (pyx_sources, ))
    cython_compiler.compile(
        pyx_sources, options=cython_compiler.CompilationOptions(cplus=True))

cchardet_sources = glob.glob(cchardet_dir + '*.cpp')
sources = cchardet_sources

uchardet_sources = [
    os.path.join(uchardet_dir, 'CharDistribution.cpp'),
    os.path.join(uchardet_dir, 'JpCntx.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangArabicModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangBulgarianModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangCroatianModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangCzechModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangEsperantoModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangEstonianModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangFinnishModel.cpp'),
    os.path.join(uchardet_dir, 'LangModels/LangFrenchModel.cpp'),
Ejemplo n.º 18
0
 def __init__(self, *args, **kwargs):
     for src in glob('salt/msgpack/*.pyx'):
         cython_compiler.compile(glob('msgpack/*.pyx'),
                                 cython_compiler.default_options)
     sdist.__init__(self, *args, **kwargs)
Ejemplo n.º 19
0
Archivo: setup.py Proyecto: brodul/borg
 def __init__(self, *args, **kwargs):
     for src in glob('borg/*.pyx'):
         cython_compiler.compile(src, cython_compiler.default_options)
     versioneer.cmd_sdist.__init__(self, *args, **kwargs)
Ejemplo n.º 20
0
 def __init__(self, *args, **kwargs):
     for src in cython_sources:
         cython_compiler.compile(src, cython_compiler.default_options)
     super().__init__(*args, **kwargs)
Ejemplo n.º 21
0
    pypissh.monkeypatch()

DEBUG = False

src_dir = 'src'
ext_dir = os.path.join(src_dir,'ext')
build_dir = 'build'
cchardet_dir = os.path.join(src_dir,'cchardet/')
charsetdetect_dir = os.path.join(ext_dir, 'libcharsetdetect/')
nspr_emu_dir = os.path.join(charsetdetect_dir,"nspr-emu/")
uchardet_dir = os.path.join(charsetdetect_dir,"mozilla/extensions/universalchardet/src/base/")

if have_cython:
    pyx_sources = glob.glob(cchardet_dir+'*.pyx')
    sys.stderr.write("cythonize: %r\n" % (pyx_sources,))
    cython_compiler.compile(pyx_sources,options=cython_compiler.CompilationOptions(cplus=True))
cchardet_sources = glob.glob(cchardet_dir+'*.cpp')
sources = cchardet_sources  + [os.path.join(charsetdetect_dir,"charsetdetect.cpp")] + glob.glob(uchardet_dir+'*.cpp')

macros = []
extra_compile_args = []
extra_link_args = []

if platform.system() == "Windows":
    macros.append(("WIN32","1"))

if DEBUG:
    macros.append(("DEBUG_chardet","1"))
    extra_compile_args.append("-g"),
    extra_link_args.append("-g"),
Ejemplo n.º 22
0
 def __init__(self, *args, **kwargs):
     cy_opt = cython_compiler.default_options.copy()
     cy_opt["cplus"] = True
     for src in glob("msgpack/*.pyx"):
         cython_compiler.compile(glob("msgpack/*.pyx"), cy_opt)
     sdist.__init__(self, *args, **kwargs)
Ejemplo n.º 23
0
def cythonize(src):
    sys.stderr.write("cythonize: %r\n" % (src, ))
    cython_compiler.compile([src], cplus=True)
Ejemplo n.º 24
0
def cython_extension(srcfile):
    options = Main.CompilationOptions(include_path=[
        os.path.join(os.path.abspath(os.path.dirname(__file__)), 'include')
    ])
    Main.compile(srcfile, options=options)
Ejemplo n.º 25
0
 def __init__(self, *args, **kwargs):
     for src in glob('msgpack/*.pyx'):
         cython_compiler.compile(glob('msgpack/*.pyx'),
                                 cython_compiler.default_options)
     sdist.__init__(self, *args, **kwargs)
Ejemplo n.º 26
0
    cmdclass['build_ext'] = build_pyx
else:
    ext.sources[0] = 'fplib.cpp'

# This silly hack, inspired by the pymt setup.py, runs Cython if we're
# doing a source distribution. The MANIFEST.in file ensures that the
# C++ source is included in the tarball also.
if 'sdist' in sys.argv:
    if not HAVE_CYTHON:
        print 'We need Cython to build a source distribution.'
        sys.exit(1)
    from Cython.Compiler import Main
    source = ext.sources[0]  # hacky!
    Main.compile(
        source,
        cplus=True,
        full_module_name=ext.name,
    )

setup(
    name='pylastfp',
    version='0.3',
    description="bindings for Last.fm's acoustic fingerprinting (fplib)",
    author='Adrian Sampson',
    author_email='*****@*****.**',
    url='http://github.com/sampsyo/pylastfp/',
    license='LGPL',
    platforms='ALL',
    long_description=_read('README.rst'),
    classifiers=[
        'Topic :: Multimedia :: Sound/Audio :: Analysis',
Ejemplo n.º 27
0
 def __init__(self, *args, **kwargs):
     for src in glob('borg/*.pyx'):
         cython_compiler.compile(src, cython_compiler.default_options)
     super().__init__(*args, **kwargs)
Ejemplo n.º 28
0
 def __init__(self, *args, **kwargs):
     for src in glob('libuuid/*.pyx'):
         cython_compiler.compile(glob('libuuid/*.pyx'),
                                 cython_compiler.default_options)
     sdist.__init__(self, *args, **kwargs)
Ejemplo n.º 29
0
 def __init__(self, *args, **kwargs):
     for src in glob('borg/*.pyx'):
         cython_compiler.compile(src, cython_compiler.default_options)
     super().__init__(*args, **kwargs)
Ejemplo n.º 30
0
 def __init__(self, *args, **kwargs):
     for src in glob('timeuuid/*.pyx'):
         print src
         Main.compile(glob('timeuuid/*.pyx'), Main.default_options)
     sdist.__init__(self, *args, **kwargs)