Skip to content

Commit 348b073

Browse files
committed
Fixed lambda-uploader to work with Python 3, using tox for testing
This change adds the ability to run lambda-uploader in a local Python 3 environment. The lambda-uploader will explicitly look for a python2 executable instead of just using python.
1 parent cdeed07 commit 348b073

15 files changed

+106
-404
lines changed

Diff for: circle.yml

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
dependencies:
2-
pre:
3-
- rm -r ~/virtualenvs
4-
51
machine:
62
python:
7-
version: 2.7
3+
version: '2.7.10'
4+
5+
dependencies:
6+
override:
7+
- pip install -U pip
8+
- pip install -U tox tox-pyenv
9+
- pyenv local 2.7.9 3.4.3 3.5.0
810

911
test:
10-
pre:
11-
- pip install -r test-requirements.txt
12-
- python setup.py develop
1312
override:
14-
- flake8 .
15-
- py.test
13+
- tox

Diff for: lambda_uploader/config.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
import json
1616
from os import path
1717

18+
# Python 2/3 compatability
19+
try:
20+
basestring
21+
except NameError:
22+
basestring = str
23+
1824
REQUIRED_PARAMS = {u'name': basestring, u'description': basestring,
1925
u'region': basestring, u'handler': basestring,
2026
u'role': basestring, u'timeout': int, u'memory': int}
@@ -37,7 +43,7 @@ def __init__(self, pth, config_file=None, role=None):
3743
if self._config['vpc']:
3844
self._validate_vpc()
3945

40-
for param, clss in REQUIRED_PARAMS.iteritems():
46+
for param, clss in REQUIRED_PARAMS.items():
4147
self._validate(param, cls=clss)
4248

4349
'''
@@ -81,7 +87,7 @@ def set_alias(self, alias, description=None):
8187

8288
'''Set all defaults after loading the config'''
8389
def _set_defaults(self):
84-
for param, val in DEFAULT_PARAMS.iteritems():
90+
for param, val in DEFAULT_PARAMS.items():
8591
if self._config.get(param) is None:
8692
self._config[param] = val
8793

@@ -95,7 +101,7 @@ def _validate(self, key, cls=None):
95101

96102
'''Validate the VPC configuration'''
97103
def _validate_vpc(self):
98-
for param, clss in REQUIRED_VPC_PARAMS.iteritems():
104+
for param, clss in REQUIRED_VPC_PARAMS.items():
99105
self._compare(param, clss, self._config['vpc'].get(param))
100106

101107
if len(self._config['vpc'].get(param)) == 0:

Diff for: lambda_uploader/package.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from subprocess import Popen, PIPE
2222
from lambda_uploader import utils
23+
from distutils.spawn import find_executable
2324

2425
# Python 2/3 compatability
2526
try:
@@ -160,8 +161,8 @@ def _build_new_virtualenv(self):
160161
if sys.platform == 'win32' or sys.platform == 'cygwin':
161162
self._venv_pip = 'Scripts\pip.exe'
162163

163-
proc = Popen(["virtualenv", self._pkg_venv],
164-
stdout=PIPE, stderr=PIPE)
164+
proc = Popen(["virtualenv", "-p", _python_executable(),
165+
self._pkg_venv], stdout=PIPE, stderr=PIPE)
165166
stdout, stderr = proc.communicate()
166167
LOG.debug("Virtualenv stdout: %s" % stdout)
167168
LOG.debug("Virtualenv stderr: %s" % stderr)
@@ -265,3 +266,14 @@ def _isfile(path):
265266
if not path:
266267
return False
267268
return os.path.isfile(path)
269+
270+
271+
def _python_executable():
272+
python_exe = find_executable('python2')
273+
if python_exe is '':
274+
python_exe = find_executable('python')
275+
276+
if python_exe is '':
277+
raise Exception('Unable to locate python executable')
278+
279+
return python_exe

0 commit comments

Comments
 (0)