diff --git a/.gitmodules b/.gitmodules index 31f95b1..8b13789 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1 @@ -[submodule "cFMS"] - path = cFMS - url = https://github.com/NOAA-GFDL/cFMS.git - branch = main diff --git a/cFMS b/cFMS deleted file mode 160000 index b9ebf84..0000000 --- a/cFMS +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b9ebf8431100a4c7ebb14ae919301a7b6ec53136 diff --git a/compile_c_libs.sh b/compile_c_libs.sh deleted file mode 100755 index 409c4ad..0000000 --- a/compile_c_libs.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash - -set -ex -#set -o posix - -#yaml includes -YAML_FLAGS+="" - -#yaml libraries -YAML_LDFLAGS+="" - -#fortran netcdf includes -NF_FLAGS+=$(nf-config --fflags) - -#c netcdf includes -NC_FLAGS+=$(nc-config --cflags) - -#netcdf libraries -NC_LDFLAGS=$(nc-config --libs | nf-config --flibs) - -#fortran and c compiler -FC=mpif90 -CC=mpicc - -#fms fortran, c, library compiler flags -FMS_FCFLAGS+="$NF_FLAGS -fPIC" -FMS_CFLAGS+="$NC_FLAGS $YAML_FLAGS -fPIC" -FMS_LDFLAGS+="$NC_LDFLAGS $YAML_LDFLAGS" - -#cfms fortran, c, library compiler flags -#cfms does not need the netcdf flags. -#these will be removed once cfms configure.ac is updated -cFMS_FCFLAGS+="-fPIC $NF_FLAGS" -cFMS_CFLAGS+="-fPIC $NC_FLAGS" -cFMS_LDFLAGS+="" - -curr_dir=$PWD - -#fms installation path -fms_install=$curr_dir/pyfms/lib/FMS - -#cfms installation path -cfms_install=$curr_dir/pyfms/lib/cFMS - -#cfms to compile -cfms_dir=$curr_dir/cFMS - -#fms to compile -fms_dir=$cfms_dir/FMS - -#compile fms with autotools -cd $fms_dir -autoreconf -iv -./configure --enable-portable-kinds \ - --with-yaml \ - --prefix=$fms_install \ - FC=$FC \ - CC=$CC \ - FCFLAGS="$FMS_FCFLAGS" \ - CFLAGS="$FMS_CFLAGS" \ - LDFLAGS="$FMS_LDFLAGS" -make install - -cd $currdir - -#compile cFMS with autotools -cd $cfms_dir -autoreconf -iv -./configure --with-fms=$fms_install \ - --prefix=$cfms_install \ - FC=$FC \ - CC=$CC \ - FCFLAGS="$cFMS_FCFLAGS" \ - CFLAGS="$cFMS_CFLAGS" \ - LDFLAGS="$cFMS_LDFLAGS" -make install - -cd $currdir diff --git a/pyfms/cfms.py b/pyfms/cfms.py index 72a570e..fe962d2 100644 --- a/pyfms/cfms.py +++ b/pyfms/cfms.py @@ -1,5 +1,4 @@ import ctypes -import os import pyfms @@ -26,14 +25,11 @@ def init(libpath: str = None): # todo reset all _function parameters to None if libpath is None: - _libpath = os.path.dirname(__file__) + "/lib/cFMS/lib/libcFMS.so" + _libpath = "libcFMS.so" try: _lib = ctypes.cdll.LoadLibrary(_libpath) - except OSError: - print( - f"{_libpath} does not exist. Please provide a path to cFMS with\ - pyfms.cfms.init(libpath=path_to_cfms)" - ) + except Exception as e: + print(f"{type(e).__name__}: {e}") return else: _libpath = libpath diff --git a/setup.py b/setup.py index e8d16e2..74b5f25 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,31 @@ import subprocess from setuptools import find_namespace_packages, setup -from setuptools.command.build import build +from setuptools.command.editable_wheel import editable_wheel as _editable_wheel +from setuptools.command.install import install as _install -class CustomBuild(build): +class editable_wheel(_editable_wheel): def run(self): - with open("install.log", "w") as f: - subprocess.run(["./compile_c_libs.sh"], stdout=f, check=True) - build.run(self) + print("Installing cFMS") + try: + subprocess.run(["conda", "install", "-y", "-c", "file:///home/Frank.Malatino/cfms_conda_channel", "cfms"], check=True, capture_output=True, text=True) + except subprocess.CalledProcessError as e: + print(f"Error during conda install of cFMS: {e}") + print("STDOUT:", e.stdout) + print("STDERR:", e.stderr) + _editable_wheel.run(self) + +class install(_install): + def run(self): + print("Installing cFMS") + try: + subprocess.run(["conda", "install", "-y", "-c", "file:///home/Frank.Malatino/cfms_conda_channel", "cfms"], check=True, capture_output=True, text=True) + except subprocess.CalledProcessError as e: + print(f"Error during conda install of cFMS: {e}") + print("STDOUT:", e.stdout) + print("STDERR:", e.stderr) + _install.run(self) test_requirements = ["pytest", "pytest-subtests", "coverage"] @@ -44,7 +61,7 @@ def run(self): name="pyfms", license="", packages=find_namespace_packages(include=["pyfms", "pyfms.*"]), - cmdclass={"build": CustomBuild}, + cmdclass={"editable_wheel": editable_wheel, "install": install}, include_package_data=True, url="https://github.com/fmalatino/pyFMS.git", version="2024.02.0",