Skip to content

Commit 089cb43

Browse files
author
Jeff Parker
committed
better handling of pip using subprocess
1 parent 7e9a0d3 commit 089cb43

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

aws_lambda/aws_lambda.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import json
66
import logging
77
import os
8+
import re
9+
import subprocess
810
import sys
911
import time
1012
from collections import defaultdict
@@ -25,7 +27,6 @@
2527
from .helpers import read
2628
from .helpers import timestamp
2729

28-
2930
ARN_PREFIXES = {
3031
'us-gov-west-1': 'aws-us-gov',
3132
}
@@ -83,9 +84,9 @@ def cleanup_old_versions(
8384

8485

8586
def deploy(
86-
src, requirements=None, local_package=None,
87-
config_file='config.yaml', profile_name=None,
88-
preserve_vpc=False
87+
src, requirements=None, local_package=None,
88+
config_file='config.yaml', profile_name=None,
89+
preserve_vpc=False
8990
):
9091
"""Deploys a new function to AWS Lambda.
9192
@@ -155,8 +156,8 @@ def deploy_s3(
155156

156157

157158
def upload(
158-
src, requirements=None, local_package=None,
159-
config_file='config.yaml', profile_name=None,
159+
src, requirements=None, local_package=None,
160+
config_file='config.yaml', profile_name=None,
160161
):
161162
"""Uploads a new function to AWS S3.
162163
@@ -400,21 +401,16 @@ def _install_packages(path, packages):
400401
:param list packages:
401402
A list of packages to be installed via pip.
402403
"""
403-
def _filter_blacklist(package):
404-
blacklist = ['-i', '#', 'Python==', 'python-lambda==']
405-
return all(package.startswith(entry) is False for entry in blacklist)
406-
filtered_packages = filter(_filter_blacklist, packages)
404+
bad_packages = ['-i', '#', 'Python==', 'python-lambda']
405+
blacklist = re.compile('|'.join([re.escape(pack) for pack in bad_packages]))
406+
filtered_packages = [pack for pack in packages if not blacklist.search(pack)]
407+
407408
for package in filtered_packages:
408409
if package.startswith('-e '):
409410
package = package.replace('-e ', '')
410411

411412
print('Installing {package}'.format(package=package))
412-
pip_major_version = [int(v) for v in pip.__version__.split('.')][0]
413-
if pip_major_version >= 10:
414-
from pip._internal import main
415-
main(['install', package, '-t', path, '--ignore-installed'])
416-
else:
417-
pip.main(['install', package, '-t', path, '--ignore-installed'])
413+
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package, '-t', path, '--ignore-installed'])
418414

419415

420416
def pip_install_to_target(path, requirements=None, local_package=None):
@@ -587,7 +583,7 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
587583

588584

589585
def update_function(
590-
cfg, path_to_zip_file, existing_cfg, use_s3=False, s3_file=None, preserve_vpc=False
586+
cfg, path_to_zip_file, existing_cfg, use_s3=False, s3_file=None, preserve_vpc=False
591587
):
592588
"""Updates the code of an existing Lambda function"""
593589

0 commit comments

Comments
 (0)