Skip to content

Commit 76a7f86

Browse files
authored
Merge pull request #166 from ocefpaf/numpy_2
Test against numpy 2.0
2 parents f9b3f6e + 8f39666 commit 76a7f86

13 files changed

+117
-44
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Test code generation
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
code-generation:
10+
runs-on: ubuntu-latest
11+
defaults:
12+
run:
13+
shell: bash -l {0}
14+
15+
steps:
16+
- name: checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup Micromamba
22+
uses: mamba-org/setup-micromamba@v1
23+
with:
24+
environment-name: TEST
25+
init-shell: bash
26+
create-args: >-
27+
python=3 pip
28+
--file requirements-dev.txt
29+
--channel conda-forge
30+
31+
- name: Install nightly version of numpy
32+
run: |
33+
python -m pip install --pre --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple numpy scipy pandas -U
34+
35+
- name: Test Code Generation
36+
run: >
37+
git clone https://github.com/TEOS-10/GSW-C.git ../GSW-C
38+
&& git clone https://github.com/TEOS-10/GSW-Matlab.git ../GSW-Matlab
39+
&& python tools/copy_from_GSW-C.py
40+
&& python tools/mat2npz.py
41+
&& python tools/make_ufuncs.py
42+
&& python tools/make_wrapped_ufuncs.py
43+
&& python tools/fix_wrapped_ufunc_typos.py
44+
45+
- name: Install gsw
46+
run: >
47+
python -m pip install -v -e . --no-deps --no-build-isolation --force-reinstall
48+
&& python -m pytest -s -rxs -v gsw/tests

.github/workflows/tests.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ jobs:
1212
matrix:
1313
python-version: ["3.9", "3.10", "3.11", "3.12"]
1414
os: [windows-latest, ubuntu-latest, macos-latest]
15+
experimental: [false]
1516
# Oldest one based on NEP-29 and latest one.
1617
# See https://numpy.org/neps/nep-0029-deprecation_policy.html
1718
numpy-version: ["1.23", "1.26"]
1819
exclude:
1920
- python-version: "3.12"
2021
numpy-version: "1.23"
22+
include:
23+
- python-version: "3.12"
24+
os: "ubuntu-latest"
25+
experimental: true
2126
fail-fast: false
27+
defaults:
28+
run:
29+
shell: bash -l {0}
2230

2331
steps:
2432
- uses: actions/checkout@v4
@@ -31,18 +39,21 @@ jobs:
3139
create-args: >-
3240
python=${{ matrix.python-version }} python-build numpy=${{ matrix.numpy-version }} --file requirements-dev.txt --channel conda-forge
3341
34-
- name: Install gsw
35-
shell: bash -l {0}
42+
- name: Install unstable dependencies
43+
if: matrix.experimental == true
3644
run: |
37-
python -m pip install -e . --no-deps --force-reinstall
45+
python -m pip install \
46+
--index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/ \
47+
--trusted-host pypi.anaconda.org \
48+
--no-deps --pre --upgrade \
49+
numpy scipy pandas;
50+
python -m pip install -v -e . --no-deps --no-build-isolation --force-reinstall
3851
39-
- name: Debug
40-
shell: bash -l {0}
52+
- name: Install gsw
53+
if: matrix.experimental != true
4154
run: |
42-
python -c "import numpy; print(f'Running numpy {numpy.__version__}')"
55+
python -m pip install -e . --no-deps --force-reinstall
4356
4457
- name: Tests
45-
shell: bash -l {0}
4658
run: |
47-
micromamba activate TEST
48-
pytest -s -rxs -v gsw/tests
59+
python -m pytest -s -rxs -v gsw/tests

gsw/tests/test_check_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
mfuncnames = [mf.name for mf in mfuncs]
4646

4747

48-
@pytest.fixture(params=[-360, 0, 360])
48+
@pytest.fixture(params=[-360., 0., 360.])
4949
def lonshift(request):
5050
return request.param
5151

