Skip to content

Commit

Permalink
chore: Update test-meson workflow to exclude building wheels and setu…
Browse files Browse the repository at this point in the history
…p tmate session for debugging
  • Loading branch information
sunt05 committed May 15, 2024
1 parent 987875d commit 47197e4
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 56 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/test-meson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ jobs:
meson setup build
meson compile -C build
- name: Build wheels
uses: pypa/[email protected]
env:
# SETUPTOOLS_USE_DISTUTILS: stdlib
CC: gcc
CXX: g++
with:
# package-dir: ./src/supy
output-dir: wheelhouse
# config-file: ./src/supy/pyproject.toml
# - name: Build wheels
# uses: pypa/[email protected]
# env:
# # SETUPTOOLS_USE_DISTUTILS: stdlib
# CC: gcc
# CXX: g++
# with:
# # package-dir: ./src/supy
# output-dir: wheelhouse
# # config-file: ./src/supy/pyproject.toml

# - name: Setup tmate session for debugging
# if: failure()
Expand Down
99 changes: 53 additions & 46 deletions src/supy_driver/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fpp_flags = ['-E', '-x', 'f95-cpp-input', '-fPIC']
# include the SUEWS library
dir_suews = meson.current_source_dir() / '../suews'

include_dir_suews = include_directories( '../suews/mod')
include_dir_suews = include_directories('../suews/mod')

dir_src_suews = dir_suews / 'src'

Expand Down Expand Up @@ -134,52 +134,65 @@ endforeach
prog_f90wrap = find_program('f90wrap')
file_kind_map = files('kind_map')

# gen_f90wrap_f90 = custom_target(
# 'f90wrap_f90',
# command: [
# prog_f90wrap,
# '-m', 'supy_driver',
# '@INPUT@',
# '-k', file_kind_map,
# '-v',
# '--skip', 'error_hint',
# '&&',
# py,
# '@CURRENT_SOURCE_DIR@/move_output_gen.py',
# '@OUTPUT@',
# '@OUTDIR@',
# ],
# input: [gen_fpp_files],
# build_by_default: true,
# output: [out_wrap_f90],
# depends: build_suews,
# )
gen_f90wrap_f90 = custom_target(
'f90wrap_f90',
command: [
prog_f90wrap,
'-m', 'supy_driver',
'@INPUT@',
'-k', file_kind_map,
'-v',
'--skip', 'error_hint',
'&&',
py,
'@CURRENT_SOURCE_DIR@/move_output_gen.py',
'@OUTPUT@',
'@CURRENT_SOURCE_DIR@/run_f90wrap.py', # Path to your Python wrapper script
prog_f90wrap, # Assuming this is defined elsewhere as the f2py executable
'supy_driver',
'@CURRENT_SOURCE_DIR@',
'@OUTDIR@',
'@INPUT@',
'@OUTPUT@',
],
input: [gen_fpp_files, 'move_output_gen.py'],
build_by_default: true,
input: [gen_fpp_files],
output: [out_wrap_f90],
depends: build_suews,
build_by_default: true,
)

##################################################################
# 3. use f2py-f90wrap to generate the C file for the python interface
# build the driver module c file
prog_f2py_f90wrap = find_program('f2py-f90wrap')
# message('Output files will be generated at:', meson.current_build_dir())
gen_module_c = custom_target(
output: [
'_supy_drivermodule.c',
'_supy_driver-f2pywrappers.f',
],
command: [
prog_f2py_f90wrap,
'-m', '_supy_driver',
'@INPUT@',
# IMPORTANT: lower case the module name
'--lower', '&&',
py,
'@CURRENT_SOURCE_DIR@/move_output_gen.py',
'@OUTPUT@',
'@CURRENT_SOURCE_DIR@/run_f2py.py', # Path to your Python wrapper script
prog_f2py_f90wrap, # Assuming this is defined elsewhere as the f2py executable
'_supy_driver',
'@CURRENT_SOURCE_DIR@',
'@OUTDIR@',
'@INPUT@',
'@OUTPUT@',
],
input: [gen_f90wrap_f90],
output: [
'_supy_drivermodule.c',
'_supy_driver-f2pywrappers.f',
],
depends: [gen_f90wrap_f90],
build_by_default: true,

)

