Skip to content

Commit

Permalink
python: rewrite Python high level API in python
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentebolea committed Nov 22, 2023
1 parent a8e02fe commit 67d769d
Show file tree
Hide file tree
Showing 10 changed files with 572 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ if(ADIOS2_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

add_subdirectory(python)

#------------------------------------------------------------------------------#
# Testing
#------------------------------------------------------------------------------#
Expand Down
4 changes: 2 additions & 2 deletions bindings/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Python_add_library(adios2_py MODULE
py11File.cpp py11File.tcc
py11glue.cpp
)
target_compile_definitions(adios2_py PRIVATE "ADIOS2_PYTHON_MODULE_NAME=adios2${ADIOS2_LIBRARY_SUFFIX}")
target_compile_definitions(adios2_py PRIVATE "ADIOS2_PYTHON_MODULE_NAME=adios2_bindings${ADIOS2_LIBRARY_SUFFIX}")
if(ADIOS2_HAVE_MPI)
target_sources(adios2_py PRIVATE
py11ADIOSMPI.cpp
Expand All @@ -29,7 +29,7 @@ target_link_libraries(adios2_py PRIVATE
${maybe_adios2_cxx11_mpi} adios2_cxx11
${maybe_adios2_core_mpi} adios2_core
adios2::thirdparty::pybind11
${maybe_mpi4py} Python::NumPy
${maybe_mpi4py}
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in
Expand Down
1 change: 1 addition & 0 deletions cmake/ADIOSFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function(python_add_test)
set_property(TEST ${ARGS_NAME} PROPERTY
ENVIRONMENT
"PYTHONPATH=${ADIOS2_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}:$ENV{PYTHONPATH}"
"MODULEPATH=${ADIOS2_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}:$ENV{MODULEPATH}"
)
else()
set_property(TEST ${ARGS_NAME} PROPERTY
Expand Down
4 changes: 2 additions & 2 deletions cmake/DetectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,12 @@ if(NOT SHARED_LIBS_SUPPORTED)
endif()

if(ADIOS2_USE_Python STREQUAL AUTO)
find_package(Python 3 COMPONENTS Interpreter Development NumPy)
find_package(Python 3 COMPONENTS Interpreter Development)
if(Python_FOUND AND ADIOS2_HAVE_MPI)
find_package(PythonModule COMPONENTS mpi4py mpi4py/mpi4py.h)
endif()
elseif(ADIOS2_USE_Python)
find_package(Python 3 REQUIRED COMPONENTS Interpreter Development NumPy)
find_package(Python 3 REQUIRED COMPONENTS Interpreter Development)
if(ADIOS2_HAVE_MPI)
find_package(PythonModule REQUIRED COMPONENTS mpi4py mpi4py/mpi4py.h)
endif()
Expand Down
13 changes: 13 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#------------------------------------------------------------------------------#
# Distributed under the OSI-approved Apache License, Version 2.0. See
# accompanying file Copyright.txt for details.
#------------------------------------------------------------------------------#

add_custom_target(adios_python COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/adios
${CMAKE_PYTHON_OUTPUT_DIRECTORY}/adios)

install(DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/adios
DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/adios
COMPONENT adios2_python-python
)
3 changes: 3 additions & 0 deletions python/adios/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/python3

from . import adios
7 changes: 7 additions & 0 deletions python/adios/adios.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/python3

from . import file

def open(name, mode, engine_type="BPFile", config_file = None):
"""High-level API, file object open"""
return file.File(name, mode, engine_type)
Loading

0 comments on commit 67d769d

Please sign in to comment.