Skip to content

Commit

Permalink
cmake: Update Python install path documentation
Browse files Browse the repository at this point in the history
Python install paths are notoriusly difficult to determine.
This commit is an effort to provide more info on the subject.

Signed-off-by: Johannes Demel <[email protected]>
  • Loading branch information
jdemel committed Jul 5, 2022
1 parent 32709a6 commit 75a98d5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cmake/Modules/VolkPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,23 @@ import sysconfig
import site
install_dir = None
# The next line passes a CMake variable into our script.
prefix = '${CMAKE_INSTALL_PREFIX}'
#use `site` when the prefix is already recognized
# We use `site` to identify if our chosen prefix is a default one.
# https://docs.python.org/3/library/site.html
try:
paths = [p for p in site.getsitepackages() if p.startswith(prefix)]
if len(paths) == 1: install_dir = paths[0]
# https://docs.python.org/3/library/site.html#site.getsitepackages
paths = [p for p in site.getsitepackages() if p.startswith(prefix)]
if len(paths) == 1: install_dir = paths[0]
except AttributeError: pass
# If we found a default install path, `install_dir` is set.
if not install_dir:
# find where to install the python module
# for Python 3.11+, we could use the 'venv' scheme for all platforms
# We use a custom install prefix!
# Determine the correct install path in that prefix on the current platform.
# For Python 3.11+, we could use the 'venv' scheme for all platforms
# https://docs.python.org/3.11/library/sysconfig.html#installation-paths
if os.name == 'nt':
scheme = 'nt'
else:
Expand Down

0 comments on commit 75a98d5

Please sign in to comment.