55from __future__ import unicode_literals
66
77import os
8+ import subprocess
89import sys
910from os .path import abspath
1011from os .path import dirname
1112from os .path import exists
1213from os .path import join
13- from os .path import normpath
1414
15- try :
16- from os .path import samefile
17- except ImportError :
18- def samefile (a , b ):
19- return normpath (abspath (a )) == normpath (abspath (b ))
15+ base_path = dirname (dirname (abspath (__file__ )))
2016
2117
22- if __name__ == "__main__" :
23- base_path = dirname (dirname (abspath (__file__ )))
24- print ("Project path: {0}" .format (base_path ))
18+ def check_call (args ):
19+ print ("+" , * args )
20+ subprocess .check_call (args )
21+
22+
23+ def exec_in_env ():
2524 env_path = join (base_path , ".tox" , "bootstrap" )
2625 if sys .platform == "win32" :
2726 bin_path = join (env_path , "Scripts" )
@@ -32,21 +31,26 @@ def samefile(a, b):
3231
3332 print ("Making bootstrap env in: {0} ..." .format (env_path ))
3433 try :
35- subprocess . check_call (["virtualenv " , env_path ])
34+ check_call ([sys . executable , "-m" , "venv " , env_path ])
3635 except subprocess .CalledProcessError :
37- subprocess .check_call ([sys .executable , "-m" , "virtualenv" , env_path ])
36+ try :
37+ check_call ([sys .executable , "-m" , "virtualenv" , env_path ])
38+ except subprocess .CalledProcessError :
39+ check_call (["virtualenv" , env_path ])
3840 print ("Installing `jinja2` into bootstrap environment..." )
39- subprocess . check_call ([join (bin_path , "pip" ), "install" , "jinja2" ])
41+ check_call ([join (bin_path , "pip" ), "install" , "jinja2" , "tox " ])
4042 python_executable = join (bin_path , "python" )
4143 if not os .path .exists (python_executable ):
4244 python_executable += '.exe'
43- if not samefile (python_executable , sys .executable ):
44- print ("Re-executing with: {0}" .format (python_executable ))
45- os .execv (python_executable , [python_executable , __file__ ])
4645
46+ print ("Re-executing with: {0}" .format (python_executable ))
47+ print ("+ exec" , python_executable , __file__ , "--no-env" )
48+ os .execv (python_executable , [python_executable , __file__ , "--no-env" ])
49+
50+ def main ():
4751 import jinja2
4852
49- import subprocess
53+ print ( "Project path: {0}" . format ( base_path ))
5054
5155 jinja = jinja2 .Environment (
5256 loader = jinja2 .FileSystemLoader (join (base_path , "ci" , "templates" )),
@@ -71,3 +75,15 @@ def samefile(a, b):
7175 fh .write (jinja .get_template (name ).render (tox_environments = tox_environments ))
7276 print ("Wrote {}" .format (name ))
7377 print ("DONE." )
78+
79+
80+ if __name__ == "__main__" :
81+ args = sys .argv [1 :]
82+ if args == ["--no-env" ]:
83+ main ()
84+ elif not args :
85+ exec_in_env ()
86+ else :
87+ print ("Unexpected arguments {0}" .format (args ), file = sys .stderr )
88+ sys .exit (1 )
89+
0 commit comments