diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2020-07-29 18:15:13 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-29 18:15:13 -0600 |
commit | b46e5d3ecb9dcc6e167579f5e5cc0978a8e59e93 (patch) | |
tree | 0b9c70ffbc1670833c6d669c904d92a995b6154f | |
parent | 6f673997393448454370b3d70043adcd3428e42e (diff) | |
parent | cf5e7665fdd764a6647f2b62d2740bb431180794 (diff) | |
download | numpy-b46e5d3ecb9dcc6e167579f5e5cc0978a8e59e93.tar.gz |
Merge pull request #16974 from mattip/pypy-win32
TST: Add pypy win32 CI testing.
-rw-r--r-- | azure-pipelines.yml | 5 | ||||
-rw-r--r-- | azure-steps-windows.yml | 38 | ||||
-rw-r--r-- | numpy/core/tests/test_memmap.py | 7 | ||||
-rw-r--r-- | numpy/distutils/mingw32ccompiler.py | 24 | ||||
-rw-r--r-- | numpy/lib/tests/test_format.py | 41 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 9 | ||||
-rw-r--r-- | numpy/testing/_private/utils.py | 3 |
7 files changed, 92 insertions, 35 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 51f30c263..cdff56e1a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -217,6 +217,11 @@ stages: BITS: 64 NPY_USE_BLAS_ILP64: '1' OPENBLAS_SUFFIX: '64_' + PyPy36-32bit: + PYTHON_VERSION: 'PyPy3.6' + PYTHON_ARCH: 'x32' + TEST_MODE: fast + BITS: 32 steps: - template: azure-steps-windows.yml - job: Linux_PyPy3 diff --git a/azure-steps-windows.yml b/azure-steps-windows.yml index 4c4e1d177..28762f5d9 100644 --- a/azure-steps-windows.yml +++ b/azure-steps-windows.yml @@ -4,10 +4,31 @@ steps: versionSpec: $(PYTHON_VERSION) addToPath: true architecture: $(PYTHON_ARCH) -- script: python -m pip install --upgrade pip + condition: not(contains(variables['PYTHON_VERSION'], 'PyPy')) +- powershell: | + $url = "http://buildbot.pypy.org/nightly/py3.6/pypy-c-jit-latest-win32.zip" + $output = "pypy.zip" + $wc = New-Object System.Net.WebClient + $wc.DownloadFile($url, $output) + echo "downloaded $url to $output" + mkdir pypy3 + Expand-Archive $output -DestinationPath pypy3 + move pypy3/pypy-c-*/* pypy3 + cp pypy3/pypy3.exe pypy3/python.exe + $pypypath = Join-Path (Get-Item .).FullName pypy3 + $env:Path = $pypypath + ";" + $env:Path + setx PATH $env:Path + python -mensurepip + echo "##vso[task.prependpath]$pypypath" + condition: contains(variables['PYTHON_VERSION'], 'PyPy') + displayName: "Install PyPy pre-release" + +- script: python -m pip install --upgrade pip wheel displayName: 'Install tools' + - script: python -m pip install -r test_requirements.txt displayName: 'Install dependencies; some are optional to avoid test skips' + - powershell: | $ErrorActionPreference = "Stop" # Download and get the path to "openblas.a". We cannot copy it @@ -16,7 +37,7 @@ steps: # since OPENBLAS will be picked up by the openblas discovery $target = $(python tools/openblas_support.py) mkdir openblas - echo Copying $target to openblas/openblas$env:OPENBLAS_SUFFIX.a + echo "Copying $target to openblas/openblas$env:OPENBLAS_SUFFIX.a" cp $target openblas/openblas$env:OPENBLAS_SUFFIX.a If ( Test-Path env:NPY_USE_BLAS_ILP64 ){ echo "##vso[task.setvariable variable=OPENBLAS64_]$pwd\openblas" @@ -27,35 +48,40 @@ steps: - powershell: | choco install -y mingw --forcex86 --force --version=7.3.0 + refreshenv displayName: 'Install 32-bit mingw for 32-bit builds' condition: eq(variables['BITS'], 32) # NOTE: for Windows builds it seems much more tractable to use runtests.py # vs. manual setup.py and then runtests.py for testing only + - powershell: | If ($(BITS) -eq 32) { $env:CFLAGS = "-m32" $env:LDFLAGS = "-m32" $env:PATH = "C:\\ProgramData\\chocolatey\\lib\\mingw\\tools\\install\\mingw$(BITS)\\bin;" + $env:PATH - refreshenv } python -c "from tools import openblas_support; openblas_support.make_init('numpy')" - pip wheel -v -v -v --no-build-isolation --no-use-pep517 --wheel-dir=dist . + python -m pip wheel -v -v -v --no-build-isolation --no-use-pep517 --wheel-dir=dist . ls dist -r | Foreach-Object { - pip install $_.FullName + python -m pip install $_.FullName } displayName: 'Build NumPy' + - bash: | pushd . && cd .. && target=$(python -c "import numpy, os; print(os.path.abspath(os.path.join(os.path.dirname(numpy.__file__), '.libs')))") && popd - pip download -d destination --only-binary :all: --no-deps numpy==1.14 + python -m pip download -d destination --only-binary :all: --no-deps numpy==1.14 cd destination && unzip numpy*.whl && cp numpy/.libs/*.dll $target ls $target displayName: 'Add extraneous & older DLL to numpy/.libs to probe DLL handling robustness' condition: eq(variables['PYTHON_VERSION'], '3.6') - script: pushd . && cd .. && python -c "from ctypes import windll; windll.kernel32.SetDefaultDllDirectories(0x00000800); import numpy" && popd displayName: 'For gh-12667; Windows DLL resolution' + condition: eq(variables['PYTHON_VERSION'], '3.6') + - script: python runtests.py -n --show-build-log --mode=$(TEST_MODE) -- -rsx --junitxml=junit/test-results.xml displayName: 'Run NumPy Test Suite' + - task: PublishTestResults@2 condition: succeededOrFailed() inputs: diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py index feef80ce8..a1e0c8f8f 100644 --- a/numpy/core/tests/test_memmap.py +++ b/numpy/core/tests/test_memmap.py @@ -11,7 +11,8 @@ from numpy import ( from numpy import arange, allclose, asarray from numpy.testing import ( - assert_, assert_equal, assert_array_equal, suppress_warnings + assert_, assert_equal, assert_array_equal, suppress_warnings, IS_PYPY, + break_cycles ) class TestMemmap: @@ -25,6 +26,10 @@ class TestMemmap: def teardown(self): self.tmpfp.close() + self.data = None + if IS_PYPY: + break_cycles() + break_cycles() shutil.rmtree(self.tempdir) def test_roundtrip(self): diff --git a/numpy/distutils/mingw32ccompiler.py b/numpy/distutils/mingw32ccompiler.py index 7cb6fadcc..3358695a8 100644 --- a/numpy/distutils/mingw32ccompiler.py +++ b/numpy/distutils/mingw32ccompiler.py @@ -8,6 +8,7 @@ Support code for building Python extensions on Windows. """ import os +import platform import sys import subprocess import re @@ -265,16 +266,19 @@ def find_python_dll(): # search in the file system for possible candidates major_version, minor_version = tuple(sys.version_info[:2]) - patterns = ['python%d%d.dll'] - - for pat in patterns: - dllname = pat % (major_version, minor_version) - print("Looking for %s" % dllname) - for folder in lib_dirs: - dll = os.path.join(folder, dllname) - if os.path.exists(dll): - return dll - + implementation = platform.python_implementation() + if implementation == 'CPython': + dllname = f'python{major_version}{minor_version}.dll' + elif implementation == 'PyPy': + dllname = f'libpypy{major_version}-c.dll' + else: + dllname = 'Unknown platform {implementation}' + print("Looking for %s" % dllname) + for folder in lib_dirs: + dll = os.path.join(folder, dllname) + if os.path.exists(dll): + return dll + raise ValueError("%s not found in %s" % (dllname, lib_dirs)) def dump_table(dll): diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py index 2dbaeb8cb..1bfd63bba 100644 --- a/numpy/lib/tests/test_format.py +++ b/numpy/lib/tests/test_format.py @@ -285,7 +285,7 @@ from io import BytesIO import numpy as np from numpy.testing import ( assert_, assert_array_equal, assert_raises, assert_raises_regex, - assert_warns + assert_warns, IS_PYPY, break_cycles ) from numpy.lib import format @@ -488,11 +488,8 @@ def test_memmap_roundtrip(): # Write it out normally and through mmap. nfn = os.path.join(tempdir, 'normal.npy') mfn = os.path.join(tempdir, 'memmap.npy') - fp = open(nfn, 'wb') - try: + with open(nfn, 'wb') as fp: format.write_array(fp, arr) - finally: - fp.close() fortran_order = ( arr.flags.f_contiguous and not arr.flags.c_contiguous) @@ -500,26 +497,29 @@ def test_memmap_roundtrip(): shape=arr.shape, fortran_order=fortran_order) ma[...] = arr del ma + if IS_PYPY: + break_cycles() # Check that both of these files' contents are the same. - fp = open(nfn, 'rb') - normal_bytes = fp.read() - fp.close() - fp = open(mfn, 'rb') - memmap_bytes = fp.read() - fp.close() + with open(nfn, 'rb') as fp: + normal_bytes = fp.read() + with open(mfn, 'rb') as fp: + memmap_bytes = fp.read() assert_equal_(normal_bytes, memmap_bytes) # Check that reading the file using memmap works. ma = format.open_memmap(nfn, mode='r') del ma + if IS_PYPY: + break_cycles() def test_compressed_roundtrip(): arr = np.random.rand(200, 200) npz_file = os.path.join(tempdir, 'compressed.npz') np.savez_compressed(npz_file, arr=arr) - arr1 = np.load(npz_file)['arr'] + with np.load(npz_file) as npz: + arr1 = npz['arr'] assert_array_equal(arr, arr1) @@ -545,7 +545,8 @@ def test_load_padded_dtype(dt): arr[i] = i + 5 npz_file = os.path.join(tempdir, 'aligned.npz') np.savez(npz_file, arr=arr) - arr1 = np.load(npz_file)['arr'] + with np.load(npz_file) as npz: + arr1 = npz['arr'] assert_array_equal(arr, arr1) @@ -610,8 +611,8 @@ def test_pickle_disallow(): allow_pickle=False, encoding='latin1') path = os.path.join(data_dir, 'py2-objarr.npz') - f = np.load(path, allow_pickle=False, encoding='latin1') - assert_raises(ValueError, f.__getitem__, 'x') + with np.load(path, allow_pickle=False, encoding='latin1') as f: + assert_raises(ValueError, f.__getitem__, 'x') path = os.path.join(tempdir, 'pickle-disabled.npy') assert_raises(ValueError, np.save, path, np.array([None], dtype=object), @@ -713,6 +714,8 @@ def test_version_2_0_memmap(): shape=d.shape, version=(2, 0)) ma[...] = d del ma + if IS_PYPY: + break_cycles() with warnings.catch_warnings(record=True) as w: warnings.filterwarnings('always', '', UserWarning) @@ -721,9 +724,14 @@ def test_version_2_0_memmap(): assert_(w[0].category is UserWarning) ma[...] = d del ma + if IS_PYPY: + break_cycles() ma = format.open_memmap(tf, mode='r') assert_array_equal(ma, d) + del ma + if IS_PYPY: + break_cycles() def test_write_version(): @@ -925,7 +933,8 @@ def test_empty_npz(): # Test for gh-9989 fname = os.path.join(tempdir, "nothing.npz") np.savez(fname) - np.load(fname) + with np.load(fname) as nps: + pass def test_unicode_field_names(): diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 959e63fa2..a23c6b007 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -24,7 +24,8 @@ from numpy.ma.testutils import assert_equal from numpy.testing import ( assert_warns, assert_, assert_raises_regex, assert_raises, assert_allclose, assert_array_equal, temppath, tempdir, IS_PYPY, - HAS_REFCOUNT, suppress_warnings, assert_no_gc_cycles, assert_no_warnings + HAS_REFCOUNT, suppress_warnings, assert_no_gc_cycles, assert_no_warnings, + break_cycles ) from numpy.testing._private.utils import requires_memory @@ -2387,6 +2388,9 @@ class TestPathUsage: assert_array_equal(data, a) # close the mem-mapped file del data + if IS_PYPY: + break_cycles() + break_cycles() def test_save_load_memmap_readwrite(self): # Test that pathlib.Path instances can be written mem-mapped. @@ -2398,6 +2402,9 @@ class TestPathUsage: a[0][0] = 5 b[0][0] = 5 del b # closes the file + if IS_PYPY: + break_cycles() + break_cycles() data = np.load(path) assert_array_equal(data, a) diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 3827b7505..4fc22dceb 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -2403,7 +2403,8 @@ def break_cycles(): if IS_PYPY: # interpreter runs now, to call deleted objects' __del__ methods gc.collect() - # one more, just to make sure + # two more, just to make sure + gc.collect() gc.collect() |