Skip to content

Commit

Permalink
Merge pull request #214 from shaoxc/master
Browse files Browse the repository at this point in the history
Add meson for examples to support python3.12 and new numpy
  • Loading branch information
jameskermode authored Apr 8, 2024
2 parents 8fb86e4 + 9b90df5 commit 7cb83cf
Show file tree
Hide file tree
Showing 42 changed files with 495 additions and 17 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- [windows-2019, win, AMD64]
- [macos-14, macosx, arm64]

python: ["cp38", "cp39", "cp310", "cp311"]
python: ["cp38", "cp39", "cp310", "cp311", "cp312"]
exclude:
- buildplat: [macos-14, macosx, arm64]
python: "cp38"
Expand All @@ -54,9 +54,10 @@ jobs:
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}*
CIBW_ARCHS: ${{ matrix.buildplat[2] }}
CIBW_ENVIRONMENT_PASS_LINUX: RUNNER_OS
CIBW_BEFORE_ALL_MACOS: "brew install gfortran && brew unlink gfortran && brew link gfortran"
CIBW_TEST_COMMAND_MACOS: "cd {project}/examples; make clean; make test"
CIBW_TEST_COMMAND_LINUX: "cd {project}/examples; make clean; make test"
CIBW_TEST_REQUIRES: meson-python>=0.12.0 ninja
CIBW_BEFORE_ALL_MACOS: "brew install gfortran gnu-sed && brew unlink gfortran && brew link gfortran"
CIBW_TEST_COMMAND_MACOS: "cd {project}/examples; make clean_meson; make test_meson"
CIBW_TEST_COMMAND_LINUX: "cd {project}/examples; make clean_meson; make test_meson"
CIBW_TEST_COMMAND_WINDOWS: "python -m f90wrap --version"

- name: Setup tmate session
Expand Down
16 changes: 16 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ clean:
echo "running make test in $$example" ; \
make -C $$example clean || exit ; \
done

test_meson:
for example in ${EXAMPLES}; do \
echo "" ; \
echo "" ; \
echo "" ; \
echo "# ---------------------------------------------------" ; \
echo "running make test in $$example" ; \
make -C $$example -f Makefile.meson PYTHON=$(PYTHON) test || exit ; \
done

clean_meson:
for example in ${EXAMPLES}; do \
echo "running make test in $$example" ; \
make -C $$example -f Makefile.meson clean || exit ; \
done
7 changes: 7 additions & 0 deletions examples/arrayderivedtypes/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include ../make.meson.inc

NAME := arrayderivedtype
WRAPFLAGS += -k kind_map

test: build
$(PYTHON) tests.py
24 changes: 24 additions & 0 deletions examples/arrays/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include ../make.meson.inc

NAME := ExampleArray_pkg
NAME2 := ExampleArray_relative
NAME3 := ExampleArray_top
WRAPFLAGS += -k kind_map -P
MAKEFILE := $(lastword $(MAKEFILE_LIST))

test: build2
$(PYTHON) tests.py

build2_pre: build
$(eval WRAPFLAGS += --relative)
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME2) WRAPFLAGS="$(WRAPFLAGS)"

build2: build2_pre
mkdir ${NAME3}
mv ${NAME2}/ _${NAME2}.*so ${NAME3}/
touch ${NAME3}/__init__.py

clean:
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME)
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME2)
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME3)
16 changes: 16 additions & 0 deletions examples/arrays_fixed/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include ../make.meson.inc

NAME := ExampleArray
NAME2 := ExampleArray_pkg
WRAPFLAGS += -k kind_map
MAKEFILE := $(lastword $(MAKEFILE_LIST))

test: build2
$(PYTHON) tests.py

build2: build
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME2) WRAPFLAGS="$(WRAPFLAGS) -P"

clean:
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME)
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME2)
6 changes: 6 additions & 0 deletions examples/arrays_in_derived_types_issue50/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include ../make.meson.inc

NAME := issue50

test: build
$(PYTHON) tests.py
15 changes: 15 additions & 0 deletions examples/callback_print_function_issue93/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include ../make.meson.inc

NAME := CBF
NAME2 := CBF_pkg
MAKEFILE := $(lastword $(MAKEFILE_LIST))

test: build2
$(PYTHON) tests.py

build2: build
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME2) WRAPFLAGS="$(WRAPFLAGS) -P"

clean:
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME)
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME2)
7 changes: 7 additions & 0 deletions examples/class_names/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include ../make.meson.inc

NAME := classnames
WRAPFLAGS += -k kind_map --class-names class_names.json

test: build
$(PYTHON) tests.py
16 changes: 16 additions & 0 deletions examples/cylinder/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include ../make.meson.inc

NAME := Example
NAME2 := Example_pkg
WRAPFLAGS += -k kind_map
MAKEFILE := $(lastword $(MAKEFILE_LIST))

test: build
$(PYTHON) tests.py

