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 5
5
from dls_utilpack .exceptions import DuplicateUuidException , NotFound
6
6
7
7
# 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
+ )
9
13
10
14
logger = logging .getLogger (__name__ )
11
15
@@ -111,11 +115,21 @@ def lookup_class(self, class_type):
111
115
""""""
112
116
113
117
# 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 )} " )
120
134
121
135
raise NotFound ("unable to get class for %s thing" % (class_type ))
You can’t perform that action at this time.
0 commit comments