mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
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).
This commit is contained in:
@@ -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 ):
|
||||
|
||||
Reference in New Issue
Block a user