Ejemplo n.º 1
0
    try:
        self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + deps +
                   extra_postargs,
                   display=display)
    except DistutilsExecError:
        msg = str(get_exception())
        raise CompileError(msg)

    # add commandline flags to dependency file
    if deps:
        with open(obj + '.d', 'a') as f:
            f.write(_commandline_dep_string(cc_args, extra_postargs, pp_opts))


replace_method(UnixCCompiler, '_compile', UnixCCompiler__compile)


def UnixCCompiler_create_static_lib(self,
                                    objects,
                                    output_libname,
                                    output_dir=None,
                                    debug=0,
                                    target_lang=None):
    """
    Build a static library in a separate sub-process.

    Parameters
    ----------
    objects : list or tuple of str
        List of paths to object files used to build the static library.
Ejemplo n.º 2
0
    if (len(sys.argv) >= 2
            and sys.argv[1] in ('bdist_wheel', 'bdist_egg')) or ('develop'
                                                                 in sys.argv):
        # bdist_wheel/bdist_egg needs setuptools
        import setuptools

    from numpy.distutils.core import setup

    # Add the configuration to the setup dict when building
    # after numpy is installed
    metadata['configuration'] = configuration

    # A Small hack to remove -std=c99 from c++ compiler options (if present)
    # This should only be if numpy 1.18.0 is installed.
    from numpy.distutils.ccompiler import CCompiler_customize, CCompiler
    from numpy.distutils.ccompiler import replace_method
    _np_customize = CCompiler_customize

    def _simpeg_customize(self, dist, need_cxx=0):
        _np_customize(self, dist, need_cxx)
        if need_cxx:
            # Remove -std=c99 option if present
            try:
                self.compiler_so.remove('-std=c99')
            except (AttributeError, ValueError):
                pass

    replace_method(CCompiler, 'customize', _simpeg_customize)

setup(**metadata)
            ccomp.remove('-Ae')
        if '-Aa' in ccomp:
            ccomp.remove('-Aa')
        # add flags for (almost) sane C++ handling
        ccomp += ['-AA']
        self.compiler_so = ccomp

    display = '%s: %s' % (os.path.basename(self.compiler_so[0]),src)
    try:
        self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
                   extra_postargs, display = display)
    except DistutilsExecError:
        msg = str(get_exception())
        raise CompileError(msg)

replace_method(UnixCCompiler, '_compile', UnixCCompiler__compile)


def UnixCCompiler_create_static_lib(self, objects, output_libname,
                                    output_dir=None, debug=0, target_lang=None):
    """
    Build a static library in a separate sub-process.

    Parameters
    ----------
    objects : list or tuple of str
        List of paths to object files used to build the static library.
    output_libname : str
        The library name as an absolute or relative (if `output_dir` is used)
        path.
    output_dir : str, optional
from distutils.errors import DistutilsExecError, CompileError
from distutils.unixccompiler import *
from numpy.distutils.ccompiler import replace_method

import log

# Note that UnixCCompiler._compile appeared in Python 2.3
def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
    display = "%s: %s" % (os.path.basename(self.compiler_so[0]), src)
    try:
        self.spawn(self.compiler_so + cc_args + [src, "-o", obj] + extra_postargs, display=display)
    except DistutilsExecError, msg:
        raise CompileError, msg


replace_method(UnixCCompiler, "_compile", UnixCCompiler__compile)


def UnixCCompiler_create_static_lib(self, objects, output_libname, output_dir=None, debug=0, target_lang=None):
    objects, output_dir = self._fix_object_args(objects, output_dir)

    output_filename = self.library_filename(output_libname, output_dir=output_dir)

    if self._need_link(objects, output_filename):
        try:
            # previous .a may be screwed up; best to remove it first
            # and recreate.
            # Also, ar on OS X doesn't handle updating universal archives
            os.unlink(output_filename)
        except (IOError, OSError):
            pass
Ejemplo n.º 5
0
        self.spawn(
            self.compiler_so + cc_args + [src, "-o", obj] + deps +
            extra_postargs,
            display=display,
        )
    except DistutilsExecError:
        msg = str(get_exception())
        raise CompileError(msg)

    # add commandline flags to dependency file
    if deps:
        with open(obj + ".d", "a") as f:
            f.write(_commandline_dep_string(cc_args, extra_postargs, pp_opts))


replace_method(UnixCCompiler, "_compile", UnixCCompiler__compile)


