Skip to content

Commit e7b9f95

Browse files
committed
bugfix for importing nested handlers
1 parent 8299469 commit e7b9f95

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Diff for: Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ SDIST := dist/$(shell python setup.py --fullname).tar.gz
22
SLEEP := 0
33
TIMEOUT := 3
44

5-
.PHONY: default clean test up upload
5+
.PHONY: all clean test up upload
66

7-
default: $(SDIST)
7+
all: $(SDIST)
88

99
clean:
1010
rm -rf dist
@@ -17,7 +17,7 @@ upload: $(SDIST)
1717
up:
1818
SLEEP=$(SLEEP) python -m lambda_gateway -t $(TIMEOUT) lambda_function.lambda_handler
1919

20-
coverage.xml: $(shell find . -name '*.py' -not -path './.*')
20+
coverage.xml: $(shell find lambda_gateway tests -name '*.py')
2121
flake8 $^
2222
pytest
2323

Diff for: lambda_gateway/event_proxy.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import asyncio
2+
import importlib
23
import json
34
import os
4-
from importlib.util import (spec_from_file_location, module_from_spec)
5+
import sys
56

67
from lambda_gateway import (lambda_context, logger)
78

@@ -23,12 +24,11 @@ def get_handler(self):
2324
if not name:
2425
raise ValueError(f"Bad handler signature '{self.handler}'")
2526
try:
26-
pypath = os.path.join(os.path.curdir, f'{name}.py')
27-
spec = spec_from_file_location(name, pypath)
28-
module = module_from_spec(spec)
29-
spec.loader.exec_module(module)
30-
return getattr(module, func)
31-
except FileNotFoundError:
27+
sys.path.append(os.path.curdir)
28+
module = importlib.import_module(name)
29+
handler = getattr(module, func)
30+
return handler
31+
except ModuleNotFoundError:
3232
raise ValueError(f"Unable to import module '{name}'")
3333
except AttributeError:
3434
raise ValueError(f"Handler '{func}' missing on module '{name}'")

0 commit comments

Comments
 (0)