Skip to content

Commit dc14146

Browse files
committed
Merge branch 'master' of github.com:nficano/python-lambda
* 'master' of github.com:nficano/python-lambda: Bumped version Issue nficano#31 Issue nficano#44: Support multiple local_packages Issue: nficano#44 Turn on support for multiple options Fix init trying to copy a __pycache__ directory Added missing instruction to README.md Update README.rst Say which local files are being bundled. The Zope hack.
2 parents c2ee29e + 0897619 commit dc14146

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

README.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ python-λ
1212

1313
Python-lambda is a toolset for developing and deploying *serverless* Python code in AWS Lambda.
1414

15+
A call for contributors
16+
=======================
17+
With python-lambda and `pytube <https://github.com/nficano/pytube/>`_ both continuing to gain momentum, I'm calling for contributors to help build out new features, review pull requests, fix bugs, and maintain overall code quality. If you're interested, please email me at nficano[at]gmail.com.
18+
1519
Description
1620
===========
1721

@@ -32,7 +36,9 @@ Requirements
3236
Getting Started
3337
===============
3438

35-
Begin by creating a new virtualenv and project folder.
39+
First, you must create an IAM Role on your AWS account called `lambda_basic_execution` with the `LambdaBasicExecution` policy attached.
40+
41+
On your computer, create a new virtualenv and project folder.
3642

3743
.. code:: bash
3844

aws_lambda/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# flake8: noqa
33
__author__ = 'Nick Ficano'
44
__email__ = 'nficano@gmail.com'
5-
__version__ = '0.7.0'
5+
__version__ = '0.7.1'
66

77
from .aws_lambda import deploy, invoke, init, build, cleanup_old_versions
88

aws_lambda/aws_lambda.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import logging
55
import os
6+
import sys
67
import time
78
from imp import load_source
89
from shutil import copy, copyfile
@@ -110,6 +111,12 @@ def invoke(src, alt_event=None, verbose=False):
110111
path_to_event_file = os.path.join(src, 'event.json')
111112
event = read(path_to_event_file, loader=json.loads)
112113

114+
#Tweak to allow module to import local modules
115+
try:
116+
sys.path.index(src)
117+
except:
118+
sys.path.append(src)
119+
113120
handler = cfg.get('handler')
114121
# Inspect the handler string (<module>.<function name>) and translate it
115122
# into a function we can execute.
@@ -142,8 +149,10 @@ def init(src, minimal=False):
142149
for filename in os.listdir(templates_path):
143150
if (minimal and filename == 'event.json') or filename.endswith('.pyc'):
144151
continue
145-
destination = os.path.join(templates_path, filename)
146-
copy(destination, src)
152+
dest_path = os.path.join(templates_path, filename)
153+
154+
if not os.path.isdir(dest_path):
155+
copy(dest_path, src)
147156

148157

149158
def build(src, requirements=False, local_package=None):
@@ -176,6 +185,13 @@ def build(src, requirements=False, local_package=None):
176185
requirements=requirements,
177186
local_package=local_package)
178187

188+
# Hack for Zope.
189+
if "zope" in os.listdir(path_to_temp):
190+
print("Zope packages detected; fixing Zope package paths to make them importable.")
191+
# Touch.
192+
with open(os.path.join(path_to_temp, "zope/__init__.py"), "wb"):
193+
pass
194+
179195
# Gracefully handle whether ".zip" was included in the filename or not.
180196
output_filename = ('{0}.zip'.format(output_filename)
181197
if not output_filename.endswith('.zip')
@@ -188,6 +204,7 @@ def build(src, requirements=False, local_package=None):
188204
continue
189205
if filename == 'config.yaml':
190206
continue
207+
print("Bundling: %r" % filename)
191208
files.append(os.path.join(src, filename))
192209

193210
# "cd" into `temp_path` directory.
@@ -288,7 +305,10 @@ def pip_install_to_target(path, requirements=False, local_package=None):
288305
print('No dependency packages installed!')
289306

290307
if local_package is not None:
291-
packages.append(local_package)
308+
if not isinstance(local_package, (list, tuple) ):
309+
local_package = [local_package]
310+
for l_package in local_package:
311+
packages.append(l_package)
292312
_install_packages(path, packages)
293313

294314

scripts/lambda

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def init(folder):
2828

2929
@click.command(help="Bundles package for deployment.")
3030
@click.option('--use-requirements', default=False, is_flag=True, help='Install all packages defined in requirements.txt')
31-
@click.option('--local-package', default=None, help='Install local package as well.', type=click.Path())
31+
@click.option('--local-package', default=None, help='Install local package as well.', type=click.Path(), multiple=True)
3232
def build(use_requirements, local_package):
3333
aws_lambda.build(CURRENT_DIR, use_requirements, local_package)
3434

@@ -42,7 +42,7 @@ def invoke(event_file, verbose):
4242

4343
@click.command(help="Register and deploy your code to lambda.")
4444
@click.option('--use-requirements', default=False, is_flag=True, help='Install all packages defined in requirements.txt')
45-
@click.option('--local-package', default=None, help='Install local package as well.', type=click.Path())
45+
@click.option('--local-package', default=None, help='Install local package as well.', type=click.Path(), multiple=True)
4646
def deploy(use_requirements, local_package):
4747
aws_lambda.deploy(CURRENT_DIR, use_requirements, local_package)
4848

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.7.0
2+
current_version = 0.7.1
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
setup(
2323
name='python-lambda',
24-
version='0.7.0',
24+
version='0.7.1',
2525
description="The bare minimum for a Python app running on Amazon Lambda.",
2626
long_description=readme + '\n\n' + history,
2727
author="Nick Ficano",

0 commit comments

Comments
 (0)