From f8f11590abd1efc98bdcf2f70902f95bf3092ef0 Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 1 Sep 2023 00:11:56 -0700 Subject: [PATCH 1/8] Maintenance improvements - Migrate almost everything to pyproject.toml - Use setuptools_scm for versioning - Rely on modern (PEP 518) build system dependencies, simplifies extension module setup significantly - Expose environment variable to disable building cython impl if needed --- .github/workflows/dist.yml | 16 ++----- .github/workflows/test.yml | 2 +- MANIFEST.in | 4 -- ndsplines/__init__.py | 5 +-- ndsplines/version.py | 5 ++- pyproject.toml | 50 ++++++++++++++++++++-- readme.rst | 16 +++---- setup.py | 88 +++++++------------------------------- 8 files changed, 79 insertions(+), 107 deletions(-) delete mode 100644 MANIFEST.in diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml index 252225c..e7351e4 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 - name: Upload artifacts uses: actions/upload-artifact@v3 @@ -45,12 +41,8 @@ jobs: - 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 - - 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/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 index a39aba6..e6d09cb 100644 --- a/ndsplines/version.py +++ b/ndsplines/version.py @@ -1 +1,4 @@ -__version__ = "0.1.5dev" +# file generated by setuptools_scm +# don't change, don't track in version control +__version__ = version = '0.1.5.dev8+ga380339.d20230901' +__version_tuple__ = version_tuple = (0, 1, 5, 'dev8', 'ga380339.d20230901') diff --git a/pyproject.toml b/pyproject.toml index 04e9fc3..69c59ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,50 @@ +[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", +] + +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 {package}/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) From 3e9d4df7f10f87cabe4fdea36f8ec3a0879a5685 Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 1 Sep 2023 00:43:08 -0700 Subject: [PATCH 2/8] Remove and ignore version.py --- .gitignore | 1 + ndsplines/version.py | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 ndsplines/version.py 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/ndsplines/version.py b/ndsplines/version.py deleted file mode 100644 index e6d09cb..0000000 --- a/ndsplines/version.py +++ /dev/null @@ -1,4 +0,0 @@ -# file generated by setuptools_scm -# don't change, don't track in version control -__version__ = version = '0.1.5.dev8+ga380339.d20230901' -__version_tuple__ = version_tuple = (0, 1, 5, 'dev8', 'ga380339.d20230901') From c7174f232f5058ea755e88fbcde93904691a81d0 Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 1 Sep 2023 00:55:48 -0700 Subject: [PATCH 3/8] Typo fix in test-command --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 69c59ba..c24517f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,4 +47,4 @@ write_to = "ndsplines/version.py" # disable builds for PyPy, all 32-bit, musl skip = "pp* *-win32 *-manylinux_i686 *-musllinux*" test-extras = "test" -test-command = "pytest {package}/tests" +test-command = "pytest {project}/tests" From dc3ae4d74a0aea8eeb37014d57899a1b36c09e02 Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 1 Sep 2023 07:36:52 -0700 Subject: [PATCH 4/8] Typo fix --- .github/workflows/dist.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml index e7351e4..dc43e92 100644 --- a/.github/workflows/dist.yml +++ b/.github/workflows/dist.yml @@ -24,7 +24,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - fetch_depth: 0 + fetch-depth: 0 - name: Build wheels and test uses: pypa/cibuildwheel@v2.8.0 From 07b99606411e8501f21ccf2d0c2869fc20bb50b3 Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 1 Sep 2023 07:43:16 -0700 Subject: [PATCH 5/8] Need fetch-depth: 0 for sdist job too --- .github/workflows/dist.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml index dc43e92..9e45a5f 100644 --- a/.github/workflows/dist.yml +++ b/.github/workflows/dist.yml @@ -40,6 +40,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Build sdist run: pipx run build --sdist From 2bad11569289660f984368224a670e1c16a52ea7 Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 1 Sep 2023 07:53:29 -0700 Subject: [PATCH 6/8] test-extras as a list --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c24517f..997e82a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,5 +46,5 @@ 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-extras = ["test"] test-command = "pytest {project}/tests" From 1d39ccf51b12a3720a31cf3a7552b5d2a63a83fe Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 1 Sep 2023 08:43:50 -0700 Subject: [PATCH 7/8] Drop Python 3.7 --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 997e82a..93a3198 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,7 @@ classifiers=[ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", ] +requires-python = ">=3.7" dependencies = ["numpy", "scipy"] From 675f663f5a045b0cdea8670a2cd3c7256337df6d Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 1 Sep 2023 19:43:41 -0700 Subject: [PATCH 8/8] Bump cibuildwheel version to get 3.11 wheels Explicitly not bumping to 2.15.0 as that builds wheels for 3.12 which is currently broken. --- .github/workflows/dist.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml index 9e45a5f..c448a02 100644 --- a/.github/workflows/dist.yml +++ b/.github/workflows/dist.yml @@ -27,7 +27,7 @@ jobs: fetch-depth: 0 - name: Build wheels and test - uses: pypa/cibuildwheel@v2.8.0 + uses: pypa/cibuildwheel@v2.14.1 - name: Upload artifacts uses: actions/upload-artifact@v3