Coverage for python/lsstimport.py : 54%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#! env python
# # LSST Data Management System # Copyright 2008, 2009, 2010 LSST Corporation. # Copyright 2015 AURA/LSST. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
# List of extensions to set global flags. May need to be extended # for systems other than *nix and OSX.
# Ensure that duplicate allocations--particularly those related to RTTI--are # resolved by setting dynamical library loading flags.
# For portability we try a number of different options for determining RTLD constants except ImportError: pass
# Failing to find RTLD_GLOBAL is definitely unexpected and needs investigation. raise NameError("RTLD_GLOBAL constant can not be determined")
# RTLD_NOW will be missing on Python 2 with OS X. # The value is defined in dlfcn.h and on Mac and Linux has the same value: # #define RTLD_NOW 0x2 # Do not issue a warning message as this will happen on every single import. RTLD_NOW = 2
# Note: Unsure if the following is still needed with pybind11
# Swigged python libraries that import other swigged python libraries # need to import with RTLD_GLOBAL and RTLD_NOW set. This causes # problems with symbol collisions in third party packages (notably # scipy). This cannot be fixed by using import hooks because python # code generated by swig uses imp.load_module rather than import. # This makes it necessary to over ride imp.load_module. This was # handled in ticket #3055: https://dev.lsstcorp.org/trac/ticket/3055
# Don't redefine if it's already been defined.
def imp_load_module(name, *args): pathParts = args[1].split(os.path.sep) extension = os.path.splitext(pathParts[-1])[-1] # Find all swigged LSST libs. Load _lsstcppimport.so by # adding it to the EXCEPTIONLIST since it may not have lsst in # the path (it's in $BASE_DIR/python, not # $BASE_DIR/python/lsst). Also, look for paths that look like # python/lsst as that is how to know if you are in an LSST # package. lsstIdx = [i for i, el in enumerate(pathParts) if el == 'python'] if pathParts[-1] in LIB_EXCEPTION_LIST or (extension in SHARED_LIB_EXTENSION_LIST and pathParts[-1].startswith('_') and 'lsst' in [pathParts[i + 1] for i in lsstIdx]): # Get currently set flags originalDLFlags = sys.getdlopenflags() # Set flags sys.setdlopenflags(DLFLAGS) try: module = orig_imp_load_module(name, *args) finally: # Set original flags sys.setdlopenflags(originalDLFlags) else: module = orig_imp_load_module(name, *args) return module
except ImportError: # The lsstcppimport may have failed because we're inside Scons. # If we are, then don't worry about it try: import SCons.Script # noqa F401 # If we're not, then # a) we will get an ImportError trying to import SCons.Script # b) and will know that the first ImportError really is a problem # and we should let the user know. except ImportError: print( "Could not import lsstcppimport;" " please ensure the base package has been built (not just setup).\n", file=sys.stderr) |