Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated PYTHON_INSTALL_DIR generation #636

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 14 additions & 26 deletions cmake/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,20 @@ message(STATUS "Using PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}")

set(_PYTHON_PATH_VERSION_SUFFIX "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")

set(enable_setuptools_deb_layout OFF)
if(EXISTS "/etc/debian_version")
set(enable_setuptools_deb_layout ON)
endif()
option(SETUPTOOLS_DEB_LAYOUT "Enable debian style python package layout" ${enable_setuptools_deb_layout})
# setuptools is fussy about windows paths, make sure the install prefix is in native format
file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}" SETUPTOOLS_INSTALL_PREFIX)

if(SETUPTOOLS_DEB_LAYOUT)
message(STATUS "Using Debian Python package layout")
set(PYTHON_PACKAGES_DIR dist-packages)
set(SETUPTOOLS_ARG_EXTRA "--install-layout=deb")
# use major version only when installing 3.x with debian layout
if("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
set(_PYTHON_PATH_VERSION_SUFFIX "${PYTHON_VERSION_MAJOR}")
endif()
else()
message(STATUS "Using default Python package layout")
set(PYTHON_PACKAGES_DIR site-packages)
# setuptools is fussy about windows paths, make sure the install prefix is in native format
file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}" SETUPTOOLS_INSTALL_PREFIX)
# PYTHON_INSTALL_DIR needs to be in PYTHONPATH when 'setup.py install'
# is called, and it needs to match. setuptools won't tell us where it will
# install things, so we'll ask Python. Becuase this has to match
# python/catkin/builder.py exactly, we let Python handle the work.
execute_process(COMMAND "${PYTHON_EXECUTABLE}"
"-c" "from distutils.sysconfig import get_python_lib; import os; python_install_dir = os.sep.join(get_python_lib().split(os.sep)[-2 if os.name == 'nt' else -3:]); print(python_install_dir)"
RESULT_VARIABLE _res
OUTPUT_VARIABLE PYTHON_INSTALL_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _res EQUAL 0)
message(FATAL_ERROR "Determine PYTHON_INSTALL_DIR failed")
endif()
message(STATUS "Using PYTHON_INSTALL_DIR: " ${PYTHON_INSTALL_DIR})

if(NOT WIN32)
set(PYTHON_INSTALL_DIR lib/python${_PYTHON_PATH_VERSION_SUFFIX}/${PYTHON_PACKAGES_DIR}
CACHE INTERNAL "This needs to be in PYTHONPATH when 'setup.py install' is called. And it needs to match. But setuptools won't tell us where it will install things.")
else()
# Windows setuptools installs to lib/site-packages not lib/python2.7/site-packages
set(PYTHON_INSTALL_DIR lib/${PYTHON_PACKAGES_DIR}
CACHE INTERNAL "This needs to be in PYTHONPATH when 'setup.py install' is called. And it needs to match. But setuptools won't tell us where it will install things.")
endif()
13 changes: 3 additions & 10 deletions python/catkin/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from io import StringIO
import subprocess
import sys
from distutils.sysconfig import get_python_lib

try:
from catkin_pkg.cmake import configure_file, get_metapackage_cmake_template_path
Expand Down Expand Up @@ -270,16 +271,8 @@ def get_multiarch():

def get_python_install_dir():
# this function returns the same value as the CMake variable PYTHON_INSTALL_DIR from catkin/cmake/python.cmake
python_install_dir = 'lib'
python_use_debian_layout = os.path.exists('/etc/debian_version')
if os.name != 'nt':
python_version_xdoty = str(sys.version_info[0]) + '.' + str(sys.version_info[1])
if python_use_debian_layout and sys.version_info[0] == 3:
python_version_xdoty = str(sys.version_info[0])
python_install_dir = os.path.join(python_install_dir, 'python' + python_version_xdoty)

python_packages_dir = 'dist-packages' if python_use_debian_layout else 'site-packages'
python_install_dir = os.path.join(python_install_dir, python_packages_dir)
# one-liner so cmake can use the same code
python_install_dir = os.sep.join(get_python_lib().split(os.sep)[-2 if os.name == 'nt' else -3:])
return python_install_dir


Expand Down