Python Cython.__version__() Examples

The following are 16 code examples of Cython.__version__(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Cython , or try the search function .
Example #1
Source File: setup.py    From pulse2percept with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_numpy_status():
    """
    Returns a dictionary containing a boolean specifying whether NumPy
    is up-to-date, along with the version string (empty string if
    not installed).
    """
    numpy_status = {}
    try:
        import numpy
        numpy_version = numpy.__version__
        numpy_status['up_to_date'] = parse_version(
            numpy_version) >= parse_version(NUMPY_MIN_VERSION)
        numpy_status['version'] = numpy_version
    except ImportError:
        traceback.print_exc()
        numpy_status['up_to_date'] = False
        numpy_status['version'] = ""
    return numpy_status 
Example #2
Source File: setup.py    From pulse2percept with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_cython_status():
    """
    Returns a dictionary containing a boolean specifying whether Cython is
    up-to-date, along with the version string (empty string if not installed).
    """
    cython_status = {}
    try:
        import Cython
        from Cython.Build import cythonize
        cython_version = Cython.__version__
        cython_status['up_to_date'] = parse_version(
            cython_version) >= parse_version(CYTHON_MIN_VERSION)
        cython_status['version'] = cython_version
    except ImportError:
        traceback.print_exc()
        cython_status['up_to_date'] = False
        cython_status['version'] = ""
    return cython_status 
Example #3
Source File: setup.py    From scikit-multiflow with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def maybe_cythonize_extensions(top_path, config):
    """Tweaks for building extensions between release and development mode."""
    is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))
    if is_release:
        build_from_c_and_cpp_files(config.ext_modules)
    else:
        message = ('Please install cython with a version >= {0} in order '
                   'to build a scikit-multiflow development version.').format(
                       CYTHON_MIN_VERSION)
        try:
            import Cython
            if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
                message += ' Your version of Cython was {0}.'.format(
                    Cython.__version__)
                raise ValueError(message)
            from Cython.Build import cythonize
        except ImportError as exc:
            exc.args += (message,)
            raise
        config.ext_modules = cythonize(config.ext_modules,
                                       compiler_directives={'language_level': 3}) 
Example #4
Source File: __init__.py    From Splunking-Crime with GNU Affero General Public License v3.0 6 votes vote down vote up
def maybe_cythonize_extensions(top_path, config):
    """Tweaks for building extensions between release and development mode."""
    is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))

    if is_release:
        build_from_c_and_cpp_files(config.ext_modules)
    else:
        message = ('Please install cython with a version >= {0} in order '
                   'to build a scikit-learn development version.').format(
                       CYTHON_MIN_VERSION)
        try:
            import Cython
            if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
                message += ' Your version of Cython was {0}.'.format(
                    Cython.__version__)
                raise ValueError(message)
            from Cython.Build import cythonize
        except ImportError as exc:
            exc.args += (message,)
            raise

        config.ext_modules = cythonize(config.ext_modules) 
Example #5
Source File: __init__.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def maybe_cythonize_extensions(top_path, config):
    """Tweaks for building extensions between release and development mode."""
    is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))

    if is_release:
        build_from_c_and_cpp_files(config.ext_modules)
    else:
        message = ('Please install cython with a version >= {0} in order '
                   'to build a scikit-learn development version.').format(
                       CYTHON_MIN_VERSION)
        try:
            import Cython
            if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
                message += ' Your version of Cython was {0}.'.format(
                    Cython.__version__)
                raise ValueError(message)
            from Cython.Build import cythonize
        except ImportError as exc:
            exc.args += (message,)
            raise

        config.ext_modules = cythonize(config.ext_modules) 
