Skip to content

Commit

Permalink
PROTON-2526/PROTON-2527: [Python,ruby] Don't install without SYSINSTA…
Browse files Browse the repository at this point in the history
…LL_BINDINGS

As we now make both the python package and the ruby gem as part of the
build we don't need to install anything in the install area by default.

- Also remove a long deprecated use of Python distutils
  • Loading branch information
astitcher committed Apr 1, 2022
1 parent 40cb24b commit a920192
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pn_relative_install_dir (LIBDIR "${CMAKE_INSTALL_PREFIX}" "${LIB_INSTALL_DIR}")
# system specified locations.
set (BINDINGS_DIR ${LIB_INSTALL_DIR}/proton/bindings)

set (SYSINSTALL_BINDINGS OFF CACHE BOOL "If SYSINSTALL_BINDINGS is OFF then proton bindings will be installed underneath ${BINDINGS_DIR} and each user will need to modify their interpreter configuration to load the appropriate binding. If SYSINSTALL_BINDINGS is ON, then each language interpreter will be queried for the appropriate directory and proton bindings will be installed and available system wide with no additional per user configuration.")
set (SYSINSTALL_BINDINGS OFF CACHE BOOL "If SYSINSTALL_BINDINGS is ON, then each language interpreter will be queried for the appropriate directory and proton bindings will be installed in that location.")

set (BINDING_LANGS PYTHON RUBY)

Expand Down
77 changes: 38 additions & 39 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,6 @@ set_target_properties(${SWIG_MODULE_cproton_REAL_NAME}
PROPERTIES
LINK_FLAGS "${CATCH_UNDEFINED}")

if (CHECK_SYSINSTALL_PYTHON)
execute_process(COMMAND ${Python_EXECUTABLE}
-c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True))"
OUTPUT_VARIABLE PYTHON_SITEARCH_PACKAGES_DEFAULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
else ()
set (PYTHON_SITEARCH_PACKAGES_DEFAULT ${BINDINGS_DIR}/python)
endif ()

if (NOT PYTHON_SITEARCH_PACKAGES)
set (PYTHON_SITEARCH_PACKAGES ${PYTHON_SITEARCH_PACKAGES_DEFAULT})
endif()

set (pysrc-generated cproton.py)
set (pysrc
proton/__init__.py
Expand Down Expand Up @@ -100,21 +87,6 @@ set(py_dist_files
docs/tutorial.rst
)

macro (py_compile directory files artifacts)
foreach (src_file ${files})
install(CODE "execute_process(COMMAND \"${Python_EXECUTABLE}\" -c \"import py_compile; py_compile.compile('${src_file}', cfile='${src_file}c')\"
WORKING_DIRECTORY ${directory})")
install(CODE "execute_process(COMMAND \"${Python_EXECUTABLE}\" -O -c \"import py_compile; py_compile.compile('${src_file}', cfile='${src_file}o')\"
WORKING_DIRECTORY ${directory})")
list(APPEND ${artifacts} ${directory}/${src_file}
${directory}/${src_file}c
${directory}/${src_file}o)
endforeach (src_file)
endmacro(py_compile)

py_compile(${CMAKE_CURRENT_BINARY_DIR} ${pysrc-generated} CPROTON_ARTIFACTS)
py_compile(${CMAKE_CURRENT_SOURCE_DIR} "${pysrc}" PROTON_ARTIFACTS)

# Sphinx documentation
check_python_module("sphinx" SPHINX_MODULE_FOUND)
if (NOT SPHINX_MODULE_FOUND)
Expand All @@ -130,24 +102,51 @@ else ()
DESTINATION "${PROTON_SHARE}/docs/api-py"
COMPONENT documentation
OPTIONAL)
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES docs)
endif ()

