Skip to content

Commit 6b09e72

Browse files
committed
fix: Add skill handler directory in pythonpath, for local imports
This commit adds the skill handler directory into the PYTHONPATH variable, so that while running the skill handler file, local python modules/packages imports works as expected. This is to stimulate the behavior of running the skill lambda handler as the main file from the python interpreter.
1 parent 4dc20bc commit 6b09e72

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

ask-sdk-local-debug/ask_sdk_local_debug/config/skill_invoker_config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# specific language governing permissions and limitations under the
1616
# License.
1717
#
18+
import os
19+
import sys
1820
import typing
1921
import importlib.util
2022

@@ -82,8 +84,22 @@ def __initialize_skill_invoker(self):
8284
self.skill_file_path, str(e)))
8385
return skill_invoker
8486

87+
def __load_skill_handler_dir_path(self):
88+
# type: () -> None
89+
"""Loads skill handler directory path into PYTHONPATH.
90+
91+
For local module/package resolution, this method loads the
92+
directory containing the skill handler file into the
93+
python path, so that the interpreter will be able to resolve
94+
the needed imports during runtime.
95+
"""
96+
skill_dir = os.path.dirname(self.skill_file_path)
97+
if skill_dir not in sys.path:
98+
sys.path.append(skill_dir)
99+
85100
def __get_skill_builder_func(self):
86101
try:
102+
self.__load_skill_handler_dir_path()
87103
return getattr(self.__initialize_skill_invoker(), self.skill_handler)
88104
except Exception as e:
89105
raise LocalDebugSdkException(

0 commit comments

Comments
 (0)