diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml index 252225c..c448a02 100644 --- a/.github/workflows/dist.yml +++ b/.github/workflows/dist.yml @@ -18,20 +18,16 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, windows-2019, macos-10.15] + os: [ubuntu-latest, windows-latest, macos-latest] steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Build wheels and test - uses: pypa/cibuildwheel@v2.8.0 - env: - # disable builds for PyPy, all 32-bit, musl - CIBW_SKIP: "pp* *-win32 *-manylinux_i686 *-musllinux*" - # testing - CIBW_TEST_REQUIRES: pytest pandas - CIBW_TEST_COMMAND: pytest {package}/tests + uses: pypa/cibuildwheel@v2.14.1 - name: Upload artifacts uses: actions/upload-artifact@v3 @@ -44,13 +40,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - - name: Install dependencies - # this makes cythonize work so .c files are included in the sdist - run: python -m pip install numpy cython + with: + fetch-depth: 0 - name: Build sdist - run: python setup.py sdist + run: pipx run build --sdist - uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9704009..013ee6b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] os: [ubuntu-latest, windows-latest, macos-latest] steps: diff --git a/.gitignore b/.gitignore index 51d6cef..72e30a6 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ build/ _bspl.*.pyd _bspl.c docs/auto_* +ndsplines/version.py diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index a36a0ea..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,4 +0,0 @@ -include readme.rst -include LICENSE -include ndsplines/*.h -include ndsplines/*.pyx diff --git a/ndsplines/__init__.py b/ndsplines/__init__.py index e6f1b0e..5f99492 100644 --- a/ndsplines/__init__.py +++ b/ndsplines/__init__.py @@ -23,10 +23,7 @@ def set_impl(name): evaluate_spline = _bspl.evaluate_spline _impl = "cython" except ImportError: - raise ImportError( - "Can't use cython implementation. Install cython then reinstall " - "ndsplines." - ) + raise ImportError("Cython implementation not installed.") elif name == "numpy": from . import _npy_bspl diff --git a/ndsplines/version.py b/ndsplines/version.py deleted file mode 100644 index a39aba6..0000000 --- a/ndsplines/version.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "0.1.5dev" diff --git a/pyproject.toml b/pyproject.toml index 04e9fc3..93a3198 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,51 @@ +[project] +name = "ndsplines" +dynamic = ["version"] +description = "Multi-dimensional splines" +readme = "readme.rst" +authors = [ + {name = "Benjamin Margolis", email = "ben@sixpearls.com"}, +] +maintainers = [ + {name = "Kenneth Lyons", email = "ixjlyons@gmail.com"}, +] +license = {file = "LICENSE"} +classifiers=[ + "License :: OSI Approved :: BSD License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] +requires-python = ">=3.7" + +dependencies = ["numpy", "scipy"] + +[project.optional-dependencies] +test = ["pytest", "pandas"] +examples = ["matplotlib"] +docs = ["sphinx", "sphinx_gallery"] + [build-system] +build-backend = "setuptools.build_meta" requires = [ - "setuptools>=42", - "wheel", - "Cython", + "setuptools>=45", + "setuptools_scm[toml]", + "cython", "oldest-supported-numpy", ] -build-backend = "setuptools.build_meta" + +[tool.setuptools] +# autodiscovery doesn't exclude paper/ +packages = ["ndsplines"] + +[tool.setuptools_scm] +write_to = "ndsplines/version.py" + +[tool.cibuildwheel] +# disable builds for PyPy, all 32-bit, musl +skip = "pp* *-win32 *-manylinux_i686 *-musllinux*" +test-extras = ["test"] +test-command = "pytest {project}/tests" diff --git a/readme.rst b/readme.rst index 0a70999..1981e34 100644 --- a/readme.rst +++ b/readme.rst @@ -43,15 +43,15 @@ Install ndsplines with pip:: $ pip install ndsplines -or from source:: +Wheels are provided for a range of Python versions and platforms, so no +compilation is required to get the better-performing Cython-based implementation +in many cases. - $ git clone https://github.com/kb-press/ndsplines - $ cd ndsplines - $ pip install . +If no matching wheel is found, pip will install build dependencies and attempt +to compile the Cython-based extension module. If this is not desired, set the +environment variable ``NDSPLINES_NUMPY_ONLY=1``, e.g.:: -Reasonably recent versions of ``pip`` will automatically pull Cython and NumPy -to build the compiled implementation. If you need to install ndsplines without -compiling, try ``python setup.py install`` instead of using ``pip install``. + $ NDSPLINES_NUMPY_ONLY=1 pip install ndsplines Usage ----- @@ -82,7 +82,7 @@ evaluate it over a denser mesh. .. code:: python - # create the interpolating splane + # create the interpolating spline interp = ndsplines.make_interp_spline(gridxy, meshf) # generate denser grid of independent variables to interpolate diff --git a/setup.py b/setup.py index d2a849d..cdc526f 100644 --- a/setup.py +++ b/setup.py @@ -1,80 +1,22 @@ import os -from setuptools import setup, Extension -try: - import numpy -except ImportError: - use_numpy = False -else: - use_numpy = True +import numpy +from Cython.Build import cythonize +from setuptools import Extension, setup -try: - from Cython.Build import cythonize -except ImportError: - use_cython = False -else: - use_cython = True +numpy_only = os.environ.get("NDSPLINES_NUMPY_ONLY") == "1" -name = "ndsplines" -extname = '_bspl' +ext_modules = [] -if use_cython and use_numpy: - extensions = cythonize([ - Extension("{}.{}".format(name, extname), - [os.path.join(name, "{}.pyx".format(extname))], - include_dirs=[numpy.get_include()], - depends=[os.path.join(name, "{}.h".format(extname))]), - ]) - -elif use_numpy: - extensions = [ - Extension("{}.{}".format(name, extname), - [os.path.join(name, "{}.c".format(extname))], - include_dirs=[numpy.get_include()], - depends=[os.path.join(name, "{}.h".format(extname)),], - optional=True) - ] -else: - extensions = [] - -exec(open('ndsplines/version.py').read()) - -here = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(here, 'readme.rst'), encoding='utf-8') as f: - long_description = f.read() - -long_description = long_description.replace( - "https://ndsplines.readthedocs.io/en/latest/", - "https://ndsplines.readthedocs.io/en/v{}/".format( - '.'.join(__version__.split('.')[:3]) +if not numpy_only: + ext_modules.extend( + cythonize( + Extension( + "ndsplines._bspl", + [os.path.join("ndsplines", "_bspl.pyx")], + include_dirs=["ndsplines", numpy.get_include()], + ) + ) ) -) -setup( - name=name, - version=__version__, - description="Multi-dimensional splines", - url="https://github.com/kb-press/ndsplines", - author="Benjamin Margolis", - author_email="ben@sixpearls.com", - classifiers=[ - 'License :: OSI Approved :: BSD License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - ], - packages=["ndsplines"], - ext_modules=extensions, - long_description=long_description, - license='BSD', - install_requires=['numpy', 'scipy'], - extras_require={ - 'test': ['pytest', 'pandas'], - 'examples': ['matplotlib'], - 'build_ext': ['cython'], - 'docs': ['sphinx', 'sphinx_gallery'] - }, -) +setup(ext_modules=ext_modules)