Example #6
Source File: setup.py    From tenpy with GNU General Public License v3.0 5 votes vote down vote up
def write_version_py(full_version, git_rev, filename='tenpy/_version.py'):
    """Write the version during compilation to disc."""
    content = """\
# THIS FILE IS GENERATED FROM setup.py
# thus, it contains the version during compilation
# Copyright 2018-2020 TeNPy Developers, GNU GPLv3
version = '{version!s}'
short_version = 'v' + version
released = {released!s}
full_version = '{full_version!s}'
git_revision = '{git_rev!s}'
numpy_version = '{numpy_ver!s}'
cython_version = '{cython_ver!s}'
"""
    try:
        import Cython
        cython_ver = Cython.__version__
    except:
        cython_ver = "(not available)"
    content = content.format(version=VERSION,
                             full_version=full_version,
                             released=RELEASED,
                             git_rev=git_rev,
                             numpy_ver=numpy.version.full_version,
                             cython_ver=cython_ver)
    with open(filename, 'w') as f:
        f.write(content)
    # done 
Example #7
Source File: __init__.py    From pmdarima with MIT License 5 votes vote down vote up
def _check_cython_version():
    message = 'Please install Cython with a version >= {0} in order ' \
              'to build a pmdarima distribution from source.' \
              .format(CYTHON_MIN_VERSION)
    try:
        import Cython
    except ModuleNotFoundError:
        # Re-raise with more informative error message instead:
        raise ModuleNotFoundError(message)

    if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
        message += (' The current version of Cython is {} installed in {}.'
                    .format(Cython.__version__, Cython.__path__))
        raise ValueError(message) 
Example #8
Source File: __init__.py    From pmdarima with MIT License 5 votes vote down vote up
def cythonize_extensions(top_path, config):
    """Check that a recent Cython is available and cythonize extensions"""
    _check_cython_version()
    from Cython.Build import cythonize

    # Fast fail before cythonization if compiler fails compiling basic test
    # code even without OpenMP
    basic_check_build()

    # check simple compilation with OpenMP. If it fails scikit-learn will be
    # built without OpenMP and the test test_openmp_supported in the test suite
    # will fail.
    # `check_openmp_support` compiles a small test program to see if the
    # compilers are properly configured to build with OpenMP. This is expensive
    # and we only want to call this function once.
    # The result of this check is cached as a private attribute on the sklearn
    # module (only at build-time) to be used twice:
    # - First to set the value of SKLEARN_OPENMP_PARALLELISM_ENABLED, the
    #   cython build-time variable passed to the cythonize() call.
    # - Then in the build_ext subclass defined in the top-level setup.py file
    #   to actually build the compiled extensions with OpenMP flags if needed.

    n_jobs = 1
    with contextlib.suppress(ImportError):
        import joblib
        if LooseVersion(joblib.__version__) > LooseVersion("0.13.0"):
            # earlier joblib versions don't account for CPU affinity
            # constraints, and may over-estimate the number of available
            # CPU particularly in CI (cf loky#114)
            n_jobs = joblib.cpu_count()

    config.ext_modules = cythonize(
        config.ext_modules,
        nthreads=n_jobs,
        compiler_directives={'language_level': 3}) 
Example #9
Source File: __init__.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def maybe_cythonize_extensions(top_path, config):
    """Tweaks for building extensions between release and development mode."""
    with_openmp = check_openmp_support()

    is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))

    if is_release:
        build_from_c_and_cpp_files(config.ext_modules)
    else:
        message = ('Please install cython with a version >= {0} in order '
                   'to build a scikit-learn development version.').format(
                       CYTHON_MIN_VERSION)
        try:
            import Cython
            if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
                message += ' Your version of Cython was {0}.'.format(
                    Cython.__version__)
                raise ValueError(message)
            from Cython.Build import cythonize
        except ImportError as exc:
            exc.args += (message,)
            raise

        config.ext_modules = cythonize(
            config.ext_modules,
            compile_time_env={'SKLEARN_OPENMP_SUPPORTED': with_openmp},
            compiler_directives={'language_level': 3}) 
