From 6918164feca59ed5c8ddf99889b14e046db6a2b6 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Tue, 8 Aug 2023 15:41:37 -0400 Subject: [PATCH] More restructuring and progress getting the scikit-build setup working. --- .gitignore | 3 ++- CMakeLists.txt | 13 +++------- pyproject.toml | 8 ++++++ requirements.txt | 15 +++++++++++ setup.py | 50 ++++++++++++++++++++++++------------- src/CMakeLists.txt | 6 ++--- src/bindings/CMakeLists.txt | 37 +++++++++++++++++++++++++++ swiftest/__init__.py | 2 +- 8 files changed, 103 insertions(+), 31 deletions(-) create mode 100644 pyproject.toml create mode 100644 requirements.txt create mode 100644 src/bindings/CMakeLists.txt diff --git a/.gitignore b/.gitignore index bfbcc463e..28d107886 100644 --- a/.gitignore +++ b/.gitignore @@ -25,10 +25,11 @@ dump* **/.DS_Store !python/swiftest/tests/test_suite.py !version.txt +!requirements.txt +!pyproject.toml **/_skbuild - #Documentation !docs/* !docs/*/* diff --git a/CMakeLists.txt b/CMakeLists.txt index ddd78cebc..d375d3d13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ ################################################## CMAKE_MINIMUM_REQUIRED(VERSION 3.20.1) + # Get version stored in text file FILE(READ "version.txt" VERSION) PROJECT(swiftest VERSION ${VERSION} LANGUAGES C Fortran) @@ -35,14 +36,7 @@ IF (NOT SKBUILD) MESSAGE(STATUS "Looking in ${SKBLD_DIR}/resources/cmake for CMake modules") ENDIF() -# scikit-build style includes -FIND_PACKAGE(Cython REQUIRED) -SET(PYTHON_EXTENSION_MODULE_SUFFIX "${Python3_SOABI}" CACHE STRING "Suffix for python extension modules") - -# Communicate version number and other CMake build variables to the source code -SET(SETUP_PY_IN "${PROJECT_SOURCE_DIR}/setup.py.in") -SET(SETUP_PY_OUT "${PROJECT_SOURCE_DIR}/setup.py") -CONFIGURE_FILE(${SETUP_PY_IN} ${SETUP_PY_OUT}) +SET(PYTHON_EXTENSION_MODULE_SUFFIX ".${Python3_SOABI}" CACHE STRING "Suffix for python extension modules") INCLUDE(CTest) @@ -58,6 +52,7 @@ SET(SRC ${CMAKE_SOURCE_DIR}/src) SET(LIB ${CMAKE_SOURCE_DIR}/lib) SET(BIN ${CMAKE_SOURCE_DIR}/bin) SET(MOD ${CMAKE_SOURCE_DIR}/include) +SET(PY ${CMAKE_SOURCE_DIR}/swiftest) #SET(TEST ${CMAKE_SOURCE_DIR}/tests) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB}) @@ -69,7 +64,7 @@ SET(CMAKE_Fortran_MODULE_DIRECTORY ${MOD}) # The source for the SWIFTEST binary and have it placed in the bin folder ADD_SUBDIRECTORY(${SRC} ${BIN}) - +ADD_SUBDIRECTORY(${SRC}/bindings) # # Set up test directory # ENABLE_TESTING() # ADD_SUBDIRECTORY(${TEST}) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..aec44a1e3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[build-system] +requires = [ + "setuptools>=42", + "scikit-build>=0.13", + "cmake>=3.20.1", + "ninja", +] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..e27137833 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,15 @@ + python>=3.8 + numpy>=1.24.3 + pandas>=1.5.3 + scipy>=1.10.1 + xarray>=2022.11.0 + dask>=2022.1 + bottleneck>=1.3.5 + h5netcdf>=1.0.2 + netcdf4>=1.6.2 + matplotlib>=3.7.1 + astropy>=5.1 + astroquery>=0.4.6 + tqdm>=4.65.0 + x264>=1!157.20191217 + ffmpeg>=4.3.2 diff --git a/setup.py b/setup.py index 108cee6ee..a587f2421 100644 --- a/setup.py +++ b/setup.py @@ -11,31 +11,47 @@ """ from skbuild import setup -from setuptools import find_packages, Extension -from Cython.Build import cythonize +from setuptools import find_packages #, Extension +#from Cython.Build import cythonize import os # Build the pybindings extension that allows us to run the Fortran driver as a Python module. -root_dir = 'pybindings' -include_dirs = "" -include_dirs = include_dirs.split() -include_dirs.append(root_dir) -link_flags = "" -link_flags = link_flags.split() - -pybindings_extension = [Extension('swiftest.bindings', - [os.path.join(root_dir,'pybindings.pyx')], - extra_compile_args=['-fPIC', '-O3'], - extra_link_args=link_flags, - include_dirs=include_dirs, - )] +# root_dir = os.path.join(,'bindings') +# include_dirs = "" +# include_dirs = include_dirs.split() +# include_dirs.append(root_dir) +# link_flags = "" +# link_flags = link_flags.split() +# pybindings_extension = [Extension('swiftest.bindings', +# [os.path.join(root_dir,'bindings.pyx')], +# extra_compile_args=['-fPIC', '-O3'], +# extra_link_args=link_flags, +# include_dirs=include_dirs, +# package_data={"": [os.path.join(root_dir,'bindings.h')]} +# )] +with open('version.txt') as version_file: + version = version_file.read().strip() setup(name='swiftest', - version='2023.8.0', + version=version, author='David A. Minton', author_email='daminton@purdue.edu', url='https://github.itap.purdue.edu/MintonGroup/swiftest', python_requires=">3.8", license="GPLv3", - ext_modules = cythonize(pybindings_extension), + #ext_modules = cythonize(pybindings_extension), + install_requires= [ + 'numpy>=1.24.3', + 'pandas>=1.5.3', + 'scipy>=1.10.1', + 'xarray>=2022.11.0', + 'dask>=2022.1', + 'bottleneck>=1.3.5', + 'h5netcdf>=1.0.2', + 'netcdf4>=1.6.2', + 'matplotlib>=3.7.1', + 'astropy>=5.1', + 'astroquery>=0.4.6', + 'tqdm>=4.65.0', + ], packages=find_packages()) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d42627f7a..ec59d460d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -148,7 +148,7 @@ ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${DRIVER_src}) # Add the needed libraries and special compiler flags ##################################################### -TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PRIVATE ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS}) +TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS}) IF(USE_OPENMP) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${OpenMP_Fortran_FLAGS} ") @@ -156,8 +156,8 @@ IF(USE_OPENMP) ENDIF(USE_OPENMP) IF(USE_COARRAY) - TARGET_COMPILE_DEFINITIONS(${SWIFTEST_LIBRARY} PRIVATE -DCOARRAY) - TARGET_COMPILE_DEFINITIONS(${SWIFTEST_DRIVER} PRIVATE -DCOARRAY) + TARGET_COMPILE_DEFINITIONS(${SWIFTEST_LIBRARY} PUBLIC -DCOARRAY) + TARGET_COMPILE_DEFINITIONS(${SWIFTEST_DRIVER} PUBLIC -DCOARRAY) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${Coarray_Fortran_FLAGS} ") SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${Coarray_Fortran_FLAGS} ") ENDIF(USE_COARRAY) diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt new file mode 100644 index 000000000..1fec84b18 --- /dev/null +++ b/src/bindings/CMakeLists.txt @@ -0,0 +1,37 @@ +# Use the old method to get Python packages, as that's what scikit-build uses +CMAKE_POLICY(SET CMP0148 OLD) +FIND_PACKAGE(PythonInterp REQUIRED) +FIND_PACKAGE(Cython REQUIRED) +FIND_PACKAGE(PythonExtensions REQUIRED) + +# Avoid Cython/Python3.8 minor incompatibility warnings, see +# https://github.com/cython/cython/issues/3474. Note that this option is a bit +# expansive, but it's a temporary fix and we'll be testing on other Python +# versions concurrently so it shouldn't hide any real issues. ). +IF(${PYTHON_VERSION_MAJOR} EQUAL 3 + AND ${PYTHON_VERSION_MINOR} EQUAL 8 + AND NOT WIN32) + ADD_COMPILE_OPTIONS("-Wno-deprecated-declarations") +ENDIF() + + +# Detect when building against a conda environment set the _using_conda variable +# for use both in this file and in the parent +GET_FILENAME_COMPONENT(_python_bin_dir ${PYTHON_EXECUTABLE} DIRECTORY) +IF(EXISTS "${_python_bin_dir}/../conda-meta") + MESSAGE("-- Detected conda environment, setting INSTALL_RPATH_USE_LINK_PATH") + SET(_using_conda On) + SET(_using_conda On PARENT_SCOPE) +ELSE() + SET(_using_conda Off) + SET(_using_conda Off PARENT_SCOPE) +ENDIF() + +SET(SWIFTEST_BINDINGS swiftest_bindings) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +ADD_CYTHON_TARGET(${SWIFTEST_BINDINGS} bindings.pyx) +ADD_LIBRARY(${SWIFTEST_BINDINGS} MODULE ${SWIFTEST_BINDINGS}) +TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} ${SWIFTEST_LIBRARY} ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS}) +PYTHON_EXTENSION_MODULE(${SWIFTEST_BINDINGS}) +INSTALL(TARGETS ${SWIFTEST_BINDINGS} LIBRARY DESTINATION ${PY}) \ No newline at end of file diff --git a/swiftest/__init__.py b/swiftest/__init__.py index 2b9720bd7..8933c9d49 100644 --- a/swiftest/__init__.py +++ b/swiftest/__init__.py @@ -11,4 +11,4 @@ from constants import * from simulation_class import Simulation -from bindings import driver \ No newline at end of file +from swiftest_bindings import driver \ No newline at end of file