Skip to content

Commit a30c7bb

Browse files
authored
Merge pull request #156 from azatoth/py3venv
Use python specified as runtime in the virtualenv
2 parents 9d5de3c + 46c06c0 commit a30c7bb

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

lambda_uploader/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def validate_kinesis():
160160
ts = ksub.get('starting_position_timestamp')
161161
try:
162162
datetime.strptime(ts, '%Y-%m-%dT%H:%M:%SZ')
163-
except:
163+
except: # noqa: E722
164164
raise TypeError("Starting position timestamp"
165165
" must have format "
166166
" YYYY-mm-ddTHH:MM:SSZ")

lambda_uploader/package.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737

3838

3939
def build_package(path, requires, virtualenv=None, ignore=None,
40-
extra_files=None, zipfile_name=ZIPFILE_NAME):
40+
extra_files=None, zipfile_name=ZIPFILE_NAME,
41+
pyexec=None):
4142
'''Builds the zip file and creates the package with it'''
42-
pkg = Package(path, zipfile_name)
43+
pkg = Package(path, zipfile_name, pyexec)
4344

4445
if extra_files:
4546
for fil in extra_files:
@@ -59,7 +60,7 @@ def create_package(path, zipfile_name=ZIPFILE_NAME):
5960

6061

6162
class Package(object):
62-
def __init__(self, path, zipfile_name=ZIPFILE_NAME):
63+
def __init__(self, path, zipfile_name=ZIPFILE_NAME, pyexec=None):
6364
self._path = path
6465
self._temp_workspace = os.path.join(path,
6566
TEMP_WORKSPACE_NAME)
@@ -68,6 +69,7 @@ def __init__(self, path, zipfile_name=ZIPFILE_NAME):
6869
self._virtualenv = None
6970
self._skip_virtualenv = False
7071
self._requirements = None
72+
self._pyexec = pyexec
7173
self._requirements_file = os.path.join(self._path, "requirements.txt")
7274
self._extra_files = []
7375

@@ -172,7 +174,9 @@ def _build_new_virtualenv(self):
172174
if sys.platform == 'win32' or sys.platform == 'cygwin':
173175
self._venv_pip = 'Scripts\pip.exe'
174176

175-
proc = Popen(["virtualenv", "-p", _python_executable(),
177+
python_exe = self._python_executable()
178+
179+
proc = Popen(["virtualenv", "-p", python_exe,
176180
self._pkg_venv], stdout=PIPE, stderr=PIPE)
177181
stdout, stderr = proc.communicate()
178182
LOG.debug("Virtualenv stdout: %s" % stdout)
@@ -184,6 +188,22 @@ def _build_new_virtualenv(self):
184188
else:
185189
raise Exception('cannot build a new virtualenv when asked to omit')
186190

191+
def _python_executable(self):
192+
if self._pyexec is not None:
193+
python_exe = find_executable(self._pyexec)
194+
if not python_exe:
195+
raise Exception('Unable to locate {} executable'
196+
.format(self._pyexec))
197+
else:
198+
python_exe = find_executable('python2')
199+
if not python_exe:
200+
python_exe = find_executable('python')
201+
202+
if not python_exe:
203+
raise Exception('Unable to locate python executable')
204+
205+
return python_exe
206+
187207
def _install_requirements(self):
188208
'''
189209
Create a new virtualenvironment and install requirements
@@ -293,14 +313,3 @@ def _isfile(path):
293313
if not path:
294314
return False
295315
return os.path.isfile(path)
296-
297-
298-
def _python_executable():
299-
python_exe = find_executable('python2')
300-
if not python_exe:
301-
python_exe = find_executable('python')
302-
303-
if not python_exe:
304-
raise Exception('Unable to locate python executable')
305-
306-
return python_exe

lambda_uploader/shell.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def _execute(args):
8181
if args.extra_files:
8282
extra_files = args.extra_files
8383
pkg = package.build_package(pth, requirements,
84-
venv, cfg.ignore, extra_files)
84+
venv, cfg.ignore, extra_files,
85+
pyexec=cfg.runtime)
8586

8687
if not args.no_clean:
8788
pkg.clean_workspace()

lambda_uploader/uploader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def upload(self, pkg):
135135
get_resp = self._lambda_client.get_function_configuration(
136136
FunctionName=self._config.name)
137137
LOG.debug("AWS get_function_configuration response: %s" % get_resp)
138-
except:
138+
except: # noqa: E722
139139
existing_function = False
140140
LOG.debug("function not found creating new function")
141141

0 commit comments

Comments
 (0)