build2: build
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME2) WRAPFLAGS="$(WRAPFLAGS) -P"

clean:
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME)
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME2)
8 changes: 8 additions & 0 deletions examples/default_i8/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include ../make.meson.inc

NAME := testmodule
F90FLAGS += -fdefault-integer-8
WRAPFLAGS += -k kind_map -P

test: build
$(PYTHON) tests.py
23 changes: 23 additions & 0 deletions examples/derived-type-aliases/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include ../make.meson.inc

NAME := mytype
NAME2 := othertype
WRAPFLAGS += -k kind_map
MAKEFILE := $(lastword $(MAKEFILE_LIST))

test: build2
$(PYTHON) tests.py

build1:
$(eval LIBSRC_WRAP_FILES := mytype_mod.f90)
@ rm -rf f90wrap_*.f90
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME) WRAPFLAGS="$(WRAPFLAGS)" LIBSRC_WRAP_FILES=$(LIBSRC_WRAP_FILES)

build2: build1
$(eval LIBSRC_WRAP_FILES := othertype_mod.f90)
@ rm -rf f90wrap_*.f90
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME2) WRAPFLAGS="$(WRAPFLAGS)" LIBSRC_WRAP_FILES=$(LIBSRC_WRAP_FILES)

clean:
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME)
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME2)
17 changes: 17 additions & 0 deletions examples/derivedtypes/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include ../make.meson.inc

NAME := ExampleDerivedTypes
NAME2 := ExampleDerivedTypes_pkg
WRAPFLAGS += -k kind_map
MAKEFILE := $(lastword $(MAKEFILE_LIST))

test: build2
${PYTHON} tests.py
${PYTHON} tests_pkg.py

build2: build
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME2) WRAPFLAGS="$(WRAPFLAGS) -P"

clean:
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME)
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME2)
22 changes: 11 additions & 11 deletions examples/derivedtypes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_return_value_sub(self):

def test_return_a_dt_func(self):
dt = self.lib.library.return_a_dt_func()
self.assert_(isinstance(dt, self.lib.datatypes.different_types))
self.assertTrue(isinstance(dt, self.lib.datatypes.different_types))
self.assertEqual(dt.alpha, 1) # logicals, so 1/0 instead of T/F
self.assertEqual(dt.beta, 666)
self.assertEqual(dt.delta, 666.666)
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_only_manipulate(self):
self.lib.library.do_array_stuff(n=n, x=x, y=y, br=br, co=co)
self.lib.library.only_manipulate(n=n, array=co)

# self.assert_(isinstance(br.dtype.type, np.float64))
# self.assertTrue(isinstance(br.dtype.type, np.float64))

for k in range(4):
np.testing.assert_allclose((x*y + x)**2, co[k,:])
Expand All @@ -103,7 +103,7 @@ def test_set_derived_type(self):

dt = self.lib.library.set_derived_type(dt_beta=dt_beta,
dt_delta=dt_delta)
self.assert_(isinstance(dt, self.lib.datatypes.different_types))
self.assertTrue(isinstance(dt, self.lib.datatypes.different_types))
self.assertEqual(dt.beta, dt_beta)
self.assertEqual(dt.delta, dt_delta)

Expand Down Expand Up @@ -133,7 +133,7 @@ def test_modify_derived_types(self):
def test_modify_dertype_multiple_arrays(self):

dt = self.lib.library.modify_dertype_fixed_shape_arrays()
self.assert_(isinstance(dt, self.lib.datatypes.fixed_shape_arrays))
self.assertTrue(isinstance(dt, self.lib.datatypes.fixed_shape_arrays))

self.assertEqual(dt.eta.dtype, np.int32)
eta = np.ones((10,4), dtype=np.int32)
Expand All @@ -155,7 +155,7 @@ def test_modify_dertype_multiple_arrays(self):
# def test_single_precesion_array(self):

# dt = self.lib.library.modify_dertype_fixed_shape_arrays()
# self.assert_(isinstance(dt, self.lib.datatypes.Fixed_Shape_Arrays))
# self.assertTrue(isinstance(dt, self.lib.datatypes.Fixed_Shape_Arrays))

# # expected failure: dt.theta seems to be float64 (double precision)
# # while it should be single precision
Expand All @@ -165,15 +165,15 @@ def test_modify_dertype_multiple_arrays(self):

def test_nested_dertype(self):
ndt = self.lib.datatypes.nested()
self.assert_(isinstance(ndt.mu.alpha, int)) # boolean/logical in F though)
self.assert_(isinstance(ndt.mu.beta, int))
self.assert_(isinstance(ndt.mu.delta, float))
self.assert_(isinstance(ndt.nu, self.lib.datatypes.fixed_shape_arrays))
self.assertTrue(isinstance(ndt.mu.alpha, int)) # boolean/logical in F though)
self.assertTrue(isinstance(ndt.mu.beta, int))
self.assertTrue(isinstance(ndt.mu.delta, float))
self.assertTrue(isinstance(ndt.nu, self.lib.datatypes.fixed_shape_arrays))