Example #10
Source File: setuputils.py    From pyCGNS with GNU Lesser General Public License v2.1 5 votes vote down vote up
def updateVersionInFile(filename, cfg):
    f = open('{}/revision.tmp'.format(cfg.PRODUCTION_DIR))
    r = int(f.readlines()[0][:-1])
    REVISION = r
    f = open(filename, 'r')
    l = f.readlines()
    f.close()
    vver = '@@UPDATEVERSION@@'
    vrel = '@@UPDATERELEASE@@'
    vrev = '@@UPDATEREVISION@@'
    r = []
    for ll in l:
        rl = ll
        if (ll[-len(vver) - 1:-1] == vver):
            rl = '__version__=%s # %s\n' % (MAJOR_VERSION, vver)
        if (ll[-len(vrel) - 1:-1] == vrel):
            rl = '__release__=%s # %s\n' % (MINOR_VERSION, vrel)
        if (ll[-len(vrev) - 1:-1] == vrev):
            ACTUALREV = REVISION
            rl = '__revision__=%s # %s\n' % (ACTUALREV, vrev)
        r += [rl]
    f = open(filename, 'w+')
    f.writelines(r)
    f.close()
    cfg.REVISION = REVISION

# --------------------------------------------------------------------
# Clean target redefinition - force clean everything 
Example #11
Source File: __init__.py    From skoot with MIT License 5 votes vote down vote up
def maybe_cythonize_extensions(top_path, config):
    """Tweaks for building extensions between release and development mode."""
    is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))

    if is_release:
        print("Release detected--building from source files")
        build_from_c_f_and_cpp_files(config.ext_modules)
    else:
        print("Development build detected--building from .pyx & .pyf")
        message = ('Please install cython with a version >= {0} in order '
                   'to build a {1} development version.').format(
                       CYTHON_MIN_VERSION, DEFAULT_ROOT)
        try:
            import Cython
            loose_cython_ver = LooseVersion(Cython.__version__)  # type: str
            if loose_cython_ver < CYTHON_MIN_VERSION:
                message += ' Your version of Cython was {0}.'.format(
                    Cython.__version__)
                raise ValueError(message)
            from Cython.Build import cythonize
        except ImportError as exc:
            exc.args += (message,)
            raise

        # cythonize or fortranize...
        config.ext_modules = cythonize(config.ext_modules) 
Example #12
Source File: __init__.py    From sktime with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def maybe_cythonize_extensions(top_path, config):
    """Tweaks for building extensions between release and development mode."""
    with_openmp = check_openmp_support()

    is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))

    if is_release:
        build_from_c_and_cpp_files(config.ext_modules)
    else:
        message = ('Please install Cython with a version >= {0} in order '
                   'to build a sktime development version.').format(
            CYTHON_MIN_VERSION)
        try:
            import Cython
            if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
                message += ' Your version of Cython was {0}.'.format(
                    Cython.__version__)
                raise ValueError(message)
            from Cython.Build import cythonize
        except ImportError as exc:
            exc.args += (message,)
            raise

        n_jobs = 1
        with contextlib.suppress(ImportError):
            import joblib
            if LooseVersion(joblib.__version__) > LooseVersion("0.13.0"):
                # earlier joblib versions don't account for CPU affinity
                # constraints, and may over-estimate the number of available
                # CPU particularly in CI (cf loky#114)
                n_jobs = joblib.effective_n_jobs()

        config.ext_modules = cythonize(
            config.ext_modules,
            nthreads=n_jobs,
            compile_time_env={'SKTIME_OPENMP_SUPPORTED': with_openmp},
            compiler_directives={'language_level': 3}
        ) 
Example #13
Source File: setup.py    From edgedb-python with Apache License 2.0 5 votes vote down vote up
def _fix_version(self, filename):
        # Replace edgedb.__version__ with the actual version
        # of the distribution (possibly inferred from git).

        with open(str(filename)) as f:
            content = f.read()

        version_re = r"(.*__version__\s*=\s*)'[^']+'(.*)"
        repl = r"\1'{}'\2".format(self.distribution.metadata.version)
        content = re.sub(version_re, repl, content)

        with open(str(filename), 'w') as f:
            f.write(content) 