pyproject.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
build-backend = "setuptools.build_meta"
33
requires = [
44
"build",
5-
"oldest-supported-numpy",
5+
'numpy<3,>=2.0.0rc1; python_version >= "3.9"',
6+
'oldest-supported-numpy; python_version < "3.9"',
67
"pip>9.0.1",
78
"setuptools>=42",
89
"setuptools_scm[toml]>=3.4",
@@ -60,18 +61,19 @@ write_to_template = "__version__ = '{version}'"
6061
tag_regex = "^(?P<prefix>v)?(?P<version>[^\\+]+)(?P<suffix>.*)?$"
6162

6263
[tool.ruff]
63-
select = [
64+
lint.select = [
6465
"A", # flake8-builtins
6566
"B", # flake8-bugbear
6667
"C4", # flake8-comprehensions
6768
"F", # flakes
6869
"I", # import sorting
6970
"UP", # upgrade
71+
"NPY201", # numpy 2.0
7072
]
7173
target-version = "py38"
7274
line-length = 105
7375

74-
ignore = [
76+
lint.ignore = [
7577
"F401", # module imported but unused
7678
"E501", # line too long
7779
"E713", # test for membership should be 'not in'
@@ -81,7 +83,7 @@ exclude = [
8183
"tools",
8284
]
8385

84-
[tool.ruff.per-file-ignores]
86+
[tool.ruff.lint.per-file-ignores]
8587
"docs/conf.py" = [
8688
"A001", # variable is shadowing a python builtin
8789
]

requirements-dev.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
check-manifest
2+
dask
23
numpydoc
4+
pandas>=2
35
pytest
6+
scipy
47
setuptools_scm
58
sphinx
69
sphinx_rtd_theme
710
twine
8-
pandas>=2
9-
dask
11+
xarray

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import shutil
88
import sys
99

10-
import pkg_resources
10+
import numpy
1111
from setuptools import Extension, setup
1212
from setuptools.command.build_ext import build_ext as _build_ext
1313

@@ -21,7 +21,7 @@ def read(*parts):
2121
class build_ext(_build_ext):
2222
# Extension builder from pandas without the cython stuff
2323
def build_extensions(self):
24-
numpy_incl = pkg_resources.resource_filename("numpy", "core/include")
24+
numpy_incl = numpy.get_include()
2525

2626
for ext in self.extensions:
2727
if hasattr(ext, "include_dirs") and not numpy_incl in ext.include_dirs:

tools/c_header_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99

1010

11-
basedir = Path('..').resolve()
11+
basedir = Path(__file__).parent.parent
1212

1313
def get_signatures(strip_extern=True, srcdir='src'):
1414
"""

tools/copy_from_GSW-C.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,31 @@
33
Copy all relevant .c and .h files from Python-C, if they are newer.
44
55
This is a simple utility, to be run from this directory. It assumes that
6-
an up-to-date GSW-C github repo and the present GSW-Python repo are
6+
an up-to-date GSW-C GitHub repo and the present GSW-Python repo are
77
siblings in the directory tree.
88
"""
99

10+
import sys
1011
import shutil
1112
from pathlib import Path
1213

14+
current = Path(__file__).parent
15+
srcdir = Path(current.parent.parent, "GSW-C")
1316

14-
fnames = ['gsw_oceanographic_toolbox.c',
15-
'gsw_saar.c',
16-
'gsw_saar_data.h',
17-
'gsw_internal_const.h',
18-
'gswteos-10.h']
17+
destdir = Path(current.parent, "src", "c_gsw")
18+
19+
fnames = [
20+
"gsw_oceanographic_toolbox.c",
21+
"gsw_saar.c",
22+
"gsw_saar_data.h",
23+
"gsw_internal_const.h",
24+
"gswteos-10.h",
25+
]
1926

20-
srcdir = Path('..', '..', 'GSW-C')
21-
destdir = Path('..', 'src', 'c_gsw')
2227

2328
if not srcdir.exists():
2429
raise IOError(
25-
f"Could not find the GSW-C source code in {srcdir}."
30+
f"Could not find the GSW-C source code in {srcdir}. "
2631
"Please read the development notes to find how to setup your GSW-Python development environment."
2732
)
2833

@@ -31,4 +36,4 @@
3136
dest = destdir.joinpath(fname)
3237
if src.stat().st_mtime > dest.stat().st_mtime:
3338
shutil.copyfile(str(src), str(dest))
34-
print('copied %s to %s' % (src, dest))
39+
print(f"copied {src} to {dest}")

tools/fix_wrapped_ufunc_typos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pathlib import Path
1010
import shutil
1111

12-
basedir = Path('..').resolve()
12+
basedir = Path(__file__).parent.parent
1313
wrapmod = basedir.joinpath('gsw', '_wrapped_ufuncs.py')
1414

1515
orig = wrapmod.with_suffix('.orig')

tools/make_ufuncs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
blacklist = ['add_barrier']
1616

17-
basedir = Path('..').resolve()
17+
basedir = Path(__file__).parent.parent
1818

1919
modfile_head_top = """
2020
/*
@@ -358,19 +358,19 @@ def write_modfile(modfile_name, srcdir):
358358
f.write(''.join(chunks))
359359

360360
funcnamelist1.sort()
361-
with open(srcdir + '_ufuncs1.list', 'w') as f:
361+
with open(srcdir.joinpath('_ufuncs1.list'), 'w') as f:
362362
f.write('\n'.join(funcnamelist1))
363363

364364
funcnamelist2.sort()
365-
with open(srcdir + '_ufuncs2.list', 'w') as f:
365+
with open(srcdir.joinpath('_ufuncs2.list'), 'w') as f:
366366
f.write('\n'.join(funcnamelist2))
367367

368368
funcnamelist = funcnamelist1 + funcnamelist2 + funcnamelist3
369369
funcnamelist.sort()
370-
with open(srcdir + '_ufuncs.list', 'w') as f:
370+
with open(srcdir.joinpath('_ufuncs.list'), 'w') as f:
371371
f.write('\n'.join(funcnamelist))
372372

373373
if __name__ == '__main__':
374-
srcdir = 'src'
374+
srcdir = basedir.joinpath('src')
375375
modfile_name = basedir.joinpath(srcdir, '_ufuncs.c')
376376
write_modfile(modfile_name, srcdir=srcdir)

0 commit comments

Comments
 (0)