Skip to content

Commit

Permalink
Merge pull request #325 from MeasureTransport/mparno/pip-rpath
Browse files Browse the repository at this point in the history
Fixes in pip install path
  • Loading branch information
michael-c-brennan authored Apr 10, 2023
2 parents 1b54a57 + 0e55158 commit 37a54a7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(MParT VERSION 2.0.1)
project(MParT VERSION 2.0.2)

message(STATUS "Will install MParT to ${CMAKE_INSTALL_PREFIX}")

Expand Down Expand Up @@ -53,6 +53,7 @@ option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

# #############################################################
# RPATH settings
# See https://gist.github.com/kprussing/db21614ca5b51cedff07dfb70059f280 for scikit-build example

# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
Expand All @@ -70,9 +71,9 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)

if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
# if("${isSystemDir}" STREQUAL "-1")
# set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# endif("${isSystemDir}" STREQUAL "-1")

# #############################################################
# Dependencies
Expand Down
12 changes: 11 additions & 1 deletion bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ target_link_libraries(pympart PRIVATE mpart Kokkos::kokkos Eigen3::Eigen ${EXT_L

# Add an installation target for the python bindings
install(TARGETS pympart DESTINATION "${PYTHON_INSTALL_PREFIX}")
install(DIRECTORY package/ DESTINATION "${PYTHON_INSTALL_PREFIX}")
install(DIRECTORY package/ DESTINATION "${PYTHON_INSTALL_PREFIX}")

# See https://gist.github.com/kprussing/db21614ca5b51cedff07dfb70059f280
#set(lib_path "${PYTHON_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
#message(STATUS "LIB_PATH = ${lib_path}")
#list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${lib_path}" is_system)
if(SKBUILD)
if (SKBUILD_LIB_RPATH)
set_target_properties(pympart PROPERTIES INSTALL_RPATH "${SKBUILD_LIB_RPATH}")
endif()
endif()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ license={file="LICENSE.txt"}
readme="README.md"
requires-python = ">=3.7"
description="A Monotone Parameterization Toolkit"
version="2.0.1"
version="2.0.2"
keywords=["Measure Transport", "Monotone", "Transport Map", "Isotonic Regression", "Triangular", "Knothe-Rosenblatt"]

[project.urls]
Expand Down
34 changes: 33 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
from skbuild import setup

import os, sys, site
import warnings

def get_install_locations():
"""Return the installation directory, or '' if no directory could be found
Adapted from stack overflow post https://stackoverflow.com/a/36205159
"""

if '--user' in sys.argv:
paths = (site.getusersitepackages(),)
else:
py_version = f'{sys.version_info[0]}.{sys.version_info[1]}'
paths = [
sys.prefix + f'/lib/python{py_version}/dist-packages/',
sys.prefix + f'/lib/python{py_version}/site-packages/',
sys.prefix + f'/local/lib/python{py_version}/dist-packages/',
sys.prefix + f'/local/lib/python{py_version}/site-packages/',
f'/Library/Frameworks/Python.framework/Versions/{py_version}/lib/python{py_version}/site-packages/'
]

for path in paths:
if os.path.exists(path):
parts = path.split('/')
lib_indices = [index for index, item in enumerate(parts) if item == 'lib']
return path, '/'.join(parts[0:(lib_indices[-1]+1)])

return ''

site_folder, lib_folder = get_install_locations()


setup(
packages=['mpart'],
package_dir={'mpart': 'bindings/python/package'},
package_data={'mpart':['**/*pympart*']},
include_package_data=True,
cmake_args=['-DKokkos_ENABLE_THREADS:BOOL=ON', '-DPYTHON_INSTALL_SUFFIX=bindings/python/package/', '-DMPART_JULIA:BOOL=OFF', '-DMPART_MATLAB:BOOL=OFF', '-DMPART_BUILD_TESTS:BOOL=OFF', '-DMPART_PYTHON:BOOL=ON', '-DPYTHON_INSTALL_PREFIX=']
cmake_args=['-DKokkos_ENABLE_THREADS:BOOL=ON', f'-DSKBUILD_LIB_RPATH={lib_folder}', f'-DSKBUILD_SITE_PATH={site_folder}', '-DPYTHON_INSTALL_SUFFIX=bindings/python/package/', '-DMPART_JULIA:BOOL=OFF', '-DMPART_MATLAB:BOOL=OFF', '-DMPART_BUILD_TESTS:BOOL=OFF', '-DMPART_PYTHON:BOOL=ON', '-DPYTHON_INSTALL_PREFIX=']
)

0 comments on commit 37a54a7

Please sign in to comment.