Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
More restructuring and progress getting the scikit-build setup working.
Browse files Browse the repository at this point in the history
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 8, 2023
1 parent 447eaaf commit 6918164
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ dump*
**/.DS_Store
!python/swiftest/tests/test_suite.py
!version.txt
!requirements.txt
!pyproject.toml
**/_skbuild



#Documentation
!docs/*
!docs/*/*
Expand Down
13 changes: 4 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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})
Expand All @@ -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})
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build-system]
requires = [
"setuptools>=42",
"scikit-build>=0.13",
"cmake>=3.20.1",
"ninja",
]
build-backend = "setuptools.build_meta"
15 changes: 15 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
50 changes: 33 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ 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} ")
SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${OpenMP_Fortran_FLAGS} ")
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)
Expand Down
37 changes: 37 additions & 0 deletions src/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
2 changes: 1 addition & 1 deletion swiftest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

from constants import *
from simulation_class import Simulation
from bindings import driver
from swiftest_bindings import driver

0 comments on commit 6918164

Please sign in to comment.