File tree Expand file tree Collapse file tree 1 file changed +21
-7
lines changed
Expand file tree Collapse file tree 1 file changed +21
-7
lines changed Original file line number Diff line number Diff line change 55from dls_utilpack .exceptions import DuplicateUuidException , NotFound
66
77# Method to import a class from a file.
8- from dls_utilpack .import_class import import_class
8+ from dls_utilpack .import_class import (
9+ ImportClassFailed ,
10+ import_classname_from_filename ,
11+ import_classname_from_modulename ,
12+ )
913
1014logger = logging .getLogger (__name__ )
1115
@@ -111,11 +115,21 @@ def lookup_class(self, class_type):
111115 """"""
112116
113117 # This looks like a request to load a class at runtime?
114- # The class type should be filename::classname.
115- if "::" in class_type :
116-
117- RuntimeClass = import_class (class_type )
118-
119- return RuntimeClass
118+ # The class type should be filename::classname or modulename::classname.
119+
120+ if class_type is not None :
121+ parts = class_type .split ("::" )
122+ if len (parts ) == 2 :
123+ try :
124+ class_object = import_classname_from_filename (parts [1 ], parts [0 ])
125+ return class_object
126+ except ImportClassFailed as exception :
127+ logger .debug (f"tried but { str (exception )} " )
128+
129+ try :
130+ class_object = import_classname_from_modulename (parts [1 ], parts [0 ])
131+ return class_object
132+ except ImportClassFailed as exception :
133+ logger .debug (f"tried but { str (exception )} " )
120134
121135 raise NotFound ("unable to get class for %s thing" % (class_type ))
You can’t perform that action at this time.
0 commit comments