diff --git a/Makefile b/Makefile index 92e34ae..b43dcb9 100644 --- a/Makefile +++ b/Makefile @@ -1,41 +1,5 @@ -FC = gfortran -FCFLAGS = -g -c -fdefault-real-8 -fPIC -fno-second-underscore -fbacktrace -fno-align-commons -fbounds-check -std=legacy -LDFLAGS = +install: + pip install . -MODDIR := .mod -ifneq ($(MODDIR),) - $(shell test -d $(MODDIR) || mkdir -p $(MODDIR)) - FCFLAGS+= -J $(MODDIR) -endif - -SRCS = MOM_io.F90 MOM_error_handler.F90 ../MOM6/src/ALE/polynomial_functions.F90\ - ../MOM6/src/framework/MOM_string_functions.F90\ - ../MOM6/src/ALE/regrid_solvers.F90 ../MOM6/src/ALE/regrid_edge_values.F90\ - ../MOM6/src/ALE/regrid_consts.F90 ../MOM6/src/ALE/P1M_functions.F90\ - ../MOM6/src/ALE/regrid_consts.F90 ../MOM6/src/ALE/PCM_functions.F90\ - ../MOM6/src/ALE/regrid_consts.F90 ../MOM6/src/ALE/P3M_functions.F90\ - ../MOM6/src/ALE/regrid_consts.F90 ../MOM6/src/ALE/PLM_functions.F90\ - ../MOM6/src/ALE/regrid_consts.F90 ../MOM6/src/ALE/PPM_functions.F90\ - ../MOM6/src/ALE/regrid_consts.F90 ../MOM6/src/ALE/PQM_functions.F90\ - ../MOM6/src/ALE/regrid_interp.F90 ../MOM6/src/ALE/MOM_remapping.F90\ - ../MOM6/src/ALE/MOM_remapping.F90 - - -OBJECTS = $(SRCS:.F90=.o) -TARGET = libRemap.a - - -$(TARGET): $(OBJECTS) - rm -f $@ - ar cr $@ $^ - python setup.py config_fc --f90flags="-g -c -fdefault-real-8 -fPIC -fno-second-underscore -fbacktrace -fno-align-commons -fbounds-check" --fcompiler=gfortran build - python setup.py install - -%.o: %.F90 - $(FC) $(FCFLAGS) -I ../MOM6/config_src/memory/dynamic_symmetric -I ../MOM6/src/framework -c $< -o $@ - -test: $(TARGET) +test: python test.py - -clean: - rm -f *.o *.mod *.MOD libRemap.a ../MOM6/src/framework/*.o ../MOM6/src/core/*.o ../MOM6/src/ALE/*.o diff --git a/README.md b/README.md index 79e9a09..3166f49 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Instructions ``` git submodule init git submodule update -make +make install ``` # Testing the install diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..f125c3d --- /dev/null +++ b/meson.build @@ -0,0 +1,83 @@ +project('pyRemapping', ['c', 'fortran'], + version: '1.2.4', + default_options: [ + 'buildtype=release', + 'warning_level=0', + 'fortran_std=legacy', + ], +) + +py = import('python').find_installation(pure: false) +py_dep = py.dependency() + +# Locate numpy and f2py include directories at configure time +incdir_numpy = run_command(py, + ['-c', 'import numpy; print(numpy.get_include())'], + check: true, +).stdout().strip() + +incdir_f2py = run_command(py, + ['-c', 'import numpy.f2py; print(numpy.f2py.get_include())'], + check: true, +).stdout().strip() + +numpy_inc = include_directories(incdir_numpy) +f2py_inc = include_directories(incdir_f2py) + +# Fortran flags matching the original Makefile +add_project_arguments( + [ + '-fdefault-real-8', + '-fno-second-underscore', + '-fbacktrace', + '-fno-align-commons', + '-fbounds-check', + ], + language: 'fortran', +) + +# Header/module include paths required by MOM6 sources +fortran_inc = include_directories( + '../MOM6/config_src/memory/dynamic_symmetric', + '../MOM6/src/framework', +) + +# All supporting Fortran sources (deduplicated from Makefile SRCS) +remap_srcs = files( + 'MOM_io.F90', + 'MOM_error_handler.F90', + '../MOM6/src/ALE/polynomial_functions.F90', + '../MOM6/src/framework/MOM_string_functions.F90', + '../MOM6/src/ALE/regrid_solvers.F90', + '../MOM6/src/ALE/regrid_edge_values.F90', + '../MOM6/src/ALE/regrid_consts.F90', + '../MOM6/src/ALE/P1M_functions.F90', + '../MOM6/src/ALE/PCM_functions.F90', + '../MOM6/src/ALE/P3M_functions.F90', + '../MOM6/src/ALE/PLM_functions.F90', + '../MOM6/src/ALE/PPM_functions.F90', + '../MOM6/src/ALE/PQM_functions.F90', + '../MOM6/src/ALE/regrid_interp.F90', + '../MOM6/src/ALE/MOM_remapping.F90', +) + +# Generate the f2py C and Fortran wrapper sources from the interface file +remap_f2py = custom_target('remap_f2py', + input: 'remap.f90', + output: ['remapmodule.c', 'remap-f2pywrappers2.f90'], + command: [ + py, '-m', 'numpy.f2py', + '@INPUT@', + '-m', 'remap', + '--lower', + '--build-dir', '@OUTDIR@', + ], +) + +# Build the Python extension module +py.extension_module('remap', + sources: [remap_f2py, incdir_f2py / 'fortranobject.c', 'remap.f90'] + remap_srcs, + include_directories: [numpy_inc, f2py_inc, fortran_inc], + dependencies: [py_dep], + install: true, +) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c8b7f79 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,19 @@ +[build-system] +requires = [ + "meson>=1.1.0", + "meson-python>=0.13.0", + "ninja", + "numpy>=1.19", +] +build-backend = "mesonpy" + +[project] +name = "pyRemapping" +version = "1.2.4" +description = "" +authors = [ + {name = "Matthew Harrison", email = "matthew.harrison@noaa.gov"}, +] +license = {text = "CCL"} +requires-python = ">=3.9" +dependencies = ["numpy>=1.19"] diff --git a/setup.py b/setup.py deleted file mode 100644 index 881d4b0..0000000 --- a/setup.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -""" -from numpy.distutils.core import setup,Extension - -doclines = __doc__.split("\n") - - -remap = Extension(name = 'remap', - include_dirs = ['.mod'], - library_dirs = ['.'], - libraries = ['Remap'], - sources = ['remap.f90']) - - -if __name__ == '__main__': - from numpy.distutils.core import setup - setup(name = "pyRemapping", - version = '1.2.4', - description = doclines[0], - long_description = "\n".join(doclines[2:]), - author = "Matthew Harrison", - author_email = "matthew.harrison@noaa.gov", - url = "none", - license = 'CCL', - platforms = ["any"], - ext_modules = [remap], - )