3737
3838
3939def 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
6162class 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
0 commit comments