Пример #1
0
 def test_numpy_abs(self, dtype):
     if (sys.platform == "cygwin" and dtype == np.clongdouble
             and (_pep440.parse(platform.release().split("-")[0]) <
                  _pep440.Version("3.3.0"))):
         pytest.xfail(
             reason="absl is computed in double precision on cygwin < 3.3")
     self._test_abs_func(np.abs, dtype)
Пример #2
0
    def _needs_gcc_c99_flag(obj):
        if obj.compiler.compiler_type != 'unix':
            return False

        cc = obj.compiler.compiler[0]
        if "gcc" not in cc:
            return False

        # will print something like '4.2.1\n'
        out = subprocess.run([cc, '-dumpversion'],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             universal_newlines=True)
        # -std=c99 is default from this version on
        if _pep440.parse(out.stdout) >= _pep440.Version('5.0'):
            return False
        return True
Пример #3
0
def generate_cython():
    # Check Cython version
    from numpy.compat import _pep440
    try:
        # try the cython in the installed python first (somewhat related to
        # scipy/scipy#2397)
        import Cython
        from Cython.Compiler.Version import version as cython_version
    except ImportError as e:
        # The `cython` command need not point to the version installed in the
        # Python running this script, so raise an error to avoid the chance of
        # using the wrong version of Cython.
        msg = 'Cython needs to be installed in Python as a module'
        raise OSError(msg) from e
    else:
        # Note: keep in sync with that in pyproject.toml
        # Update for Python 3.10
        required_version = '0.29.24'

        if _pep440.parse(cython_version) < _pep440.Version(required_version):
            cython_path = Cython.__file__
            msg = 'Building NumPy requires Cython >= {}, found {} at {}'
            msg = msg.format(required_version, cython_version, cython_path)
            raise RuntimeError(msg)

    # Process files
    cwd = os.path.abspath(os.path.dirname(__file__))
    print("Cythonizing sources")
    for d in ('random', ):
        p = subprocess.call([
            sys.executable,
            os.path.join(cwd, 'tools', 'cythonize.py'), 'numpy/{0}'.format(d)
        ],
                            cwd=cwd)
        if p != 0:
            raise RuntimeError("Running cythonize failed!")
Пример #4
0
except ImportError:
    numba = None

try:
    import cython
    from Cython.Compiler.Version import version as cython_version
except ImportError:
    cython = None
else:
    from numpy.compat import _pep440
    # Cython 0.29.24 is required for Python 3.10 and there are
    # other fixes in the 0.29 series that are needed even for earlier
    # Python versions.
    # Note: keep in sync with the one in pyproject.toml
    required_version = '0.29.24'
    if _pep440.parse(cython_version) < _pep440.Version(required_version):
        # too old or wrong cython, skip the test
        cython = None


@pytest.mark.skipif(cython is None, reason="requires cython")
@pytest.mark.slow
def test_cython(tmp_path):
    srcdir = os.path.join(os.path.dirname(__file__), '..')
    shutil.copytree(srcdir, tmp_path / 'random')
    # build the examples and "install" them into a temporary directory
    build_dir = tmp_path / 'random' / '_examples' / 'cython'
    subprocess.check_call(
        [
            sys.executable,
            'setup.py',