Skip to content

Commit 5d30d5b

Browse files
author
David Erb
committed
things tries to import from module as well as file
1 parent 4565365 commit 5d30d5b

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/dls_utilpack/things.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
from 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

1014
logger = 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))

0 commit comments

Comments
 (0)