def UnixCCompiler_create_static_lib(self,
                                    objects,
                                    output_libname,
                                    output_dir=None,
                                    debug=0,
                                    target_lang=None):
    """
    Build a static library in a separate sub-process.

    Parameters
    ----------
    objects : list or tuple of str
        List of paths to object files used to build the static library.
Ejemplo n.º 6
0
def setup_package():

    # TODO: Require Python 3.8 for PyPy when PyPy3.8 is ready
    # https://github.com/conda-forge/conda-forge-pinning-feedstock/issues/2089
    if platform.python_implementation() == "PyPy":
        python_requires = ">=3.7"
        required_python_version = (3, 7)
    else:
        python_requires = ">=3.8"
        required_python_version = (3, 8)

    metadata = dict(
        name=DISTNAME,
        maintainer=MAINTAINER,
        maintainer_email=MAINTAINER_EMAIL,
        description=DESCRIPTION,
        license=LICENSE,
        url=URL,
        download_url=DOWNLOAD_URL,
        project_urls=PROJECT_URLS,
        version=VERSION,
        long_description=LONG_DESCRIPTION,
        classifiers=[
            "Intended Audience :: Science/Research",
            "Intended Audience :: Developers",
            "License :: OSI Approved :: BSD License",
            "Programming Language :: C",
            "Programming Language :: Python",
            "Topic :: Software Development",
            "Topic :: Scientific/Engineering",
            "Development Status :: 5 - Production/Stable",
            "Operating System :: Microsoft :: Windows",
            "Operating System :: POSIX",
            "Operating System :: Unix",
            "Operating System :: MacOS",
            "Programming Language :: Python :: 3",
            "Programming Language :: Python :: 3.8",
            "Programming Language :: Python :: 3.9",
            "Programming Language :: Python :: 3.10",
            "Programming Language :: Python :: Implementation :: CPython",
            "Programming Language :: Python :: Implementation :: PyPy",
        ],
        cmdclass=cmdclass,
        python_requires=python_requires,
        install_requires=min_deps.tag_to_packages["install"],
        package_data={"": ["*.pxd"]},
        **extra_setuptools_args,
    )

    commands = [arg for arg in sys.argv[1:] if not arg.startswith("-")]
    if all(command in ("egg_info", "dist_info", "clean", "check")
           for command in commands):
        # These actions are required to succeed without Numpy for example when
        # pip is used to install Scikit-learn when Numpy is not yet present in
        # the system.

        # These commands use setup from setuptools
        from setuptools import setup

        metadata["version"] = VERSION
        metadata["packages"] = ["sklearn"]
    else:
        if sys.version_info < required_python_version:
            required_version = "%d.%d" % required_python_version
            raise RuntimeError(
                "Scikit-learn requires Python %s or later. The current"
                " Python version is %s installed in %s." %
                (required_version, platform.python_version(), sys.executable))

        check_package_status("numpy", min_deps.NUMPY_MIN_VERSION)

        check_package_status("scipy", min_deps.SCIPY_MIN_VERSION)

        # These commands require the setup from numpy.distutils because they
        # may use numpy.distutils compiler classes.
        from numpy.distutils.core import setup

        # Monkeypatches CCompiler.spawn to prevent random wheel build errors on Windows
        # The build errors on Windows was because msvccompiler spawn was not threadsafe
        # This fixed can be removed when we build with numpy >= 1.22.2 on Windows.
        # https://github.com/pypa/distutils/issues/5
        # https://github.com/scikit-learn/scikit-learn/issues/22310
        # https://github.com/numpy/numpy/pull/20640
        from numpy.distutils.ccompiler import replace_method
        from distutils.ccompiler import CCompiler
        from sklearn.externals._numpy_compiler_patch import CCompiler_spawn

        replace_method(CCompiler, "spawn", CCompiler_spawn)

        metadata["configuration"] = configuration

    setup(**metadata)
Ejemplo n.º 7
0
    # update arguments.
    ccshared = ' '.join(set(self.compiler_so) - set(self.compiler))
    compiler = ' '.join(it for it in self.compiler if it not in unwanted)
    old_compiler = self.compiler
    self.set_executables(
        compiler=compiler,
        compiler_so=compiler + ' ' + ccshared,
    )
    modified = self.compiler != old_compiler
    if modified and need_cxx and hasattr(self, 'compiler'):
        log.warn("#### %s ####### %s removed" % (self.compiler, unwanted))

    return


replace_method(CCompiler, 'customize', CCompiler_customize)


def make_cython_extension(name,
                          c_subdirs,
                          include_dirs=None,
                          libraries=None,
                          extra_compile_args=None):
    pak_dir = os.path.join(*name.split('.')[:-1])
    files = [name.replace('.', os.sep) + '.pyx']
    for c_subdir in sorted(c_subdirs):
        path = os.path.join(pak_dir, c_subdir, '*.c')
        files += glob.glob(path)
    include_dirs = [] if None is include_dirs else include_dirs
    include_dirs.insert(0, 'solvcon')
    include_dirs.insert(0, os.path.join(pak_dir))
Ejemplo n.º 8
0
    # update arguments.
    ccshared = ' '.join(set(self.compiler_so) - set(self.compiler))
    compiler = ' '.join(it for it in self.compiler if it not in unwanted)
    old_compiler = self.compiler
    self.set_executables(
        compiler=compiler,
        compiler_so=compiler + ' ' + ccshared,
    )
    modified = self.compiler != old_compiler
    if modified and need_cxx and hasattr(self, 'compiler'):
        log.warn("#### %s ####### %s removed" % (self.compiler, unwanted))

    return

replace_method(CCompiler, 'customize', CCompiler_customize)


def make_cython_extension(
    name, c_subdirs, include_dirs=None, libraries=None, extra_compile_args=None
):
    pak_dir = os.path.join(*name.split('.')[:-1])
    files = [name.replace('.', os.sep) + '.pyx']
    for c_subdir in sorted(c_subdirs):
        path = os.path.join(pak_dir, c_subdir, '*.c')
        files += glob.glob(path)
    include_dirs = [] if None is include_dirs else include_dirs
    include_dirs.insert(0, 'solvcon')
    include_dirs.insert(0, os.path.join(pak_dir))
    libraries = [] if None is libraries else libraries
    libraries = (['scotchmetis', 'scotch', 'scotcherr', 'scotcherrexit']