Skip to content
This repository was archived by the owner on Mar 15, 2026. It is now read-only.

Commit c20ec3e

Browse files
committed
ability to pass in path of requirements file
1 parent 0897619 commit c20ec3e

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

aws_lambda/aws_lambda.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import json
44
import logging
55
import os
6-
import sys
76
import time
87
from imp import load_source
98
from shutil import copy, copyfile
@@ -111,12 +110,6 @@ def invoke(src, alt_event=None, verbose=False):
111110
path_to_event_file = os.path.join(src, 'event.json')
112111
event = read(path_to_event_file, loader=json.loads)
113112

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

157148

158149
def build(src, requirements=False, local_package=None):
@@ -185,13 +176,6 @@ def build(src, requirements=False, local_package=None):
185176
requirements=requirements,
186177
local_package=local_package)
187178

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-
195179
# Gracefully handle whether ".zip" was included in the filename or not.
196180
output_filename = ('{0}.zip'.format(output_filename)
197181
if not output_filename.endswith('.zip')
@@ -204,7 +188,6 @@ def build(src, requirements=False, local_package=None):
204188
continue
205189
if filename == 'config.yaml':
206190
continue
207-
print("Bundling: %r" % filename)
208191
files.append(os.path.join(src, filename))
209192

210193
# "cd" into `temp_path` directory.
@@ -272,7 +255,7 @@ def _filter_blacklist(package):
272255
package = package.replace('-e ', '')
273256

274257
print('Installing {package}'.format(package=package))
275-
pip.main(['install', package, '-t', path, '--ignore-installed'])
258+
pip.main(['install', package, '-t', path])
276259

277260

278261
def pip_install_to_target(path, requirements=False, local_package=None):
@@ -300,15 +283,17 @@ def pip_install_to_target(path, requirements=False, local_package=None):
300283
print('Gathering requirement packages')
301284
data = read("requirements.txt")
302285
packages.extend(data.splitlines())
286+
elif os.path.exists(requirements):
287+
print('Gathering requirement from %s' % requirements)
288+
data = read(requirements)
289+
packages.extend(data.splitlines())
303290

304291
if not packages:
305292
print('No dependency packages installed!')
306293

307294
if local_package is not None:
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)
295+
# TODO: actually sdist is probably bettter here...
296+
packages.append(local_package)
312297
_install_packages(path, packages)
313298

314299

scripts/lambda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def invoke(event_file, verbose):
4141

4242

4343
@click.command(help="Register and deploy your code to lambda.")
44-
@click.option('--use-requirements', default=False, is_flag=True, help='Install all packages defined in requirements.txt')
44+
@click.option('--use-requirements', default=None, help='Install all packages defined in requirements.txt', type=click.Path())
4545
@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)

0 commit comments

Comments
 (0)