Skip to content

Commit

Permalink
Fix python modules windows (#19360) (#19362)
Browse files Browse the repository at this point in the history
* Fix visit's python module handling on Windows.

The DEST_DIR should be /path/to/build/lib/<CONFIG>/site-packages.
So, removed the 'lib/' part from DEST_DIR in calls to PYTHON_ADD_PIP_SETUP, and modified the function to use VISIT_LIBRARY_DIR instead of CMAKE_BINARY_DIR, as VISIT_LIBRARY_DIR accounts for the <CONFIG> part of the library path on Windows.

Modified VISIT_LIBRARY_DIR setup for Windows to use $<CONFIG> instead of ${CMAKE_CFG_INTDIR}, which has been deprecated.

* Add logic to cleanup `pip install`  build artifacts left in source.
  • Loading branch information
biagas committed Mar 9, 2024
1 parent f9d82ad commit db21752
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 11 deletions.
24 changes: 23 additions & 1 deletion src/CMake/FindVisItPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
# Removed install(CODE ...) logic for PIP installed modules, in favor of
# direct install of build/lib/site-packages directory via lib/CMakeLists.txt
#
# Kathleen Biagas, Tue Mar 5, 2024
# In PYTHON_ADD_PIP_SETUP, changed setting of abs_dest_path from using
# CMAKE_BINARY_DIR to VISIT_LIBRARY_DIR which accounts for build
# configuration being part of the library path on Windows.
# Also added cleanup of build artifacts left in source by `pip install`.
#
#****************************************************************************/

# - Find python libraries
Expand Down Expand Up @@ -388,7 +394,7 @@ FUNCTION(PYTHON_ADD_PIP_SETUP)
MESSAGE(STATUS "Configuring python pip setup: ${args_NAME}")

# dest for build dir
set(abs_dest_path ${CMAKE_BINARY_DIR}/${args_DEST_DIR})
set(abs_dest_path ${VISIT_LIBRARY_DIR}/${args_DEST_DIR})
if(WIN32)
# on windows, python seems to need standard "\" style paths
string(REGEX REPLACE "/" "\\\\" abs_dest_path ${abs_dest_path})
Expand All @@ -397,10 +403,22 @@ FUNCTION(PYTHON_ADD_PIP_SETUP)
# NOTE: With pip, you can't directly control build dir with an arg
# like we were able to do with distutils, you have to use TMPDIR
# TODO: we might want to explore this in the future

# add some cleanup (rm -rf) for the build artifacts left in source
# by pip-install
# since the egg-info dir for flow_vpe doesn't match its dirname
# (flow.egg-info instead of visit_flow_vpe.egg-info)
# there isn't a reliable way to only delete it when visit_flow_vpe
# calls this function. So, go ahead and add it to all the pip installs
# the 'rm -rf' will not error out if the dir doesn't exist

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${args_NAME}_build
COMMAND ${PYTHON_EXECUTABLE} -m pip install . -V --upgrade
--disable-pip-version-check --no-warn-script-location
--target "${abs_dest_path}"
COMMAND ${CMAKE_COMMAND} -E rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/build
COMMAND ${CMAKE_COMMAND} -E rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/${args_PY_MODULE_DIR}.egg-info
COMMAND ${CMAKE_COMMAND} -E rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/flow.egg-info
DEPENDS ${args_PY_SETUP_FILE} ${args_PY_SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

Expand All @@ -411,6 +429,10 @@ FUNCTION(PYTHON_ADD_PIP_SETUP)
if(DEFINED args_FOLDER)
blt_set_target_folder(TARGET ${args_NAME} FOLDER ${args_FOLDER})
endif()

if(WIN32)
visit_add_to_util_builds(${args_NAME})
endif()

ENDFUNCTION(PYTHON_ADD_PIP_SETUP)

Expand Down
13 changes: 11 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@
# Rename Windows visit_special_builds to visit_util_builds, add function
# for easier use of this uber-target.
#
# Kathleen Biagas, Tue Mar 5, 2024
# Modified VISIT_LIBRARY_DIR to use $<CONFIG> instead of
# ${CMAKE_CFG_INTDIR} on Windows, since the latter is deprecated.
#
#****************************************************************************

cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
Expand Down Expand Up @@ -730,9 +734,14 @@ if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${VISIT_BINARY_DIR}/exe CACHE INTERNAL "Single output directory for building all executables.")
endif()

set(VISIT_LIBRARY_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(VISIT_EXECUTABLE_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

if(WIN32)
string(APPEND VISIT_LIBRARY_DIR "/$<CONFIG>")
string(APPEND VISIT_EXECUTABLE_DIR "/$<CONFIG>")
endif()

set(VISIT_LIBRARY_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
set(VISIT_EXECUTABLE_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
set(CXX_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

#-----------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# Kathleen Biagas, Wed Dec 18, 2019
# Added run_visit_test_suite.bat.in configure file for windows.
#
# Kathleen Biagas, Tue Mar 5, 2024
# For PYTHON_ADD_PIP_SETUP change DEST_DIR from lib/site-packages to
# simply site-packages. The lib part handled in PYTHON_ADD_PIP_SETUP.
#
#****************************************************************************

IF(WIN32)
Expand Down Expand Up @@ -67,7 +71,7 @@ else()
py_src/visit_test_suite.py)

PYTHON_ADD_PIP_SETUP(NAME visit_testing_py_setup
DEST_DIR lib/site-packages
DEST_DIR site-packages
PY_MODULE_DIR visit_testing
PY_SETUP_FILE setup.py
PY_SOURCES ${pytesting_sources})
Expand Down
8 changes: 6 additions & 2 deletions src/visitpy/mpicom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
# Kathleen Biagas, Thu Sep 27 11:35:34 PDT 2018
# Change PYTHON_LIBRARIES to PYTHON_LIBRARY for consistency throughout visit.
#
# Kathleen Biagas, Tue Mar 5, 2024
# For PYTHON_ADD_PIP_SETUP change DEST_DIR from lib/site-packages to
# simply site-packages. The lib part handled in PYTHON_ADD_PIP_SETUP.
#
#****************************************************************************

SET(MPICOM_PY_SOURCES py_src/__init__.py
Expand All @@ -35,7 +39,7 @@ IF(VISIT_PARALLEL)

# Create the mpicom
PYTHON_ADD_HYBRID_MODULE(NAME mpicom
DEST_DIR lib/site-packages
DEST_DIR site-packages
PY_MODULE_DIR mpicom
PY_SETUP_FILE setup.py
PY_SOURCES "${MPICOM_PY_SOURCES}"
Expand Down Expand Up @@ -71,7 +75,7 @@ IF(VISIT_PARALLEL)
ELSE(VISIT_PARALLEL)
# we still need to build the module w/ the mpi stub
PYTHON_ADD_PIP_SETUP(NAME mpicom_py_setup
DEST_DIR lib/site-packages
DEST_DIR site-packages
PY_MODULE_DIR mpicom
PY_SETUP_FILE setup.py
PY_SOURCES ${MPICOM_PY_SOURCES})
Expand Down
6 changes: 5 additions & 1 deletion src/visitpy/pyavt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# Cyrus Harrison, Fri Feb 16 13:41:04 PST 2024
# Use new cmake commands for pip setup.
#
# Kathleen Biagas, Tue Mar 5, 2024
# For PYTHON_ADD_PIP_SETUP change DEST_DIR from lib/site-packages to
# simply site-packages. The lib part handled in PYTHON_ADD_PIP_SETUP.
#
#****************************************************************************

# deps for pyavt
Expand All @@ -24,7 +28,7 @@ SET(pyavt_sources py_src/__init__.py
py_src/templates/simple_query.py)

PYTHON_ADD_PIP_SETUP(NAME pyavt_py_setup
DEST_DIR lib/site-packages
DEST_DIR site-packages
PY_MODULE_DIR pyavt
PY_SETUP_FILE setup.py
PY_SOURCES ${pyavt_sources})
Expand Down
6 changes: 5 additions & 1 deletion src/visitpy/visit_flow/flow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# Cyrus Harrison, Fri Feb 16 13:41:04 PST 2024
# Use new cmake commands for pip setup.
#
# Kathleen Biagas, Tue Mar 5, 2024
# For PYTHON_ADD_PIP_SETUP change DEST_DIR from lib/site-packages to
# simply site-packages. The lib part handled in PYTHON_ADD_PIP_SETUP.
#
#****************************************************************************/

# deps for flow
Expand Down Expand Up @@ -38,7 +42,7 @@ SET(visit_flow_sources src/__init__.py


PYTHON_ADD_PIP_SETUP(NAME visit_flow_py_setup
DEST_DIR lib/site-packages
DEST_DIR site-packages
PY_MODULE_DIR visit_flow
PY_SETUP_FILE setup.py
PY_SOURCES ${visit_flow_sources})
Expand Down
6 changes: 5 additions & 1 deletion src/visitpy/visit_flow/visit_flow_vpe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
# Cyrus Harrison, Fri Feb 16 13:41:04 PST 2024
# Use new cmake commands for pip setup.
#
# Kathleen Biagas, Tue Mar 5, 2024
# For PYTHON_ADD_PIP_SETUP change DEST_DIR from lib/site-packages to
# simply site-packages. The lib part handled in PYTHON_ADD_PIP_SETUP.
#
#****************************************************************************


PYTHON_ADD_PIP_SETUP(NAME visit_flow_vpe_py_setup
DEST_DIR lib/site-packages
DEST_DIR site-packages
PY_MODULE_DIR visit_flow_vpe
PY_SETUP_FILE setup.py
PY_SOURCES src/__init__.py
Expand Down
5 changes: 4 additions & 1 deletion src/visitpy/visit_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

#****************************************************************************
# Modifications:
# Kathleen Biagas, Tue Mar 5, 2024
# For PYTHON_ADD_PIP_SETUP change DEST_DIR from lib/site-packages to
# simply site-packages. The lib part handled in PYTHON_ADD_PIP_SETUP.
#
#****************************************************************************

PYTHON_ADD_PIP_SETUP(NAME visit_utils_py_setup
DEST_DIR lib/site-packages
DEST_DIR site-packages
PY_MODULE_DIR visit_utils
PY_SETUP_FILE setup.py
PY_SOURCES src/__init__.py
Expand Down
6 changes: 5 additions & 1 deletion src/visitpy/visitmodule/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
# Kathleen Biagas, Wed Feb 28, 2024
# Changed PY_MODULE_DIR from visit_flow_vpe to visit.
#
# Kathleen Biagas, Tue Mar 5, 2024
# For PYTHON_ADD_PIP_SETUP change DEST_DIR from lib/site-packages to
# simply site-packages. The lib part handled in PYTHON_ADD_PIP_SETUP.
#
#****************************************************************************

PYTHON_ADD_PIP_SETUP(NAME visitmodule_py_setup
DEST_DIR lib/site-packages
DEST_DIR site-packages
PY_MODULE_DIR visit
PY_SETUP_FILE setup.py
PY_SOURCES py_src/__init__.py
Expand Down

0 comments on commit db21752

Please sign in to comment.