From bd60daaea9bc4c38572098202c0934f87db8ba90 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Fri, 20 May 2022 14:06:28 -0500 Subject: [PATCH] Make numpy dependency optional --- .github/workflows/ci.yml | 15 +++++++++++++++ .gitlab-ci.yml | 13 +++++++++++++ setup.py | 5 ++++- test/test_pytools.py | 8 ++++++-- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74193dd..0a3401a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,6 +89,21 @@ jobs: curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/build-and-test-py-project.sh . ./build-and-test-py-project.sh + pytest_nonumpy: + name: Pytest without Numpy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: "Main Script" + run: | + NO_DOCTESTS=1 + curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/build-and-test-py-project.sh + . ./build-and-test-py-project.sh + #examples: # name: Examples Py3 # runs-on: ubuntu-latest diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 454e5c2..0b4f552 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,6 +18,19 @@ Pytest: reports: junit: test/pytest.xml +Pytest without Numpy: + script: | + NO_DOCTESTS=1 + curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/build-and-test-py-project.sh + . ./build-and-test-py-project.sh + tags: + - python3 + except: + - tags + artifacts: + reports: + junit: test/pytest.xml + # Examples: # script: | # EXTRA_INSTALL="numpy pymbolic" diff --git a/setup.py b/setup.py index 4a23c67..e9c3bd3 100644 --- a/setup.py +++ b/setup.py @@ -38,13 +38,16 @@ setup(name="pytools", install_requires=[ "platformdirs>=2.2.0", - "numpy>=1.6.0", "dataclasses>=0.7;python_version<='3.6'", "typing_extensions>=4.0; python_version<'3.11'", ], package_data={"pytools": ["py.typed"]}, + extras_require={ + "numpy": ["numpy>=1.6.0"], + }, + author="Andreas Kloeckner", url="http://pypi.python.org/pypi/pytools", author_email="inform@tiker.net", diff --git a/test/test_pytools.py b/test/test_pytools.py index de2c196..cf55eac 100644 --- a/test/test_pytools.py +++ b/test/test_pytools.py @@ -273,7 +273,7 @@ def test_find_module_git_revision(): def test_reshaped_view(): import pytools - import numpy as np + np = pytest.importorskip("numpy") a = np.zeros((10, 2)) b = a.T @@ -319,6 +319,8 @@ def test_table(): def test_eoc(): + np = pytest.importorskip("numpy") + from pytools.convergence import EOCRecorder eoc = EOCRecorder() @@ -397,6 +399,8 @@ class FakeArray: def test_make_obj_array_iteration(): + pytest.importorskip("numpy") + from pytools.obj_array import make_obj_array make_obj_array([FakeArray()]) @@ -624,7 +628,7 @@ def test_sphere_sampling(sampling, visualize=False): else: raise ValueError(f"unknown sampling method: '{sampling}'") - import numpy as np + np = pytest.importorskip("numpy") points = sampling_func(npoints) assert np.all(np.linalg.norm(points, axis=0) < radius + 1.0e-15) -- GitLab