Skip to content
Snippets Groups Projects
Commit 4db49345 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Fix access to Python binary modules from the build tree

Closes #240

See merge request !1392
parents 5de4967d 4a947089
No related branches found
No related tags found
1 merge request!1392Fix access to Python binary modules from the build tree
Pipeline #4769312 passed
......@@ -23,14 +23,14 @@ class TestCase(unittest.TestCase):
def test_000_Import(self):
try:
import PyExample
import GaudiExamples.PyExample
except ImportError:
self.fail("Cannot import PyExample from %s" % sys.path)
self.fail("Cannot import GaudiExamples.PyExample from %s" % sys.path)
def test_010_Function(self):
import PyExample
import GaudiExamples.PyExample
self.assertEqual(PyExample.greet(), "hello, world")
self.assertEqual(GaudiExamples.PyExample.greet(), "hello, world")
if __name__ == "__main__":
......
......@@ -459,9 +459,6 @@ function(gaudi_add_python_module module_name)
_resolve_local_targets(ARG_LINK)
target_link_libraries(${module_name} PRIVATE ${ARG_LINK})
endif()
# Add it to the runtime PYTHONPATH
_gaudi_runtime_prepend(pythonpath ${CMAKE_CURRENT_BINARY_DIR})
# install
if(ARG_PACKAGE)
set(package_path "${ARG_PACKAGE}")
get_filename_component(package_name "${package_path}" NAME)
......@@ -473,6 +470,14 @@ function(gaudi_add_python_module module_name)
message(FATAL_ERROR "${package_path}/__init__.py"
" must exist and the package must be installed (see gaudi_install(PYTHON)).")
endif()
# make the module accessible from the build tree
add_custom_command(TARGET ${module_name} POST_BUILD
BYPRODUCTS ${CMAKE_BINARY_DIR}/python/${package_name}/${module_name}${CMAKE_SHARED_MODULE_SUFFIX}
COMMAND ${CMAKE_COMMAND} -E create_symlink
$<TARGET_FILE:${module_name}>
${CMAKE_BINARY_DIR}/python/${package_name}/$<TARGET_FILE_NAME:${module_name}>)
install(
TARGETS ${module_name}
LIBRARY DESTINATION "${GAUDI_INSTALL_PYTHONDIR}/${package_name}"
......@@ -892,7 +897,8 @@ function(gaudi_install type)
"import os, sys
__path__ = [d for d in [os.path.join(os.path.realpath(d), '${python_package_name}') for d in sys.path if d]
if (d.startswith(os.path.realpath('${CMAKE_CURRENT_BINARY_DIR}')) or
d.startswith(os.path.realpath('${CMAKE_CURRENT_SOURCE_DIR}'))) and
d.startswith(os.path.realpath('${CMAKE_CURRENT_SOURCE_DIR}')) or
d.startswith(os.path.realpath('${CMAKE_BINARY_DIR}/python/${python_package_name}'))) and
(os.path.exists(d) or 'python.zip' in d)]
fname = '${CMAKE_CURRENT_SOURCE_DIR}/python/${python_package_name}/__init__.py'
if os.path.exists(fname):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment