_site_packages_dirs = list(set(_site_packages_dirs)) # Find the location of this exact file. _current_file_location = _inspect.getfile(_inspect.currentframe()) def _running_from_pip_package(): return any( _current_file_location.startswith(dir_) for dir_ in _site_packages_dirs) if _running_from_pip_package(): for s in _site_packages_dirs: # TODO(gunan): Add sanity checks to loaded modules here. plugin_dir = _os.path.join(s, 'tensorflow-plugins') if _fi.file_exists(plugin_dir): _ll.load_library(plugin_dir) # These symbols appear because we import the python package which # in turn imports from tensorflow.core and tensorflow.python. They # must come from this module. So python adds these symbols for the # resolution to succeed. # pylint: disable=undefined-variable try: del python del core except NameError: # Don't fail if these modules are not available. # For e.g. this file will be originally placed under tensorflow/_api/v1 which # does not have 'python', 'core' directories. Then, it will be copied # to tensorflow/ which does have these two directories. pass
# Find the location of this exact file. _current_file_location = _inspect.getfile(_inspect.currentframe()) def _running_from_pip_package(): return any( _current_file_location.startswith(dir_) for dir_ in _site_packages_dirs) if _running_from_pip_package(): for s in _site_packages_dirs: # TODO(gunan): Add sanity checks to loaded modules here. plugin_dir = _os.path.join(s, 'tensorflow-plugins') if _fi.file_exists(plugin_dir): _ll.load_library(plugin_dir) # These symbols appear because we import the python package which # in turn imports from tensorflow.core and tensorflow.python. They # must come from this module. So python adds these symbols for the # resolution to succeed. # pylint: disable=undefined-variable try: del python except NameError: pass try: del core except NameError: pass try:
if 'sysconfig' in dir(_distutils): _site_packages_dirs += [_distutils.sysconfig.get_python_lib()] _site_packages_dirs = list(set(_site_packages_dirs)) # Find the location of this exact file. _current_file_location = _inspect.getfile(_inspect.currentframe()) def _running_from_pip_package(): return any( _current_file_location.startswith(dir_) for dir_ in _site_packages_dirs) if _running_from_pip_package(): # TODO(gunan): Add sanity checks to loaded modules here. for _s in _site_packages_dirs: # Load first party dynamic kernels. _main_dir = _os.path.join(_s, 'tensorflow_core/core/kernels') if _fi.file_exists(_main_dir): _ll.load_library(_main_dir) # Load third party dynamic kernels. _plugin_dir = _os.path.join(_s, 'tensorflow-plugins') if _fi.file_exists(_plugin_dir): _ll.load_library(_plugin_dir) # __all__ PLACEHOLDER
# Find the location of this exact file. _current_file_location = _inspect.getfile(_inspect.currentframe()) def _running_from_pip_package(): return any( _current_file_location.startswith(dir_) for dir_ in _site_packages_dirs) if _running_from_pip_package(): # TODO(gunan): Add sanity checks to loaded modules here. # Load first party dynamic kernels. _tf_dir = _os.path.dirname(_current_file_location) _kernel_dir = _os.path.join(_tf_dir, 'core', 'kernels') if _os.path.exists(_kernel_dir): _ll.load_library(_kernel_dir) # Load third party dynamic kernels. for _s in _site_packages_dirs: _plugin_dir = _os.path.join(_s, 'tensorflow-plugins') if _os.path.exists(_plugin_dir): _ll.load_library(_plugin_dir) # Load Pluggable Device Library _ll.load_pluggable_device_library(_plugin_dir) # Add module aliases if hasattr(_current_module, 'keras'): # It is possible that keras is a lazily loaded module, which might break when # actually trying to import it. Have a Try-Catch to make sure it doesn't break # when it doing some very initial loading, like tf.compat.v2, etc. try: