Fix custom import issues when using shell environments
Translator is enabled to exectue within other shell environments by installing as a library (in addition to command line). As such, a separate package "translator" is installed, and pulls in everything under the translator/ directory. Originally the design for custom classes was to allow users to specify their own locations for custom classes that they define outside of the translator code. In order for this to work in the shell environments, the user would need to install these classes via a setup.py script. For now this is too heavy of a requirement to place on the user, so the design for this fix is that the user will need to manually copy over their custom classes to the translator/custom directory. We will revist the option to install custom classes via a user defined setup.py at a later date. Change-Id: Ib132d9fe768a954a226724929c074034cf898da3
This commit is contained in:
parent
28382b87fd
commit
302e083de6
|
@ -1,4 +1,4 @@
|
|||
[DEFAULT]
|
||||
|
||||
# Relative path location for custom types
|
||||
custom_types_location=contrib/hot
|
||||
custom_types_location=translator/custom/hot
|
|
@ -66,6 +66,7 @@ def _generate_type_map():
|
|||
def _load_custom_mod(custom_path):
|
||||
'''Dynamically load the parent module for all the custom types.'''
|
||||
|
||||
fp = None
|
||||
try:
|
||||
fp, filename, desc = imp.find_module(custom_path)
|
||||
imp.load_module(custom_path.replace('/', '.'),
|
||||
|
@ -81,8 +82,12 @@ def _load_classes(locations, classes):
|
|||
'''Dynamically load all the classes from the given locations.'''
|
||||
|
||||
for cls_path in locations:
|
||||
# Use the absolute path of the class path
|
||||
abs_path = os.path.dirname(os.path.abspath(__file__))
|
||||
abs_path = abs_path.replace('translator/hot', cls_path)
|
||||
|
||||
# Grab all the tosca type module files in the given path
|
||||
mod_files = [f for f in os.listdir(cls_path) if f.endswith('.py')
|
||||
mod_files = [f for f in os.listdir(abs_path) if f.endswith('.py')
|
||||
and not f.startswith('__init__')
|
||||
and f.startswith('tosca_')]
|
||||
|
||||
|
|
Loading…
Reference in New Issue