Skip to content

Commit

Permalink
add ectrans python interface ectrans4py
Browse files Browse the repository at this point in the history
  • Loading branch information
walidchikhi committed Oct 23, 2024
1 parent 8227b3d commit 8d9307f
Show file tree
Hide file tree
Showing 15 changed files with 1,372 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ecbuild_add_option( FEATURE SINGLE_PRECISION
DEFAULT ON
DESCRIPTION "Support for Single Precision" )


if( HAVE_SINGLE_PRECISION )
set( single "single" )
endif()
Expand Down Expand Up @@ -64,6 +65,13 @@ ecbuild_add_option( FEATURE ETRANS
DEFAULT OFF
DESCRIPTION "Include Limited-Area-Model Transforms" )


ecbuild_add_option( FEATURE ECTRANS4PY
DEFAULT OFF
CONDITION HAVE_ETRANS
DESCRIPTION "Compile ectrans4py interface routines for python binding w/ ctypesForFortran" )


ectrans_find_lapack()

### Add sources and tests
Expand Down
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include AUTHORS
include CMakeLists.txt
include LICENSE
include README.md
include VERSION
recursive-include src *
recursive-include cmake *
recursive-include tests *
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build-system]
requires = ["setuptools", "wheel", "scikit-build"]
build-backend = "setuptools.build_meta"

32 changes: 32 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import re
import ast
from skbuild import setup

def get_version(): # remove this part
version_file = os.path.join("src", "ectrans4py", "__init__.py")
with open(version_file, "r", encoding="utf-8") as f:
content = f.read()
version_match = re.search(r"^__version__\s*=\s*['\"]([^'\"]*)['\"]", content, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")

version=get_version()
# ectrans4py package :
setup(
name="ectrans4py",
version=version,
packages=['ectrans4py'],
cmake_minimum_required_version="3.13",
cmake_args=[
'-DENABLE_ETRANS=ON',
'-DENABLE_ECTRANS4PY=ON',
'-DENABLE_SINGLE_PRECISION=OFF',
'-DENABLE_OMP=OFF',
],
package_dir={"": "src"},
cmake_install_dir="src/ectrans4py",
setup_requires=["scikit-build", "setuptools"],
install_requires=["numpy", "ctypesforfortran==1.1.3"],
)
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ if( HAVE_TRANSI )
endif()
if( HAVE_ETRANS )
add_subdirectory(etrans)
endif()
endif()
if(HAVE_ECTRANS4PY)
add_subdirectory(ectrans4py)
endif()
20 changes: 20 additions & 0 deletions src/ectrans4py/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if(HAVE_ETRANS)
# (using CMAKE_CURRENT_SOURCE_DIR is necessary because sources are in a different directory than the target library (trans_${prec}))
ecbuild_list_add_pattern(
LIST ectrans4py_src
GLOB ${CMAKE_CURRENT_SOURCE_DIR}/*.F90
QUIET
)

set(HAVE_dp ${HAVE_DOUBLE_PRECISION})
set(prec dp)

if(HAVE_${prec})
# Add sources
target_sources(trans_${prec} PRIVATE ${ectrans4py_src})
endif()

else()
ecbuild_critical("To activate the ectrans Python interface, you must enable the ETRANS option.")
endif()

Loading

0 comments on commit 8d9307f

Please sign in to comment.