Skip to content

Commit fb71c25

Browse files
authored
Merge pull request #184 from nikhilym/master
fix: Add skill handler directory in pythonpath, for local imports. Fixes #183
2 parents 4dc20bc + 3972b9b commit fb71c25

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
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(

scripts/ci/sdk_install

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ sdk_packages = [
2222
if sys.version_info.major == 3:
2323
sdk_packages.extend(["django-ask-sdk", "ask-sdk-local-debug"])
2424

25-
run("pip install coverage")
25+
run("python -m pip install coverage")
2626

2727
for pkg in sdk_packages:
2828
os.chdir(os.path.join(REPO_ROOT, pkg))
29-
run("pip install -r requirements.txt")
29+
run("python -m pip install -r requirements.txt")
3030
if os.path.isdir('dist') and os.listdir('dist'):
3131
shutil.rmtree('dist')
3232
run('python setup.py bdist_wheel')
3333
wheel_dist = os.listdir('dist')[0]
34-
run('pip install %s' % (os.path.join('dist', wheel_dist)))
34+
run('python -m pip install %s' % (os.path.join('dist', wheel_dist)))

tox.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ setenv =
2626
AWS_DEFAULT_REGION = us-west-2
2727
commands =
2828
flake8 .
29-
pip install --upgrade pip
30-
pip install --upgrade wheel
29+
python -m pip install --upgrade pip
30+
python -m pip install --upgrade wheel
3131
{toxinidir}/scripts/ci/sdk_install
3232
{toxinidir}/scripts/ci/run_tests
3333
py{36,37,38}: mypy ask-sdk/ask_sdk
@@ -53,8 +53,8 @@ setenv =
5353
AWS_DEFAULT_REGION = us-west-2
5454
commands =
5555
flake8 .
56-
pip install --upgrade pip
57-
pip install --upgrade wheel
56+
python -m pip install --upgrade pip
57+
python -m pip install --upgrade wheel
5858
python {toxinidir}\scripts\ci\sdk_install
5959
python {toxinidir}\scripts\ci\run_tests
6060
mypy ask-sdk\ask_sdk

0 commit comments

Comments
 (0)