Skip to content

Commit 9a530b8

Browse files
Convert Path to string (#5)
1 parent 1442cd5 commit 9a530b8

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

package_python_function/nested_zip_loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def load_nested_zip() -> None:
4040
# [No longer applicable] We want our path to look like [working_dir, /tmp/package-python-function, ...]
4141
# Refer to https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-searchpath
4242
# We need to replace the original path that AWS Lambda setup for us.
43-
# sys.path.insert(1, target_package_path)
44-
sys.path[0] = target_package_path
43+
# sys.path.insert(1, str(target_package_path))
44+
sys.path[0] = str(target_package_path)
4545
importlib.reload(sys.modules[__name__])
4646

4747
load_nested_zip()

tests/test_local.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import importlib
2+
from pathlib import Path
3+
import sys
4+
import zipfile
5+
6+
7+
def xtest_local(package_path: str, entrypoint: str) -> None:
8+
output_path = Path(package_path).parent / 'lambda'
9+
output_path.mkdir(parents=True, exist_ok=True)
10+
with zipfile.ZipFile(package_path, 'r') as zip:
11+
zip.extractall(str(output_path))
12+
13+
sys.path.insert(0, str(output_path))
14+
15+
entrypoint_parts = entrypoint.split('.')
16+
module_name = '.'.join(entrypoint_parts[0:1])
17+
entry_function = entrypoint_parts[2]
18+
module = importlib.import_module(module_name)
19+
print(sys.path)
20+
module.__dict__[entry_function]()
21+
22+
23+
if __name__ == '__main__':
24+
xtest_local(sys.argv[1], sys.argv[2])

0 commit comments

Comments
 (0)