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

Commit

Permalink
More updates to the packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 8, 2023
1 parent 6918164 commit 8e200e4
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 45 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
##################################################
# Define the project and the depencies that it has
##################################################

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)
MESSAGE(STATUS "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}\nPROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}\n")

# The following section is modified from Numpy f2py documentation
IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
MESSAGE(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n")
ENDIF()

# Ensure scikit-build modules
FIND_PACKAGE(Python3 COMPONENTS Interpreter Development REQUIRED)
IF (NOT SKBUILD)
FIND_PACKAGE(Python3 COMPONENTS Interpreter Development REQUIRED)
EXECUTE_PROCESS(
COMMAND "${Python3_EXECUTABLE}"
-c "import os, skbuild; print(os.path.dirname(skbuild.__file__))"
Expand All @@ -38,16 +38,20 @@ ENDIF()

SET(PYTHON_EXTENSION_MODULE_SUFFIX ".${Python3_SOABI}" CACHE STRING "Suffix for python extension modules")

INCLUDE(CTest)
# 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 ${Python3_EXECUTABLE} DIRECTORY)
IF(EXISTS "${_python_bin_dir}/../conda-meta")
MESSAGE("-- Detected conda environment, setting INSTALL_RPATH_USE_LINK_PATH")
SET(_using_conda On)
ELSE()
SET(_using_conda Off)
ENDIF()

# Add our local modules to the module path
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")

############################################################
# Define the actual files and folders that make up the build
############################################################

# Define some directories
# Define some directories that are important to the build
SET(SRC ${CMAKE_SOURCE_DIR}/src)
SET(LIB ${CMAKE_SOURCE_DIR}/lib)
SET(BIN ${CMAKE_SOURCE_DIR}/bin)
Expand Down
3 changes: 3 additions & 0 deletions distclean.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ ELSE()
SET(TOPDIR "${CMAKE_SOURCE_DIR}")
ENDIF()

SET(SKBUILD_DIR "_skbuild")

MACRO(GET_PARENT_DIRECTORIES search_string return_list grandparents)
FILE(GLOB_RECURSE new_list ${search_string})
SET(dir_list "")
Expand Down Expand Up @@ -61,6 +63,7 @@ SET(DEL ${TOPDIRECTORIES}
${CMAKEFILES}
${CMAKETESTING}
${CMAKETESTFILES}
${SKBUILD_DIR}
)

# If we are not in the build dir, delete that as well
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requires = [
"setuptools>=42",
"scikit-build>=0.13",
"cmake>=3.20.1",
"cython>=3.0.0",
"ninja",
]
build-backend = "setuptools.build_meta"
29 changes: 9 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,24 @@
"""

from skbuild import setup
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 = 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=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),
cmake_args=[
'-DCMAKE_BUILD_TYPE=RELEASE',
'-DMACHINE_CODE_VALUE="generic"',
'-DUSE_COARRAY:BOOL=OFF',
'-DUSE_OPENMP:BOOL=ON',
'-DBUILD_SHARED_LIBS:BOOL=OFF'
],
install_requires= [
'numpy>=1.24.3',
'pandas>=1.5.3',
Expand All @@ -54,4 +43,4 @@
'astroquery>=0.4.6',
'tqdm>=4.65.0',
],
packages=find_packages())
packages=['swiftest'])
30 changes: 16 additions & 14 deletions src/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Use the old method to get Python packages, as that's what scikit-build uses
CMAKE_POLICY(SET CMP0148 OLD)

SET(CYTHON_FLAGS
"--directive binding=True,boundscheck=False,wraparound=False,embedsignature=True,always_allow_keywords=True"
CACHE STRING "The directives for Cython compilation.")
FIND_PACKAGE(PythonInterp REQUIRED)
FIND_PACKAGE(Cython REQUIRED)
FIND_PACKAGE(PythonExtensions REQUIRED)
Expand All @@ -14,24 +18,22 @@ IF(${PYTHON_VERSION_MAJOR} EQUAL 3
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})
INSTALL(TARGETS ${SWIFTEST_BINDINGS} DESTINATION swiftest)

IF(APPLE)
SET_TARGET_PROPERTIES(${SWIFTEST_BINDINGS} PROPERTIES INSTALL_RPATH "@loader_path")
ELSE()
SET_TARGET_PROPERTIES(${SWIFTEST_BINDINGS} PROPERTIES INSTALL_RPATH "\$ORIGIN")
ENDIF()

IF(_using_conda OR DEFINED ENV{CIBUILDWHEEL})
MESSAGE(STATUS "Conda detected. Setting INSTALL_RPATH_USE_LINK_PATH to True")
SET_TARGET_PROPERTIES(${SWIFTEST_BINDINGS} PROPERTIES INSTALL_RPATH_USE_LINK_PATH True)
ENDIF()
6 changes: 3 additions & 3 deletions swiftest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
If not, see: https://www.gnu.org/licenses.
"""

from constants import *
from simulation_class import Simulation
from swiftest_bindings import driver
from swiftest.constants import *
from swiftest.simulation_class import Simulation
from swiftest.swiftest_bindings import driver

0 comments on commit 8e200e4

Please sign in to comment.