install(FILES ${CPROTON_ARTIFACTS}
DESTINATION ${PYTHON_SITEARCH_PACKAGES}
COMPONENT Python)
install(FILES ${PROTON_ARTIFACTS}
DESTINATION "${PYTHON_SITEARCH_PACKAGES}/proton/"
COMPONENT Python)
install(TARGETS ${SWIG_MODULE_cproton_REAL_NAME}
DESTINATION ${PYTHON_SITEARCH_PACKAGES}
COMPONENT Python)
if (CHECK_SYSINSTALL_PYTHON)
execute_process(COMMAND ${Python_EXECUTABLE}
-c "from sysconfig import get_path; print(get_path('platlib'))"
OUTPUT_VARIABLE PYTHON_SITEARCH_PACKAGES_DEFAULT
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (NOT PYTHON_SITEARCH_PACKAGES)
set (PYTHON_SITEARCH_PACKAGES ${PYTHON_SITEARCH_PACKAGES_DEFAULT})
endif()

macro (py_compile directory files artifacts)
foreach (src_file ${files})
install(CODE "execute_process(COMMAND \"${Python_EXECUTABLE}\" -c \"import py_compile; py_compile.compile('${src_file}', cfile='${src_file}c')\"
WORKING_DIRECTORY ${directory})")
install(CODE "execute_process(COMMAND \"${Python_EXECUTABLE}\" -O -c \"import py_compile; py_compile.compile('${src_file}', cfile='${src_file}o')\"
WORKING_DIRECTORY ${directory})")
list(APPEND ${artifacts} ${directory}/${src_file}
${directory}/${src_file}c
${directory}/${src_file}o)
endforeach (src_file)
endmacro(py_compile)

py_compile(${CMAKE_CURRENT_BINARY_DIR} ${pysrc-generated} CPROTON_ARTIFACTS)
py_compile(${CMAKE_CURRENT_SOURCE_DIR} "${pysrc}" PROTON_ARTIFACTS)

install(FILES ${CPROTON_ARTIFACTS}
DESTINATION ${PYTHON_SITEARCH_PACKAGES}
COMPONENT Python)
install(FILES ${PROTON_ARTIFACTS}
DESTINATION "${PYTHON_SITEARCH_PACKAGES}/proton/"
COMPONENT Python)
install(TARGETS ${SWIG_MODULE_cproton_REAL_NAME}
DESTINATION ${PYTHON_SITEARCH_PACKAGES}
COMPONENT Python)
endif ()

# Install python examples even without a 'sysinstall' python
install(DIRECTORY examples/
DESTINATION "${PROTON_SHARE}/examples/python"
COMPONENT Python
USE_SOURCE_PERMISSIONS)

set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES docs)

#
# Set up the directory 'dist' for building the python native package
# source distribution for Pypi/pip
Expand Down
15 changes: 7 additions & 8 deletions ruby/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,15 @@ if (CHECK_SYSINSTALL_RUBY)
endif()

set(RUBY_ARCHLIB_DIR_DEFAULT "${OUTPUT_RUBY_ARCHLIB_DIR}")
else (CHECK_SYSINSTALL_RUBY)
set (RUBY_ARCHLIB_DIR_DEFAULT ${BINDINGS_DIR}/ruby)
endif (CHECK_SYSINSTALL_RUBY)

if (NOT RUBY_ARCHLIB_DIR)
set (RUBY_ARCHLIB_DIR ${RUBY_ARCHLIB_DIR_DEFAULT})
endif()
if (NOT RUBY_ARCHLIB_DIR)
set (RUBY_ARCHLIB_DIR ${RUBY_ARCHLIB_DIR_DEFAULT})
endif()

install(TARGETS cproton-ruby DESTINATION ${RUBY_ARCHLIB_DIR} COMPONENT Ruby)
install(DIRECTORY lib/ DESTINATION ${RUBY_ARCHLIB_DIR} COMPONENT Ruby)
endif (CHECK_SYSINSTALL_RUBY)

install(TARGETS cproton-ruby DESTINATION ${RUBY_ARCHLIB_DIR} COMPONENT Ruby)
install(DIRECTORY lib/ DESTINATION ${RUBY_ARCHLIB_DIR} COMPONENT Ruby)
install(DIRECTORY examples/
DESTINATION "${PROTON_SHARE}/examples/ruby"
COMPONENT Ruby
Expand Down

0 comments on commit a920192

Please sign in to comment.