Skip to content

Commit

Permalink
tentative at improving system python rejection (avoid caching, still …
Browse files Browse the repository at this point in the history
…some issues with a base conda environment
  • Loading branch information
SamFlt committed Jan 26, 2024
1 parent 420d0bd commit 75deb42
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
37 changes: 36 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,27 @@ endif()

# --- Python Support ---
if(NOT IOS)
# Make sure to refresh the python interpreter every time we rerun cmake
# If we don't do this, we may use an old or invalid python when installing the bindings
# that was cached by a previous attempt at building


# # this avoids non-active conda from getting picked anyway on Windows
# set(Python_FIND_REGISTRY LAST)
# set(Python_FIND_VIRTUALENV FIRST)
# set(Python_FIND_STRATEGY LOCATION)
unset(PYTHON3INTERP_FOUND CACHE)
unset(PYTHONINTERP_FOUND CACHE)
unset(PYTHON3INTERP_FOUND)
unset(PYTHONLIBS_FOUND CACHE)
unset(PYTHONINTERP_FOUND)
unset(PYTHON_FOUND CACHE)
unset(PYTHON3_EXECUTABLE CACHE)
unset(PYTHON_EXECUTABLE CACHE)
unset(PYTHON3_EXECUTABLE)
unset(PYTHON_EXECUTABLE)
unset(VISP_PYTHON_IS_SYSTEM_WIDE CACHE)
unset(VISP_PYTHON3_VERSION CACHE)
include(cmake/VISPDetectPython.cmake)
endif()

Expand All @@ -279,10 +300,24 @@ else()
endif()

if(CMAKE_NOT_OK_FOR_BINDINGS)
status("${CMAKE_NOT_OK_FOR_BINDINGS}")
status("CMake version required for Python bindings is 3.19.0, but you have ${CMAKE_VERSION}. Python bindings generation will be deactivated")
endif()

if(DEFINED ENV{VIRTUAL_ENV} OR DEFINED ENV{CONDA_PREFIX})
set(_pip_args)
set(VISP_PYTHON_IS_SYSTEM_WIDE FALSE)
else()
# First solution: raise an error when cmake will call pip install
# set(_pip_args "--require-virtualenv") # If this is a system python, throw an error
message(WARNING "\
The python version that you are using (${PYTHON3_EXECUTABLE}) is the system interpreter.
pip packages should not be installed system-wide!
Python bindings targets will be deactivated!
To reenable them, install conda or virtualenv, delete the CMakeCache file then rerun cmake when inside the virtual environment.
")
set(VISP_PYTHON_IS_SYSTEM_WIDE TRUE)
endif()

# --- Python Bindings requirements ---

# this avoids non-active conda from getting picked anyway on Windows
Expand Down
17 changes: 0 additions & 17 deletions modules/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@ find_package(VISP REQUIRED)

# TODO: check for pip

# Set pip args
if(DEFINED ENV{VIRTUAL_ENV} OR DEFINED ENV{CONDA_PREFIX})
set(_pip_args)
set(VISP_PYTHON_IS_SYSTEM_WIDE FALSE PARENT_SCOPE)
else()
# First solution: raise an error when cmake will call pip install
# set(_pip_args "--require-virtualenv") # If this is a system python, throw an error
message(WARNING "\
The python version that you are using (${PYTHON3_EXECUTABLE}) is the system interpreter.
pip packages should not be installed system-wide!
Python bindings targets will be deactivated!
To reenable them, install conda or virtualenv, delete the CMakeCache file then rerun cmake when inside the virtual environment.
")
set(VISP_PYTHON_IS_SYSTEM_WIDE TRUE PARENT_SCOPE)
return()
endif()

# Step 1: Generate configuration file
# Define modules for which to generate python bindings
set(python_ignored_modules "visp_python" "visp_java_bindings_generator" "visp_java" )
Expand Down

0 comments on commit 75deb42

Please sign in to comment.