Skip to content

Commit

Permalink
Simplify to process of loading the Python plugins on Linux.
Browse files Browse the repository at this point in the history
Remove any need to force some libraries to load first. Newer linkers
seem to have removed the need for this.
Refs #10271
  • Loading branch information
martyngigg committed Sep 23, 2014
1 parent 076399a commit afa941f
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 240 deletions.
21 changes: 11 additions & 10 deletions Code/Mantid/Framework/PythonInterface/mantid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
Implementing Algorithms, Virtual Instrument Geometry.
"""
from __future__ import absolute_import

###############################################################################
# Check the current Python version is correct
###############################################################################
import pyversion
from . import pyversion

###############################################################################
# Define the api version
Expand Down Expand Up @@ -61,15 +63,15 @@ def apiVersion():
###############################################################################
# Ensure the sub package C libraries are loaded
###############################################################################
import kernel
import geometry
import api
import mantid.kernel as kernel
import mantid.geometry as geometry
import mantid.api as api

###############################################################################
# Make the aliases form each module accessible in a the mantid namspace
# Make the aliases from each module accessible in a the mantid namspace
###############################################################################
from kernel._aliases import *
from api._aliases import *
from mantid.kernel._aliases import *
from mantid.api._aliases import *

###############################################################################
# Make the version string accessible in the standard way
Expand All @@ -89,9 +91,8 @@ def apiVersion():
# to the simple import mechanism then plugins that are loaded later cannot
# be seen by the earlier ones (chicken & the egg essentially).
################################################################################
import simpleapi as _simpleapi
from kernel import plugins as _plugins

from . import simpleapi as _simpleapi
from mantid.kernel import plugins as _plugins

_plugins_key = 'python.plugins.directories'
_user_key = 'user.%s' % _plugins_key
Expand Down
23 changes: 8 additions & 15 deletions Code/Mantid/Framework/PythonInterface/mantid/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@
Defines Python objects that wrap the C++ API namespace.
"""
from __future__ import absolute_import

###############################################################################
# The _api C extension depends on exports defined in the _kernel extension
###############################################################################
# The fully-qualified package path allows it to be found without path manipulation
from mantid.kernel import dlopen as _pydlopen
import os as _os
clib = _os.path.join(_os.path.dirname(__file__), '_api.so')
flags = _pydlopen.setup_dlopen(clib, ['libMantidKernel', 'libMantidGeometry', 'libMantidAPI']) # Ensure the library is open with the correct flags
from mantid.kernel import _kernel
import _api
from _api import *
_pydlopen.restore_flags(flags)
# Load the C++ library
###############################################################################
from . import _api
from ._api import *

###############################################################################
# Start the framework (if not embedded in other application)
Expand All @@ -30,17 +23,17 @@
###############################################################################
# Make aliases accessible in this namespace
###############################################################################
from _aliases import *
from ._aliases import *

###############################################################################
# Add importAll member to ADS
###############################################################################
import _adsimports
from . import _adsimports

###############################################################################
# Attach additional operators to workspaces
###############################################################################
import _workspaceops
from . import _workspaceops
_workspaceops.attach_binary_operators_to_workspace()
_workspaceops.attach_unary_operators_to_workspace()
_workspaceops.attach_tableworkspaceiterator()
_workspaceops.attach_tableworkspaceiterator()
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
Defines Python objects that wrap the C++ Geometry namespace.
"""
from __future__ import absolute_import

###############################################################################
# The _api C extension depends on exports defined in the _kernel extension
# Load the C++ library
###############################################################################
from mantid.kernel import dlopen as _pydlopen
import os as _os
clib = _os.path.join(_os.path.dirname(__file__), '_geometry.so')
flags = _pydlopen.setup_dlopen(clib, ['libMantidKernel', 'libMantidGeometry']) # Ensure the library is open with the correct flags
from _geometry import *
_pydlopen.restore_flags(flags)
from ._geometry import *
18 changes: 0 additions & 18 deletions Code/Mantid/Framework/PythonInterface/mantid/kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ set ( INC_FILES
set ( PY_FILES
__init__.py
_aliases.py
dlopen.py
environment.py
funcreturns.py
plugins.py
Expand Down Expand Up @@ -160,28 +159,11 @@ set_target_output_directory ( PythonKernelModule ${OUTPUT_DIR} .pyd )
# Add the required dependencies
target_link_libraries ( PythonKernelModule ${PYTHON_DEPS} )

if ( UNIX )
add_library ( _dlopen src/dlopen.c )
set_python_properties ( _dlopen _dlopen )
set_target_output_directory ( _dlopen ${OUTPUT_DIR} .pyd )
if ( APPLE )
# and in .so on the Mac
# Need to remove OpenMP
set ( CMAKE_C_FLAGS -m64 )
set_target_properties ( _dlopen PROPERTIES SUFFIX .so )
target_link_libraries ( _dlopen ${PYTHON_LIBRARIES} )
endif()
add_dependencies( PythonKernelModule _dlopen )
endif()

###########################################################################
# Installation settings
###########################################################################
install ( TARGETS PythonKernelModule ${SYSTEM_PACKAGE_TARGET} DESTINATION
${BIN_DIR}/mantid/kernel )
if ( UNIX )
install ( TARGETS _dlopen DESTINATION ${BIN_DIR}/mantid/kernel )
endif()

# Pure Python files
install ( FILES ${PY_FILES} DESTINATION ${BIN_DIR}/mantid/kernel )
Expand Down
19 changes: 7 additions & 12 deletions Code/Mantid/Framework/PythonInterface/mantid/kernel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@
Defines Python objects that wrap the C++ Kernel namespace.
"""
from __future__ import absolute_import

###############################################################################
# Loads the C library with the correct flags
###############################################################################
import dlopen as _pydlopen
import os as _os
clib = _os.path.join(_os.path.dirname(__file__), '_kernel.so')
flags = _pydlopen.setup_dlopen(clib, ['libMantidKernel'])
from _kernel import *
_pydlopen.restore_flags(flags)
# Load the C++ library
###############################################################################
from ._kernel import *

###############################################################################
# Do any site-specific setup for packages
###############################################################################
import packagesetup as _packagesetup
from . import packagesetup as _packagesetup

###############################################################################
# Make modules available in this namespace
###############################################################################
import environment
import funcreturns
from _aliases import *
from . import environment
from . import funcreturns
from ._aliases import *
119 changes: 0 additions & 119 deletions Code/Mantid/Framework/PythonInterface/mantid/kernel/dlopen.py

This file was deleted.

41 changes: 0 additions & 41 deletions Code/Mantid/Framework/PythonInterface/mantid/kernel/src/dlopen.c

This file was deleted.

0 comments on commit afa941f

Please sign in to comment.