Example #14
Source File: setup.py    From asyncpg with Apache License 2.0 5 votes vote down vote up
def _fix_version(self, filename):
        # Replace asyncpg.__version__ with the actual version
        # of the distribution (possibly inferred from git).

        with open(str(filename)) as f:
            content = f.read()

        version_re = r"(.*__version__\s*=\s*)'[^']+'(.*)"
        repl = r"\1'{}'\2".format(self.distribution.metadata.version)
        content = re.sub(version_re, repl, content)

        with open(str(filename), 'w') as f:
            f.write(content) 
Example #15
Source File: setup.py    From edgedb with Apache License 2.0 4 votes vote down vote up
def finalize_options(self):
        # finalize_options() may be called multiple times on the
        # same command object, so make sure not to override previously
        # set options.
        if getattr(self, '_initialized', False):
            return

        import pkg_resources

        # Double check Cython presence in case setup_requires
        # didn't go into effect (most likely because someone
        # imported Cython before setup_requires injected the
        # correct egg into sys.path.
        try:
            import Cython
        except ImportError:
            raise RuntimeError(
                'please install {} to compile edgedb from source'.format(
                    CYTHON_DEPENDENCY))

        cython_dep = pkg_resources.Requirement.parse(CYTHON_DEPENDENCY)
        if Cython.__version__ not in cython_dep:
            raise RuntimeError(
                'edgedb requires {}, got Cython=={}'.format(
                    CYTHON_DEPENDENCY, Cython.__version__
                ))

        from Cython.Build import cythonize

        directives = {
            'language_level': '3'
        }

        if self.cython_directives:
            for directive in self.cython_directives.split(','):
                k, _, v = directive.partition('=')
                if v.lower() == 'false':
                    v = False
                if v.lower() == 'true':
                    v = True

                directives[k] = v

        self.distribution.ext_modules[:] = cythonize(
            self.distribution.ext_modules,
            compiler_directives=directives,
            annotate=self.cython_annotate,
            include_path=["edb/server/pgproto/"])

        super(build_ext, self).finalize_options() 
Example #16
Source File: setup.py    From httptools with MIT License 4 votes vote down vote up
def finalize_options(self):
        # finalize_options() may be called multiple times on the
        # same command object, so make sure not to override previously
        # set options.
        if getattr(self, '_initialized', False):
            return

        need_cythonize = self.cython_always
        cfiles = {}

        for extension in self.distribution.ext_modules:
            for i, sfile in enumerate(extension.sources):
                if sfile.endswith('.pyx'):
                    prefix, ext = os.path.splitext(sfile)
                    cfile = prefix + '.c'

                    if os.path.exists(cfile) and not self.cython_always:
                        extension.sources[i] = cfile
                    else:
                        if os.path.exists(cfile):
                            cfiles[cfile] = os.path.getmtime(cfile)
                        else:
                            cfiles[cfile] = 0
                        need_cythonize = True

        if need_cythonize:
            try:
                import Cython
            except ImportError:
                raise RuntimeError(
                    'please install Cython to compile httptools from source')

            if Cython.__version__ < '0.29':
                raise RuntimeError(
                    'httptools requires Cython version 0.29 or greater')

            from Cython.Build import cythonize

            directives = {}
            if self.cython_directives:
                for directive in self.cython_directives.split(','):
                    k, _, v = directive.partition('=')
                    if v.lower() == 'false':
                        v = False
                    if v.lower() == 'true':
                        v = True

                    directives[k] = v

            self.distribution.ext_modules[:] = cythonize(
                self.distribution.ext_modules,
                compiler_directives=directives,
                annotate=self.cython_annotate)

        super().finalize_options()

        self._initialized = True