Ejemplo n.º 1
0
def make_pythran_extensions(modules):
    exclude_pythran = tuple(
        key for key, value in config["exclude_pythran"].items() if value)
    if len(exclude_pythran) > 0:
        logger.info("Pythran files in the packages " + str(exclude_pythran) +
                    " will not be built.")
    develop = sys.argv[-1] == "develop"
    extensions = []
    for mod in modules:
        package = mod.rsplit(".", 1)[0]
        if any(package == excluded for excluded in exclude_pythran):
            continue
        base_file = mod.replace(".", os.path.sep)
        py_file = base_file + ".py"
        # warning: does not work on Windows
        suffix = get_config_var("EXT_SUFFIX") or ".so"
        bin_file = base_file + suffix
        logger.info("make_pythran_extension: {} -> {} ".format(
            py_file, os.path.basename(bin_file)))
        if (not develop or not os.path.exists(bin_file)
                or modification_date(bin_file) < modification_date(py_file)):
            pext = PythranExtension(mod, [py_file], extra_compile_args=["-O3"])
            pext.include_dirs.append(np.get_include())
            # bug pythran extension...
            compile_arch = os.getenv("CARCH", "native")
            pext.extra_compile_args.extend(
                ["-O3", "-march={}".format(compile_arch), "-DUSE_XSIMD"])
            # pext.extra_link_args.extend(['-fopenmp'])
            extensions.append(pext)
    return extensions
Ejemplo n.º 2
0
def configuration(parent_package='', top_path=None):
    from numpy.distutils.misc_util import Configuration
    from scipy._build_utils import (get_f2py_int64_options,
                                    ilp64_pre_build_hook, uses_blas64,
                                    numpy_nodepr_api)

    if uses_blas64():
        # TODO: Note that fitpack does not use BLAS/LAPACK.
        # The reason why we use 64-bit ints only in this case
        # is because scipy._build_utils knows the 64-bit int
        # flags for too few Fortran compilers, so we cannot turn
        # this on by default.
        pre_build_hook = ilp64_pre_build_hook
        f2py_options = get_f2py_int64_options()
        define_macros = [("HAVE_ILP64", None)]
    else:
        pre_build_hook = None
        f2py_options = None
        define_macros = []

    config = Configuration('interpolate', parent_package, top_path)

    fitpack_src = [join('fitpack', '*.f')]
    config.add_library('fitpack',
                       sources=fitpack_src,
                       _pre_build_hook=pre_build_hook)

    config.add_extension('interpnd', sources=['interpnd.c'])

    config.add_extension('_ppoly', sources=['_ppoly.c'])

    config.add_extension('_bspl',
                         sources=['_bspl.c'],
                         depends=['src/__fitpack.h'])

    config.add_extension('_fitpack',
                         sources=['src/_fitpackmodule.c'],
                         libraries=['fitpack'],
                         define_macros=define_macros +
                         numpy_nodepr_api['define_macros'],
                         depends=(['src/__fitpack.h'] + fitpack_src))

    config.add_extension('dfitpack',
                         sources=['src/fitpack.pyf'],
                         libraries=['fitpack'],
                         define_macros=define_macros,
                         depends=fitpack_src,
                         f2py_options=f2py_options)

    if int(os.environ.get('SCIPY_USE_PYTHRAN', 1)):
        from pythran.dist import PythranExtension
        ext = PythranExtension(
            'scipy.interpolate._rbfinterp_pythran',
            sources=['scipy/interpolate/_rbfinterp_pythran.py'],
            config=['compiler.blas=none'])
        config.ext_modules.append(ext)

    config.add_data_dir('tests')

    return config
Ejemplo n.º 3
0
def compile_cxxfile(module_name, cxxfile, output_binary=None, **kwargs):
    '''c++ file -> native module
    Return the filename of the produced shared library
    Raises CompileError on failure

    '''

    builddir = mkdtemp()
    buildtmp = mkdtemp()

    extension = PythranExtension(module_name,
                                 [cxxfile],
                                 **kwargs)

    try:
        setup(name=module_name,
              ext_modules=[extension],
              cmdclass={"build_ext": PythranBuildExt},
              # fake CLI call
              script_name='setup.py',
              script_args=['--verbose'
                           if logger.isEnabledFor(logging.INFO)
                           else '--quiet',
                           'build_ext',
                           '--build-lib', builddir,
                           '--build-temp', buildtmp]
              )
    except SystemExit as e:
        raise CompileError(str(e))

    def copy(src_file, dest_file):
        # not using shutil.copy because it fails to copy stat across devices
        with open(src_file, 'rb') as src:
            with open(dest_file, 'wb') as dest:
                dest.write(src.read())

    ext = sysconfig.get_config_var('EXT_SUFFIX')
    # Copy all generated files including the module name prefix (.pdb, ...)
    for f in glob.glob(os.path.join(builddir, module_name + "*")):
        if f.endswith(ext):
            if output_binary:
                output_binary = output_binary.replace('%{ext}', ext)
            else:
                output_binary = os.path.join(os.getcwd(), module_name + ext)
            copy(f, output_binary)
        else:
            if output_binary:
                output_binary = output_binary.replace('%{ext}', '')
                output_directory = os.path.dirname(output_binary)
            else:
                output_directory = os.getcwd()
            copy(f, os.path.join(output_directory, os.path.basename(f)))
    shutil.rmtree(builddir)
    shutil.rmtree(buildtmp)

    logger.info("Generated module: " + module_name)
    logger.info("Output: " + output_binary)

    return output_binary