def test_return_dertype_pointer_arrays(self):
m, n = 9, 5
dt = self.lib.library.return_dertype_pointer_arrays(m, n)
self.assert_(isinstance(dt, self.lib.datatypes.pointer_arrays))
self.assertTrue(isinstance(dt, self.lib.datatypes.pointer_arrays))
expected = np.ones((m, n), order='F', dtype=np.float64) * 100.0
expected[m-3, n-2] = -10.0
np.testing.assert_allclose(dt.chi, expected)
Expand All @@ -182,7 +182,7 @@ def test_return_dertype_alloc_arrays(self):
m, n = 9, 5
dt = self.lib.library.return_dertype_alloc_arrays(m, n)
dt.chi_shape = np.array([m, n], dtype=np.int32)
self.assert_(isinstance(dt, self.lib.datatypes_allocatable.alloc_arrays))
self.assertTrue(isinstance(dt, self.lib.datatypes_allocatable.alloc_arrays))
expected = np.ones((m, n), order='F', dtype=np.float64) * 10.0
expected[m-3, n-2] = -1.0
np.testing.assert_allclose(dt.chi, expected)
Expand Down
6 changes: 6 additions & 0 deletions examples/derivedtypes_procedure/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include ../make.meson.inc

NAME := library

test: build
$(PYTHON) tests.py
13 changes: 13 additions & 0 deletions examples/docstring/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include ../make.meson.inc

NAME := pywrapper
MAKEFILE := $(lastword $(MAKEFILE_LIST))

LIBSRC_WRAP_FPP_FILES := main.f90

test: build1
$(PYTHON) docstring_test.py

build1:
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME) LIBSRC_WRAP_FPP_FILES=$(LIBSRC_WRAP_FPP_FILES)

7 changes: 7 additions & 0 deletions examples/elemental/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include ../make.meson.inc

NAME := elmod
WRAPFLAGS += -k kind_map

test: build
$(PYTHON) test.py
17 changes: 17 additions & 0 deletions examples/errorbinding/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include ../make.meson.inc

NAME := ExampleDerivedTypes
NAME2 := ExampleDerivedTypes_pkg
WRAPFLAGS += -k kind_map
MAKEFILE := $(lastword $(MAKEFILE_LIST))

test: build2
#${PYTHON} tests.py
#${PYTHON} tests_pkg.py

build2: build
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME2) WRAPFLAGS="$(WRAPFLAGS) -P"

clean:
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME)
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME2)
22 changes: 22 additions & 0 deletions examples/example2/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
include ../make.meson.inc

NAME := mockdt
NAME2 := mockdtpkg
WRAPFLAGS += -k kind_map
MAKEFILE := $(lastword $(MAKEFILE_LIST))

LIBSRC_WRAP_FILES := $(shell find ./ -name '*.F90')

test: build2
$(PYTHON) test_module.py
$(PYTHON) test_package.py

build2:
@ rm -rf f90wrap_*.f90
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME) WRAPFLAGS="$(WRAPFLAGS)" LIBSRC_WRAP_FILES="$(LIBSRC_WRAP_FILES)"
@ rm -rf f90wrap_*.f90
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME2) WRAPFLAGS="$(WRAPFLAGS) -P" LIBSRC_WRAP_FILES="$(LIBSRC_WRAP_FILES)"

clean:
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME)
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME2)
6 changes: 6 additions & 0 deletions examples/extends/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include ../make.meson.inc

NAME := testextends

test: build
$(PYTHON) testextends.py
7 changes: 7 additions & 0 deletions examples/fixed_1D_derived_type_array_argument/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include ../make.meson.inc

NAME := test_python
WRAPFLAGS += --default-to-inout

test: build
$(PYTHON) tests.py
16 changes: 16 additions & 0 deletions examples/interface/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include ../make.meson.inc

NAME := example
NAME2 := examplepkg
MAKEFILE := $(lastword $(MAKEFILE_LIST))

test: build2
$(PYTHON) test.py
$(PYTHON) test_pkg.py

build2: build
$(MAKE) -f $(MAKEFILE) build NAME=$(NAME2) WRAPFLAGS=-P

clean:
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME)
$(MAKE) -f $(MAKEFILE) clean NAME=$(NAME2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include ../make.meson.inc

NAME := itest

test: build
$(PYTHON) run.py
6 changes: 6 additions & 0 deletions examples/issue206_subroutine_oldstyle/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include ../make.meson.inc

NAME := itest

test: build
$(PYTHON) run.py
6 changes: 6 additions & 0 deletions examples/issue32/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include ../make.meson.inc

NAME := test

test: build
$(PYTHON) -c 'import test; test.foo(1.0, 2)'
Loading

0 comments on commit 7cb83cf

Please sign in to comment.