Skip to content

Commit 4bd9927

Browse files
authored
Merge pull request #39 from HDE/master
Release v0.1.7
2 parents 0a8e44d + 2de2a72 commit 4bd9927

File tree

13 files changed

+105
-18
lines changed

13 files changed

+105
-18
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ target/
5858

5959
# Python environment
6060
.python-version
61+
62+
# Vitual Environments
63+
venv/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2017 HDE, Inc.
3+
Copyright (c) 2015-2018 HDE, Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Run lambda function on local machine
88

99
## Prepare development environment
1010

11-
Please use a newly created virtualenv of Python 2.7 or Python 3.6 .
11+
Please use a newly created virtualenv of Python 2.7 or Python 3.6.
1212

1313
## Installation
1414

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Run lambda function on local machine
99
Prepare development environment
1010
-------------------------------
1111

12-
Please use a newly created virtualenv of Python 2.7 or Python 3.6 .
12+
Please use a newly created virtualenv of Python 2.7 or Python 3.6.
1313

1414
Installation
1515
------------

lambda_local/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'''
22
python-lambda-local: Main module
33
4-
Copyright 2015-2017 HDE, Inc.
4+
Copyright 2015-2018 HDE, Inc.
55
Licensed under MIT.
66
'''
77

lambda_local/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
Copyright 2015-2017 HDE, Inc.
2+
Copyright 2015-2018 HDE, Inc.
33
Licensed under MIT.
44
'''
55

lambda_local/environment_variables.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import os
33

44

5+
def export_variables(environment_variables):
6+
for env_name, env_value in environment_variables.items():
7+
os.environ[str(env_name)] = str(env_value)
8+
9+
510
def set_environment_variables(json_file_path):
611
"""
712
Read and set environment variables from a flat json file.
@@ -25,5 +30,4 @@ def set_environment_variables(json_file_path):
2530
with open(json_file_path) as json_file:
2631
env_vars = json.loads(json_file.read())
2732

28-
for env_name, env_value in env_vars.items():
29-
os.environ[str(env_name)] = str(env_value)
33+
export_variables(env_vars)

lambda_local/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
Copyright 2015-2017 HDE, Inc.
2+
Copyright 2015-2018 HDE, Inc.
33
Licensed under MIT.
44
'''
55

lambda_local/main.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
Copyright 2015-2017 HDE, Inc.
2+
Copyright 2015-2018 HDE, Inc.
33
Licensed under MIT.
44
'''
55

@@ -15,7 +15,7 @@
1515

1616
from . import event
1717
from . import context
18-
from .environment_variables import set_environment_variables
18+
from .environment_variables import set_environment_variables, export_variables
1919
from .timeout import time_limit
2020
from .timeout import TimeoutException
2121

@@ -31,6 +31,17 @@
3131
EXITCODE_ERR = 1
3232

3333

34+
def call(func, event, timeout, environment_variables={}, arn_string="", version_name="", library=None):
35+
export_variables(environment_variables)
36+
e = json.loads(event)
37+
c = context.Context(timeout, arn_string, version_name)
38+
if library is not None:
39+
load_lib(library)
40+
request_id = uuid.uuid4()
41+
42+
return _runner(request_id, e, c, func)
43+
44+
3445
def run(args):
3546
# set env vars if path to json file was given
3647
set_environment_variables(args.environment_variables)
@@ -41,16 +52,23 @@ def run(args):
4152
load_lib(args.library)
4253
request_id = uuid.uuid4()
4354
func = load(request_id, args.file, args.function)
55+
56+
(result, err_type) = _runner(request_id, e, c, func)
57+
58+
if err_type is not None:
59+
sys.exit(EXITCODE_ERR)
60+
4461

62+
def _runner(request_id, event, context, func):
4563
logger = logging.getLogger()
4664
result = None
4765

48-
logger.info("Event: {}".format(e))
66+
logger.info("Event: {}".format(event))
4967

5068
logger.info("START RequestId: {}".format(request_id))
5169

5270
start_time = timeit.default_timer()
53-
result, err_type = execute(func, e, c)
71+
result, err_type = execute(func, event, context)
5472
end_time = timeit.default_timer()
5573

5674
logger.info("END RequestId: {}".format(request_id))
@@ -64,8 +82,7 @@ def run(args):
6482
logger.info("REPORT RequestId: {}\tDuration: {}".format(
6583
request_id, duration))
6684

67-
if err_type is not None:
68-
sys.exit(EXITCODE_ERR)
85+
return (result, err_type)
6986

7087

7188
def load_lib(path):

lambda_local/timeout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
Copyright 2015-2017 HDE, Inc.
2+
Copyright 2015-2018 HDE, Inc.
33
Licensed under MIT.
44
'''
55

0 commit comments

Comments
 (0)