Ejemplo n.º 4
0
def compile_cxxfile(module_name, cxxfile, output_binary=None, **kwargs):
    '''c++ file -> native module
    Return the filename of the produced shared library
    Raises CompileError on failure

    '''

    builddir = mkdtemp()
    buildtmp = mkdtemp()

    extension_args = make_extension(python=True, **kwargs)

    extension = PythranExtension(module_name,
                                 [cxxfile],
                                 **extension_args)

    try:
        setup(name=module_name,
              ext_modules=[extension],
              cmdclass={"build_ext": PythranBuildExt},
              # fake CLI call
              script_name='setup.py',
              script_args=['--verbose'
                           if logger.isEnabledFor(logging.INFO)
                           else '--quiet',
                           'build_ext',
                           '--build-lib', builddir,
                           '--build-temp', buildtmp]
              )
    except SystemExit as e:
        raise CompileError(str(e))

    target, = glob.glob(os.path.join(builddir, module_name + "*"))
    if not output_binary:
        output_binary = os.path.join(os.getcwd(),
                                     module_name + os.path.splitext(target)[1])

    # not using shutil.copy because it fails to copy stat across devices
    with open(target, 'rb') as src:
        with open(output_binary, 'wb') as dest:
            dest.write(src.read())

    shutil.rmtree(builddir)
    shutil.rmtree(buildtmp)

    logger.info("Generated module: " + module_name)
    logger.info("Output: " + output_binary)

    return output_binary
Ejemplo n.º 5
0
def make_pythran_extensions(modules):
    develop = sys.argv[-1] == "develop"
    extensions = []
    for mod in modules:
        base_file = mod.replace(".", os.path.sep)
        py_file = base_file + ".py"
        # warning: does not work on Windows
        suffix = get_config_var("EXT_SUFFIX") or ".so"
        bin_file = base_file + suffix
        if (not develop or not os.path.exists(bin_file)
                or modification_date(bin_file) < modification_date(py_file)):
            print('pythran extension "' + mod + '" needs to be built')
            pext = PythranExtension(mod, [py_file])
            pext.include_dirs.append(np.get_include())
            extensions.append(pext)
    return extensions
Ejemplo n.º 6
0
def compile_cxxfile(module_name, cxxfile, output_binary=None, **kwargs):
    '''c++ file -> native module
    Return the filename of the produced shared library
    Raises CompileError on failure

    '''

    builddir = mkdtemp()
    buildtmp = mkdtemp()

    extension_args = make_extension(python=True, **kwargs)

    extension = PythranExtension(module_name,
                                 [cxxfile],
                                 **extension_args)

    try:
        setup(name=module_name,
              ext_modules=[extension],
              # fake CLI call
              script_name='setup.py',
              script_args=['--verbose'
                           if logger.isEnabledFor(logging.INFO)
                           else '--quiet',
                           'build_ext',
                           '--build-lib', builddir,
                           '--build-temp', buildtmp]
              )
    except SystemExit as e:
        raise CompileError(str(e))

    target, = glob.glob(os.path.join(builddir, module_name + "*"))
    if not output_binary:
        output_binary = os.path.join(os.getcwd(),
                                     module_name + os.path.splitext(target)[1])
    shutil.move(target, output_binary)
    shutil.rmtree(builddir)
    shutil.rmtree(buildtmp)

    logger.info("Generated module: " + module_name)
    logger.info("Output: " + output_binary)

    return output_binary
Ejemplo n.º 7
0
from pythran.dist import PythranExtension, PythranBuildExt

COMPILER_ARGS_PYT = [
    "-O3", "-ffast-math", "-mfpmath=sse", "-march=native", "-funroll-loops",
    "-fwhole-program", "-fopenmp", "-std=c++11", "-fno-math-errno", "-w",
    "-fvisibility=hidden", "-fno-wrapv", "-DUSE_XSIMD", "-DNDEBUG",
    "-finline-limit=100000"
]
LINK_ARGS = ["-fopenmp", "-lm", "-Wl,-strip-all"]

WIN_LINK_ARGS = ["/openmp"]

