From 259a7dd5910a94f2822d407b508f4c61117e9f63 Mon Sep 17 00:00:00 2001 From: Matthew Parno Date: Tue, 28 Mar 2023 16:26:49 -0400 Subject: [PATCH 1/4] Attempt at fixing rpath during pip installation. --- CMakeLists.txt | 7 ++++--- bindings/python/CMakeLists.txt | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 28f1785e..6ae79159 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 9194e43f..52090da1 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -37,4 +37,18 @@ 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}") \ No newline at end of file +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) + set_target_properties(pympart PROPERTIES + INSTALL_RPATH "\$ORIGIN/../../../../lib") + # # The following is necessary for installation in a virtual + # # environment `python -m pip venv env` + # set_target_properties(_mwe PROPERTIES + # INSTALL_RPATH_USE_LINK_PATH TRUE + # INSTALL_RPATH "${lib_path}") +endif() \ No newline at end of file From 781e225873b528e143df271c87811ed14a3e1b94 Mon Sep 17 00:00:00 2001 From: Matthew Parno Date: Wed, 29 Mar 2023 07:43:56 -0400 Subject: [PATCH 2/4] Extracting lib install path in setup.py and passing to CMake for RPATH settings with SKBUILD. --- bindings/python/CMakeLists.txt | 10 +++------- setup.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 52090da1..ab8e26cd 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -44,11 +44,7 @@ install(DIRECTORY package/ DESTINATION "${PYTHON_INSTALL_PREFIX}") #message(STATUS "LIB_PATH = ${lib_path}") #list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${lib_path}" is_system) if(SKBUILD) - set_target_properties(pympart PROPERTIES - INSTALL_RPATH "\$ORIGIN/../../../../lib") - # # The following is necessary for installation in a virtual - # # environment `python -m pip venv env` - # set_target_properties(_mwe PROPERTIES - # INSTALL_RPATH_USE_LINK_PATH TRUE - # INSTALL_RPATH "${lib_path}") + if (SKBUILD_LIB_RPATH) + set_target_properties(pympart PROPERTIES INSTALL_RPATH "${SKBUILD_LIB_RPATH}") + endif() endif() \ No newline at end of file diff --git a/setup.py b/setup.py index b81a2121..4a76ccb7 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,39 @@ from skbuild import setup +import os, sys, site + +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 = '%s.%s' % (sys.version_info[0], sys.version_info[1]) + paths = (s % (py_version) for s in ( + sys.prefix + '/lib/python%s/dist-packages/', + sys.prefix + '/lib/python%s/site-packages/', + sys.prefix + '/local/lib/python%s/dist-packages/', + sys.prefix + '/local/lib/python%s/site-packages/', + '/Library/Python/%s/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='] ) \ No newline at end of file From e83960b05d0207bc21eacc7af921fe3546d90053 Mon Sep 17 00:00:00 2001 From: Matthew Parno Date: Wed, 29 Mar 2023 07:54:27 -0400 Subject: [PATCH 3/4] Likely fix to framework installation path of python. --- setup.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 4a76ccb7..0c55b3d1 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ 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 @@ -11,20 +12,21 @@ def get_install_locations(): if '--user' in sys.argv: paths = (site.getusersitepackages(),) else: - py_version = '%s.%s' % (sys.version_info[0], sys.version_info[1]) - paths = (s % (py_version) for s in ( - sys.prefix + '/lib/python%s/dist-packages/', - sys.prefix + '/lib/python%s/site-packages/', - sys.prefix + '/local/lib/python%s/dist-packages/', - sys.prefix + '/local/lib/python%s/site-packages/', - '/Library/Python/%s/site-packages/', - )) + 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() From 0e55158c8355b5964f1352f14ab68b0b2cb40382 Mon Sep 17 00:00:00 2001 From: Daniel Sharp Date: Mon, 10 Apr 2023 10:42:23 -0400 Subject: [PATCH 4/4] Bump pip/cmake version for next release --- CMakeLists.txt | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ae81642..f7edc515 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") diff --git a/pyproject.toml b/pyproject.toml index 8be97bea..679ba838 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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]