diff --git a/package_python_function/nested_zip_loader.py b/package_python_function/nested_zip_loader.py index 2fc2b0d..e5c9f7a 100644 --- a/package_python_function/nested_zip_loader.py +++ b/package_python_function/nested_zip_loader.py @@ -40,8 +40,8 @@ def load_nested_zip() -> None: # [No longer applicable] We want our path to look like [working_dir, /tmp/package-python-function, ...] # Refer to https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-searchpath # We need to replace the original path that AWS Lambda setup for us. - # sys.path.insert(1, target_package_path) - sys.path[0] = target_package_path + # sys.path.insert(1, str(target_package_path)) + sys.path[0] = str(target_package_path) importlib.reload(sys.modules[__name__]) load_nested_zip() \ No newline at end of file diff --git a/tests/test_local.py b/tests/test_local.py new file mode 100644 index 0000000..8c2db9d --- /dev/null +++ b/tests/test_local.py @@ -0,0 +1,24 @@ +import importlib +from pathlib import Path +import sys +import zipfile + + +def xtest_local(package_path: str, entrypoint: str) -> None: + output_path = Path(package_path).parent / 'lambda' + output_path.mkdir(parents=True, exist_ok=True) + with zipfile.ZipFile(package_path, 'r') as zip: + zip.extractall(str(output_path)) + + sys.path.insert(0, str(output_path)) + + entrypoint_parts = entrypoint.split('.') + module_name = '.'.join(entrypoint_parts[0:1]) + entry_function = entrypoint_parts[2] + module = importlib.import_module(module_name) + print(sys.path) + module.__dict__[entry_function]() + + +if __name__ == '__main__': + xtest_local(sys.argv[1], sys.argv[2]) \ No newline at end of file