if sys.platform.startswith("win"):
    COMPILER_ARGS_PYT.remove("-DUSE_XSIMD")  # windows fails with XSIMD
    dsp_pythran = PythranExtension(name="qampy.core.pythran_dsp",
                                   sources=["qampy/core/pythran_dsp.py"],
                                   extra_compile_args=COMPILER_ARGS_PYT,
                                   extra_link_args=WIN_LINK_ARGS)
    pythran_equalisation = PythranExtension(
        name="qampy.core.equalisation.pythran_equalisation",
        sources=["qampy/core/equalisation/pythran_equalisation.py"],
        extra_compile_args=COMPILER_ARGS_PYT,
        extra_link_args=WIN_LINK_ARGS)
else:
    dsp_pythran = PythranExtension(name="qampy.core.pythran_dsp",
                                   sources=["qampy/core/pythran_dsp.py"],
                                   extra_compile_args=COMPILER_ARGS_PYT,
                                   extra_link_args=LINK_ARGS)
    pythran_equalisation = PythranExtension(
        name="qampy.core.equalisation.pythran_equalisation",
        sources=["qampy/core/equalisation/pythran_equalisation.py"],
        extra_compile_args=COMPILER_ARGS_PYT,
Ejemplo n.º 8
0
from setuptools import setup
from pythran.dist import PythranExtension, PythranBuildExt

module1 = PythranExtension('demo', sources=['a.py'])

setup(name='demo',
      version='1.0',
      description='This is a demo package',
      cmdclass={"build_ext": PythranBuildExt},
      ext_modules=[module1])
Ejemplo n.º 9
0
from numpy.distutils.core import setup
from numpy.distutils.command.build_ext import build_ext as npy_build_ext
from pythran.dist import PythranExtension, PythranBuildExt

module1 = PythranExtension('demo3.a', sources=['demo3/a.py'])

setup(name='demo3',
      version='1.0',
      description='This is a demo package',
      cmdclass={"build_ext": PythranBuildExt[npy_build_ext]},
      ext_modules=[module1])
Ejemplo n.º 10
0
from distutils.core import setup, Extension
from pythran.dist import PythranExtension, PythranBuildExt

setup(name='demo2',
      version='1.0',
      description='This is another demo package',
      packages=['demo2'],
      cmdclass={"build_ext": PythranBuildExt},
      ext_modules=[PythranExtension('demo2.a', sources=['a.py'])])
Ejemplo n.º 11
0
# we deliberately do not set any lower nor upper bounds on `geopandas`
# dependency so that people might install its cythonized version
geo = ["geopandas", "shapely >= 1.0.2"]

install_requires = [x.strip() for x in all_reqs if 'git+' not in x]
dependency_links = [
    x.strip().replace('git+', '') for x in all_reqs if x.startswith('git+')
]

setup(
    name='pylandstats',
    version=__version__,
    description='Open-source Python library to compute landscape metrics',
    long_description=long_description,
    long_description_content_type='text/markdown',
    classifiers=classifiers,
    url='https://github.com/martibosch/pylandstats',
    author='Martí Bosch',
    author_email='*****@*****.**',
    license='GPL-3.0',
    packages=find_packages(exclude=['docs', 'tests*']),
    include_package_data=True,
    install_requires=install_requires,
    extras_require={'geo': geo},
    dependency_links=dependency_links,
    ext_modules=[
        PythranExtension('pylandstats.compute',
                         sources=['pylandstats/compute.py'])
    ],
)
Ejemplo n.º 12
0
from setuptools import setup, dist
try:
    # Try to compile pythran binary extension module.
    from pythran.dist import PythranExtension, PythranBuildExt
    dist.Distribution(dict(setup_requires='pythran'))
    ext_modules = [
        PythranExtension(
            'pyfiberamp.dynamic.fiber_simulation_pythran_bindings',
            ['pyfiberamp/dynamic/inner_loop_functions.py'],
        ),
    ]
    cmdclass = {"build_ext": PythranBuildExt}
except ImportError:
    ext_modules = []
    cmdclass = {}

VERSION = '0.4.0'

long_description = '''PyFiberAmp is a powerful simulation library for modeling
rare-earth-doped fiber lasers and amplifiers using rate equations.'''

setup(name='PyFiberAmp',
      version=VERSION,
      author='Joona Rissanen',
      author_email='*****@*****.**',
      url='https://github.com/Jomiri/pyfiberamp',
      description='Fiber amplifier modeling library',
      long_description=long_description,
      license='MIT',
      install_requires=['matplotlib', 'numpy', 'scipy'],
      packages=[
Ejemplo n.º 13
0
from setuptools import Extension, setup
from pythran.dist import PythranExtension
import numpy

setup(
    ext_modules=[
        Extension("sosfilt._sosfilt", ["sosfilt/_sosfilt.pyx"]),
        PythranExtension("sosfilt._zpk_funcs", ["sosfilt/_zpk_funcs.py"]),
    ],
    include_dirs=[numpy.get_include()],
)