From 2d589bd3765cc3fa2a7aedd89a189174b3ca342e Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Thu, 30 Aug 2012 14:40:28 -0400 Subject: [PATCH] Change the implementation for importing proprietary datatype class modules that are included in installed tool shed repositories. This approach will correctly import proprietary datatype classes whose file names conflict with a Python standard library module name (e.g., if a proprietary datatype class file is named xml.py, it will conflict with the Python standard library's xml module when attempting to import it). --- lib/galaxy/datatypes/registry.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/galaxy/datatypes/registry.py b/lib/galaxy/datatypes/registry.py index b054b423d11..0a4ad3c17d5 100644 --- a/lib/galaxy/datatypes/registry.py +++ b/lib/galaxy/datatypes/registry.py @@ -1,7 +1,7 @@ """ Provides mapping between extensions and datatypes, mime-types, etc. """ -import os, sys, tempfile, threading, logging +import os, sys, tempfile, threading, logging, imp import data, tabular, interval, images, sequence, qualityscore, genetics, xml, coverage, tracks, chrominfo, binary, assembly, ngsindex import galaxy.util from galaxy.util.odict import odict @@ -55,10 +55,9 @@ class Registry( object ): being installed. Since installation is occurring after the datatypes registry has been initialized, its contents cannot be overridden by new introduced conflicting data types. """ - def __import_module( full_path, datatype_module ): - sys.path.insert( 0, full_path ) - imported_module = __import__( datatype_module ) - sys.path.pop( 0 ) + def __import_module( full_path, datatype_module, datatype_class_name ): + open_file_obj, file_name, description = imp.find_module( datatype_module, [ full_path ] ) + imported_module = imp.load_module( datatype_class_name, open_file_obj, file_name, description ) return imported_module if root_dir and config: handling_proprietary_datatypes = False @@ -130,12 +129,12 @@ class Registry( object ): datatype_module = fields[0] datatype_class_name = fields[1] datatype_class = None - if proprietary_path and proprietary_datatype_module: + if proprietary_path and proprietary_datatype_module and datatype_class_name: # We need to change the value of sys.path, so do it in a way that is thread-safe. lock = threading.Lock() lock.acquire( True ) try: - imported_module = __import_module( proprietary_path, proprietary_datatype_module ) + imported_module = __import_module( proprietary_path, proprietary_datatype_module, datatype_class_name ) if imported_module not in self.imported_modules: self.imported_modules.append( imported_module ) if hasattr( imported_module, datatype_class_name ):