##################################################################
Expand Down Expand Up @@ -224,7 +237,7 @@ dep_fortranobject = declare_dependency(

dep_lib_src = declare_dependency(
link_args: [
'-L'+meson.current_build_dir(), # the path is relative to the build directory when running meson
'-L' + meson.current_build_dir(), # the path is relative to the build directory when running meson
'-lsrc',
],
)
Expand All @@ -237,7 +250,7 @@ dep_lib_suews = declare_dependency(
)
dep_suews = [dep_lib_src, dep_lib_suews]

inc_suews_mod = include_directories( '../suews/mod')
inc_suews_mod = include_directories('../suews/mod')

ext_supy_driver = py.extension_module(
'_supy_driver',
Expand All @@ -260,36 +273,30 @@ ext_supy_driver = py.extension_module(
subdir: 'supy',
)

# move the generated `supy_driver.py` to the correct directory
# this is kind of dummy, but it is necessary to make the installation work
gen_supy_driver_py = custom_target(
'supy_driver',
command: [
prog_f90wrap,
'-m', 'supy_driver',
'@INPUT@',
'-k', file_kind_map,
'-v',
'--skip', 'error_hint',
'&&',
py,
'@CURRENT_SOURCE_DIR@/move_output_gen.py',
'@OUTPUT@',
meson.current_build_dir() / 'supy_driver.py', # this file is actually generated by gen_f90wrap_f90
'@OUTDIR@',
],
input: [gen_fpp_files, 'move_output_gen.py'],
input: [gen_fpp_files],
build_by_default: true,
output: ['supy_driver.py'],
depends: ext_supy_driver,
install: true,
install_dir: [py.get_install_dir() / 'supy'], # this is the directory where the python module will be installed
)

##################################################################
# 5. add the test for the python module
# ##################################################################
# # 5. add the test for the python module

# add test for the python module
test(
'test_supy_driver',
py,
args: ['-c', 'import supy_driver; print(dir(supy_driver))'],
depends: ext_supy_driver,
)
# # add test for the python module
# test(
# 'test_supy_driver',
# py,
# args: ['-c', 'import supy_driver; print(dir(supy_driver))'],
# depends: ext_supy_driver,
51 changes: 51 additions & 0 deletions src/supy_driver/run_f2py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import subprocess
import sys
import os


def main():
f2py_executable = sys.argv[1] # path to f2py or f2py part of numpy
module_name = sys.argv[2]
current_source_dir = sys.argv[3]
output_dir = sys.argv[4]
input_output_files = sys.argv[5:]
input_files = input_output_files[0:-2]
output_files = input_output_files[-2:]
# output_files = sys.argv[5:] # List of output file paths

# Call f2py to generate the modules
try:
subprocess.check_call(
[
f2py_executable,
"-m",
module_name,
*input_files,
"--lower",
]
)
print("f2py call successful")
except subprocess.CalledProcessError as e:
print(f"Error calling f2py: {e}")
return 1

# Move generated files to the output directory
try:
subprocess.check_call(
[
"python",
os.path.join(current_source_dir, "move_output_gen.py"),
*output_files,
output_dir,
]
)
print("Output files moved successfully")
except subprocess.CalledProcessError as e:
print(f"Error moving output files: {e}")
return 1

return 0


if __name__ == "__main__":
sys.exit(main())
58 changes: 58 additions & 0 deletions src/supy_driver/run_f90wrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import subprocess
import sys
import os


def main():
f90wrap_executable = sys.argv[1] # path to f2py or f2py part of numpy
module_name = sys.argv[2]
current_source_dir = sys.argv[3]
output_dir = sys.argv[4]
input_output_files = sys.argv[5:]
# only .fpp files are input files
input_files = [f for f in input_output_files if f.endswith(".fpp")]
# only .f90 files are output files
output_files = [f for f in input_output_files if f.endswith(".f90")]
# input_files = input_output_files[0:-2]
# output_files = input_output_files[-2:]
# output_files = sys.argv[5:] # List of output file paths

# Call f2py to generate the modules
try:
subprocess.check_call(
[
f90wrap_executable,
"-m",
module_name,
*input_files,
"-k",
os.path.join(current_source_dir, "kind_map"),
"--skip",
"error_hint",
]
)
print("f90wrap call successful")
except subprocess.CalledProcessError as e:
print(f"Error calling f2py: {e}")
return 1

# Move generated files to the output directory
try:
subprocess.check_call(
[
"python",
os.path.join(current_source_dir, "move_output_gen.py"),
*output_files,
output_dir,
]
)
print("Output files moved successfully")
except subprocess.CalledProcessError as e:
print(f"Error moving output files: {e}")
return 1

return 0


if __name__ == "__main__":
sys.exit(main())

0 comments on commit 47197e4

Please sign in to comment.