From ec2cd1d334b161204b3a7f45ae5d1aaa224e5ebb Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Fri, 29 Mar 2024 15:43:25 +1100 Subject: [PATCH 01/19] BLD: Attempt to build using spin This commit is the first commit to try and move from poetry to spin. It is not working at the moment, namely the test runner cannot find the given tests. --- environment.yml | 21 ++++++++++ meson.build | 19 +++++++++ numpy_financial/_cfinancial.pyx | 18 +++++++++ numpy_financial/_financial.py | 18 +-------- numpy_financial/meson.build | 15 +++++++ pyproject.toml | 69 ++++++++++++++++++++------------- tests/meson.build | 9 +++++ 7 files changed, 126 insertions(+), 43 deletions(-) create mode 100644 environment.yml create mode 100644 meson.build create mode 100644 numpy_financial/_cfinancial.pyx create mode 100644 numpy_financial/meson.build create mode 100644 tests/meson.build diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..1ad8e64 --- /dev/null +++ b/environment.yml @@ -0,0 +1,21 @@ +# To use: +# $ conda env create -f environment.yml # `mamba` works too for this command +# $ conda activate numpy-financial-dev +# +name: numpy-financial-dev +channels: + - conda-forge +dependencies: + - python + - cython>=3.0.9 + - compilers + - meson + - meson-python + - ninja + - numpy + - pytest + - pytest-xdist + - asv>=0.6.0 + - hypothesis + - myst-parser + - spin \ No newline at end of file diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..4648873 --- /dev/null +++ b/meson.build @@ -0,0 +1,19 @@ +project( + 'numpy-financial', + 'cython', + version: '2.0.0.dev', + license: 'BSD-3', + meson_version: '>=1.4.0', +) + +cy = meson.get_compiler('cython') + +if not cy.version().version_compare('>=3.0.9') + error('NumPy-Financial requires Cython >= 3.0.9') +endif + +py = import('python').find_installation(pure: false) +py_dep = py.dependency() + +subdir('numpy_financial') +subdir('tests') \ No newline at end of file diff --git a/numpy_financial/_cfinancial.pyx b/numpy_financial/_cfinancial.pyx new file mode 100644 index 0000000..0a7ff3c --- /dev/null +++ b/numpy_financial/_cfinancial.pyx @@ -0,0 +1,18 @@ +from libc.math cimport NAN + + +def _cnpv(const double[::1] rates, const double[:, ::1] values, double[:, ::1] out): + cdef: + Py_ssize_t i, j, t + double acc + + for i in range(rates.shape[0]): + for j in range(values.shape[0]): + acc = 0.0 + for t in range(values.shape[1]): + if rates[i] == -1.0: + acc = NAN + break + else: + acc += values[j, t] / ((1.0 + rates[i]) ** t) + out[i, j] = acc \ No newline at end of file diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index 534230f..b5ba233 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -13,8 +13,8 @@ from decimal import Decimal -import numba as nb import numpy as np +from _cfinancial import _cnpv __all__ = ['fv', 'pmt', 'nper', 'ipmt', 'ppmt', 'pv', 'rate', 'irr', 'npv', 'mirr', @@ -844,20 +844,6 @@ def irr(values, *, raise_exceptions=False): return eirr[np.argmin(abs_eirr)] -@nb.njit -def _npv_native(rates, values, out): - for i in range(rates.shape[0]): - for j in range(values.shape[0]): - acc = 0.0 - for t in range(values.shape[1]): - if rates[i] == -1.0: - acc = np.nan - break - else: - acc += values[j, t] / ((1.0 + rates[i]) ** t) - out[i, j] = acc - - def npv(rate, values): r"""Return the NPV (Net Present Value) of a cash flow series. @@ -948,7 +934,7 @@ def npv(rate, values): output_shape = _get_output_array_shape(rate_inner, values_inner) out = np.empty(output_shape) - _npv_native(rate_inner, values_inner, out) + _cnpv(rate_inner, values_inner, out) return _ufunc_like(out) diff --git a/numpy_financial/meson.build b/numpy_financial/meson.build new file mode 100644 index 0000000..e186f00 --- /dev/null +++ b/numpy_financial/meson.build @@ -0,0 +1,15 @@ +py.extension_module( + '_cfinancial', + '_cfinancial.pyx', + install: true, + subdir: 'numpy_financial', +) + +python_sources = [ + '_financial.py', +] + +py.install_sources( + python_sources, + subdir: 'numpy_financial', +) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 517910f..d1cfc52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,15 @@ [build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" - +build-backend = "mesonpy" +requires = [ + "meson-python>=0.15.0", + "Cython>=3.0.9", + "numpy>=1.23.5", +] -[tool.poetry] +[project] name = "numpy-financial" version = "2.0.0" +requires-python = ">=3.10" description = "Simple financial functions" license = "BSD-3-Clause" authors = ["Travis E. Oliphant et al."] @@ -34,30 +38,41 @@ classifiers = [ "Operating System :: Unix", "Operating System :: MacOS", ] -packages = [{include = "numpy_financial"}] - -[tool.poetry.dependencies] -python = "^3.10" -numpy = "^1.23" -numba = "^0.59.1" - -[tool.poetry.group.test.dependencies] -pytest = "^8.0" -hypothesis = {extras = ["numpy"], version = "^6.99.11"} -pytest-xdist = {extras = ["psutil"], version = "^3.5.0"} - - -[tool.poetry.group.docs.dependencies] -sphinx = "^7.0" -numpydoc = "^1.5" -pydata-sphinx-theme = "^0.15" -myst-parser = "^2.0.0" - +[project.optional-dependencies] +test = [ + "pytest", + "pytest-xdist", + "hypothesis", +] +doc = [ + "sphinx>=7.0", + "numpydoc>=1.5", + "pydata-sphinx-theme>=0.15", + "myst-parser>=2.0.0", +] +dev = [ + "ruff>=0.3.0", + "asv>=0.6.0", +] -[tool.poetry.group.lint.dependencies] -ruff = "^0.3" +[tool.spin] +package = 'numpy_financial' -[tool.poetry.group.bench.dependencies] -asv = "^0.6" +[tool.spin.commands] +"Build" = [ + "spin.cmds.meson.build", + "spin.cmds.meson.test", + "spin.cmds.build.sdist", + "spin.cmds.pip.install", +] +"Documentation" = [ + "spin.cmds.meson.docs" +] +"Environments" = [ + "spin.cmds.meson.shell", + "spin.cmds.meson.ipython", + "spin.cmds.meson.python", + "spin.cmds.meson.run" +] diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..019f9c3 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,9 @@ +test_sources = [ + '__init__.py', + 'test_financial.py', +] + +py.install_sources( + test_sources, + subdir: 'tests', +) \ No newline at end of file From dc672af030577bdf428614445b4e798de81452d4 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Fri, 29 Mar 2024 17:26:54 +1100 Subject: [PATCH 02/19] MAINT: Update gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 8b3cdae..f495f60 100644 --- a/.gitignore +++ b/.gitignore @@ -62,6 +62,7 @@ GTAGS ################ # setup.py working directory build +build-install # sphinx build directory _build # setup.py dist directory @@ -112,3 +113,7 @@ poetry.lock # Things specific to this project # ################################### doc/source/_api_stubs + +# Misc files that we do not require # +.asv/ +.hypothesis/ From d3292269bb13a428f6029d2d900531b432d1e32d Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Sat, 30 Mar 2024 10:25:28 +1100 Subject: [PATCH 03/19] BLD: Move tests into package directory --- meson.build | 1 - numpy_financial/_cfinancial.pyx | 2 +- numpy_financial/_financial.py | 4 ++-- numpy_financial/meson.build | 5 ++++- {tests => numpy_financial/tests}/__init__.py | 0 {tests => numpy_financial/tests}/test_financial.py | 0 tests/meson.build | 9 --------- 7 files changed, 7 insertions(+), 14 deletions(-) rename {tests => numpy_financial/tests}/__init__.py (100%) rename {tests => numpy_financial/tests}/test_financial.py (100%) delete mode 100644 tests/meson.build diff --git a/meson.build b/meson.build index 4648873..5d5dd31 100644 --- a/meson.build +++ b/meson.build @@ -16,4 +16,3 @@ py = import('python').find_installation(pure: false) py_dep = py.dependency() subdir('numpy_financial') -subdir('tests') \ No newline at end of file diff --git a/numpy_financial/_cfinancial.pyx b/numpy_financial/_cfinancial.pyx index 0a7ff3c..c998345 100644 --- a/numpy_financial/_cfinancial.pyx +++ b/numpy_financial/_cfinancial.pyx @@ -1,7 +1,7 @@ from libc.math cimport NAN -def _cnpv(const double[::1] rates, const double[:, ::1] values, double[:, ::1] out): +def _npv(const double[::1] rates, const double[:, ::1] values, double[:, ::1] out): cdef: Py_ssize_t i, j, t double acc diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index b5ba233..26fdb09 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -14,7 +14,7 @@ from decimal import Decimal import numpy as np -from _cfinancial import _cnpv +from _cfinancial import _npv __all__ = ['fv', 'pmt', 'nper', 'ipmt', 'ppmt', 'pv', 'rate', 'irr', 'npv', 'mirr', @@ -934,7 +934,7 @@ def npv(rate, values): output_shape = _get_output_array_shape(rate_inner, values_inner) out = np.empty(output_shape) - _cnpv(rate_inner, values_inner, out) + _npv(rate_inner, values_inner, out) return _ufunc_like(out) diff --git a/numpy_financial/meson.build b/numpy_financial/meson.build index e186f00..6fe3ce5 100644 --- a/numpy_financial/meson.build +++ b/numpy_financial/meson.build @@ -6,10 +6,13 @@ py.extension_module( ) python_sources = [ + '__init__.py', '_financial.py', ] py.install_sources( python_sources, subdir: 'numpy_financial', -) \ No newline at end of file +) + +install_subdir('tests', install_dir: py.get_install_dir() / 'numpy_financial') diff --git a/tests/__init__.py b/numpy_financial/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to numpy_financial/tests/__init__.py diff --git a/tests/test_financial.py b/numpy_financial/tests/test_financial.py similarity index 100% rename from tests/test_financial.py rename to numpy_financial/tests/test_financial.py diff --git a/tests/meson.build b/tests/meson.build deleted file mode 100644 index 019f9c3..0000000 --- a/tests/meson.build +++ /dev/null @@ -1,9 +0,0 @@ -test_sources = [ - '__init__.py', - 'test_financial.py', -] - -py.install_sources( - test_sources, - subdir: 'tests', -) \ No newline at end of file From 07778aa0ec37f813254382d57caee6e51f5ef5e2 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Sat, 30 Mar 2024 11:03:45 +1100 Subject: [PATCH 04/19] ENH: npv: Tidy up Cython version of npv --- numpy_financial/_cfinancial.pyx | 27 +++++++++++++++------------ numpy_financial/_financial.py | 4 ++-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/numpy_financial/_cfinancial.pyx b/numpy_financial/_cfinancial.pyx index c998345..77c195b 100644 --- a/numpy_financial/_cfinancial.pyx +++ b/numpy_financial/_cfinancial.pyx @@ -1,18 +1,21 @@ from libc.math cimport NAN +cimport cython - -def _npv(const double[::1] rates, const double[:, ::1] values, double[:, ::1] out): +@cython.boundscheck(False) +@cython.cdivision(True) +def npv(const double[::1] rates, const double[:, ::1] values, double[:, ::1] out): cdef: Py_ssize_t i, j, t double acc - for i in range(rates.shape[0]): - for j in range(values.shape[0]): - acc = 0.0 - for t in range(values.shape[1]): - if rates[i] == -1.0: - acc = NAN - break - else: - acc += values[j, t] / ((1.0 + rates[i]) ** t) - out[i, j] = acc \ No newline at end of file + with nogil: + for i in range(rates.shape[0]): + for j in range(values.shape[0]): + acc = 0.0 + for t in range(values.shape[1]): + if rates[i] == -1.0: + acc = NAN + break + else: + acc = acc + values[j, t] / ((1.0 + rates[i]) ** t) + out[i, j] = acc \ No newline at end of file diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index 26fdb09..001d33d 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -14,7 +14,7 @@ from decimal import Decimal import numpy as np -from _cfinancial import _npv +import _cfinancial __all__ = ['fv', 'pmt', 'nper', 'ipmt', 'ppmt', 'pv', 'rate', 'irr', 'npv', 'mirr', @@ -934,7 +934,7 @@ def npv(rate, values): output_shape = _get_output_array_shape(rate_inner, values_inner) out = np.empty(output_shape) - _npv(rate_inner, values_inner, out) + _cfinancial.npv(rate_inner, values_inner, out) return _ufunc_like(out) From d31ff087b663401f7ab8d460fd4db24994432204 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Sun, 31 Mar 2024 17:39:30 +1100 Subject: [PATCH 05/19] BLD: Explicitly link to C compiler --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 5d5dd31..cb6a213 100644 --- a/meson.build +++ b/meson.build @@ -1,11 +1,12 @@ project( 'numpy-financial', - 'cython', + 'cython', 'c', version: '2.0.0.dev', license: 'BSD-3', meson_version: '>=1.4.0', ) +cc = meson.get_compiler('c') cy = meson.get_compiler('cython') if not cy.version().version_compare('>=3.0.9') From a34611a27ed60117d3e8acde8e1fa9fb6dcaa4fd Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 1 Apr 2024 01:00:01 -0700 Subject: [PATCH 06/19] Remove __init__.py from tests I'm not sure what the preferred practice is, but it fixes pytest test discovery. See https://stackoverflow.com/a/41752043/214686 --- numpy_financial/tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 numpy_financial/tests/__init__.py diff --git a/numpy_financial/tests/__init__.py b/numpy_financial/tests/__init__.py deleted file mode 100644 index e69de29..0000000 From 2e6402c952b0fb48a60843e5e3028902470af768 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 1 Apr 2024 01:02:00 -0700 Subject: [PATCH 07/19] Import _cfinancial from local package --- numpy_financial/_financial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index 001d33d..9532f40 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -14,7 +14,7 @@ from decimal import Decimal import numpy as np -import _cfinancial +from . import _cfinancial __all__ = ['fv', 'pmt', 'nper', 'ipmt', 'ppmt', 'pv', 'rate', 'irr', 'npv', 'mirr', From 75f03ae2a473a85ef39ce0372ae4c1adf48b2b0d Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 1 Apr 2024 01:06:53 -0700 Subject: [PATCH 08/19] Fix linter --- numpy_financial/_financial.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index 9532f40..2483869 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -14,6 +14,7 @@ from decimal import Decimal import numpy as np + from . import _cfinancial __all__ = ['fv', 'pmt', 'nper', 'ipmt', 'ppmt', 'pv', 'rate', From 7420dc8e322b6d3084ec30d2a306117abfea2842 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 08:56:37 +1100 Subject: [PATCH 09/19] ENH: npv: Cast input arrays to ``np.float64`` At the moment we have only templated the Cython code to work with ``double``s. This may need to be changed in the future. --- numpy_financial/_financial.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index 2483869..03f3f1b 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -922,8 +922,8 @@ def npv(rate, values): [-2798.19, -3612.24], [-2884.3 , -3710.74]]) """ - values_inner = np.atleast_2d(values) - rate_inner = np.atleast_1d(rate) + values_inner = np.atleast_2d(values).astype(np.float64) + rate_inner = np.atleast_1d(rate).astype(np.float64) if rate_inner.ndim != 1: msg = "invalid shape for rates. Rate must be either a scalar or 1d array" From e36dddc31a9470c33a2884b91fb401ef59a0115d Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 08:57:30 +1100 Subject: [PATCH 10/19] BLD/DOC: Include dependencies to build documentation --- environment.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 1ad8e64..4768460 100644 --- a/environment.yml +++ b/environment.yml @@ -18,4 +18,6 @@ dependencies: - asv>=0.6.0 - hypothesis - myst-parser - - spin \ No newline at end of file + - numpydoc + - pydata-sphinx-theme>=15.0.0 + - spin From a8c976ad7c1790306323d24da4119fcc83e3d332 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 09:14:34 +1100 Subject: [PATCH 11/19] BLD/CI: Update package CI to test with conda/spin --- .github/workflows/pythonpackage.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index e5b576c..31e2169 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -1,4 +1,4 @@ -name: Python package +name: Test package on: [push, pull_request] @@ -12,14 +12,12 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: conda-incubator/setup-miniconda@v3 with: + auto-update-conda: true python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip poetry - poetry env use ${{ matrix.python-version }} - poetry install --with=test + activate-environment: numpy-financial-dev + environment-file: environment.yml - name: Test with pytest run: | - poetry run pytest --doctest-modules + spin test -- --doctest-modules From 79b8248d3ec3d95919a473ecccfbaefca8870516 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 09:17:04 +1100 Subject: [PATCH 12/19] BLD/CI: Fix pydata-sphinx-theme version --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 4768460..4fc87d5 100644 --- a/environment.yml +++ b/environment.yml @@ -19,5 +19,5 @@ dependencies: - hypothesis - myst-parser - numpydoc - - pydata-sphinx-theme>=15.0.0 + - pydata-sphinx-theme>=0.15.0 - spin From d15a883272d67407f29ab60bebc0de45b7fae8c9 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 09:21:24 +1100 Subject: [PATCH 13/19] BLD/CI: Try explicitly activate the environment --- .github/workflows/pythonpackage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 31e2169..b8f1238 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -20,4 +20,5 @@ jobs: environment-file: environment.yml - name: Test with pytest run: | + conda activate numpy-financial-dev spin test -- --doctest-modules From 79472523f1c2446dcd07084567738e77f78c4f55 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 09:23:51 +1100 Subject: [PATCH 14/19] BLD/CI: Try running with same command as installing conda --- .github/workflows/pythonpackage.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index b8f1238..05efc8c 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -11,14 +11,12 @@ jobs: python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} + - name: Testing with Python ${{ matrix.python-version }} uses: conda-incubator/setup-miniconda@v3 with: auto-update-conda: true python-version: ${{ matrix.python-version }} activate-environment: numpy-financial-dev environment-file: environment.yml - - name: Test with pytest run: | - conda activate numpy-financial-dev spin test -- --doctest-modules From 4f54b50adea34969d2455b7812db8bc3c6cc2e87 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 09:26:18 +1100 Subject: [PATCH 15/19] BLD/CI: Print conda info --- .github/workflows/pythonpackage.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 05efc8c..a339d5b 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -11,12 +11,18 @@ jobs: python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 - - name: Testing with Python ${{ matrix.python-version }} + - name: Set up Python ${{ matrix.python-version }} uses: conda-incubator/setup-miniconda@v3 with: auto-update-conda: true python-version: ${{ matrix.python-version }} activate-environment: numpy-financial-dev environment-file: environment.yml + auto-activate-base: false + - name: Conda info + run: | + conda info + conda list + - name: Test with pytest run: | spin test -- --doctest-modules From 34985e0d5376a166fecd8c14741a7e8cdf438e4d Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 09:40:02 +1100 Subject: [PATCH 16/19] BLD/CI: Add job to build the project --- .github/workflows/pythonpackage.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index a339d5b..a7af180 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -23,6 +23,9 @@ jobs: run: | conda info conda list + - name: Build project + run: | + spin build -v - name: Test with pytest run: | spin test -- --doctest-modules From b6d7834980797a63dee49fd92e9146e332dd4131 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 09:47:54 +1100 Subject: [PATCH 17/19] BLD/CI: Add default bash command --- .github/workflows/pythonpackage.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index a7af180..d1f92d6 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -5,6 +5,9 @@ on: [push, pull_request] jobs: build: runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash -el {0} strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] @@ -19,7 +22,7 @@ jobs: activate-environment: numpy-financial-dev environment-file: environment.yml auto-activate-base: false - - name: Conda info + - name: Conda metadata run: | conda info conda list From 5dfb8f2aa82c417fc81b43bbb624864142fecb2f Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 09:58:21 +1100 Subject: [PATCH 18/19] BLD/CI: Add linting to main workflow --- .github/workflows/lint.yml | 53 ----------------------------- .github/workflows/pythonpackage.yml | 9 +++++ environment.yml | 10 +++++- 3 files changed, 18 insertions(+), 54 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 7ed2347..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Lint - -on: - push: - branches: - - "*" - pull_request: - branches: - - main - -permissions: - contents: read # to fetch code (actions/checkout) - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - test_lint: - name: Lint - # If using act to run CI locally the github object does not exist and the usual skipping should not be enforced - if: "github.repository == 'numpy/numpy-financial' || github.repository == ''" - runs-on: ubuntu-22.04 - strategy: - matrix: - python-version: ['3.11'] - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - submodules: recursive - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Python packages - run: | - python -m pip install --upgrade pip poetry - poetry env use ${{ matrix.python-version }} - poetry install --with=lint - - - name: Lint with Ruff - run: | - set -euo pipefail - # Tell us what version we are using - poetry run ruff version - # Check the source file, ignore type annotations (ANN) for now. - poetry run ruff check numpy_financial/ --ignore F403 --select E,F,B,I - # Check the test and benchmark files - poetry run ruff check tests/ benchmarks/ --select E,F,B,I diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index d1f92d6..e22522d 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -26,6 +26,15 @@ jobs: run: | conda info conda list + - name: Lint + run: | + set -euo pipefail + # Tell us what version we are using + ruff version + # Check the source file, ignore type annotations (ANN) for now. + ruff check numpy_financial/ --ignore F403 --select E,F,B,I + # Check the test and benchmark files + ruff check tests/ benchmarks/ --select E,F,B,I - name: Build project run: | spin build -v diff --git a/environment.yml b/environment.yml index 4fc87d5..921cec8 100644 --- a/environment.yml +++ b/environment.yml @@ -6,18 +6,26 @@ name: numpy-financial-dev channels: - conda-forge dependencies: + # Runtime dependencies - python + - numpy + # Build - cython>=3.0.9 - compilers - meson - meson-python - ninja - - numpy + # Tests - pytest - pytest-xdist - asv>=0.6.0 - hypothesis + # Docs - myst-parser - numpydoc - pydata-sphinx-theme>=0.15.0 - spin + # Lint + - ruff>=0.3.0 + # Benchmarks + - asv>=0.6.0 From 69b8db7f275812419d746a8fc87d4be869b127d4 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Tue, 2 Apr 2024 10:01:22 +1100 Subject: [PATCH 19/19] BLD/CI: Merge linting commands into one command --- .github/workflows/pythonpackage.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index e22522d..2812b50 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -32,9 +32,7 @@ jobs: # Tell us what version we are using ruff version # Check the source file, ignore type annotations (ANN) for now. - ruff check numpy_financial/ --ignore F403 --select E,F,B,I - # Check the test and benchmark files - ruff check tests/ benchmarks/ --select E,F,B,I + ruff check numpy_financial/ benchmarks/ --ignore F403 --select E,F,B,I - name: Build project run: | spin build -v