55from __future__ import unicode_literals
66
77import os
8- import pathlib
98import subprocess
109import sys
10+ from os .path import abspath
11+ from os .path import dirname
12+ from os .path import exists
13+ from os .path import join
14+ from os .path import relpath
1115
12- self_path = pathlib .Path (__file__ ).resolve ()
13- base_path = self_path .parent .parent
14- template_path = base_path .joinpath ('ci' , 'templates' )
16+ base_path = dirname (dirname (abspath (__file__ )))
17+ templates_path = join (base_path , 'ci' , 'templates' )
1518
1619
1720def check_call (args ):
@@ -20,12 +23,14 @@ def check_call(args):
2023
2124
2225def exec_in_env ():
23- env_path = base_path . joinpath ( '.tox' , 'bootstrap' )
26+ env_path = join ( base_path , '.tox' , 'bootstrap' )
2427 if sys .platform == 'win32' :
25- bin_path = env_path . joinpath ( 'Scripts' )
28+ bin_path = join ( env_path , 'Scripts' )
2629 else :
27- bin_path = env_path .joinpath ('bin' )
28- if not env_path .exists ():
30+ bin_path = join (env_path , 'bin' )
31+ if not exists (env_path ):
32+ import subprocess
33+
2934 print ('Making bootstrap env in: {0} ...' .format (env_path ))
3035 try :
3136 check_call ([sys .executable , '-m' , 'venv' , env_path ])
@@ -35,29 +40,26 @@ def exec_in_env():
3540 except subprocess .CalledProcessError :
3641 check_call (['virtualenv' , env_path ])
3742 print ('Installing `jinja2` into bootstrap environment...' )
38- check_call ([bin_path .joinpath ('pip' ), 'install' , 'jinja2' , 'tox' ])
39- python_executable = bin_path .joinpath ('python' )
40- if not python_executable .exists ():
41- python_executable = '{}.exe' .format (python_executable )
42- else :
43- python_executable = str (python_executable )
43+ check_call ([join (bin_path , 'pip' ), 'install' , 'jinja2' , 'tox' ])
44+ python_executable = join (bin_path , 'python' )
45+ if not os .path .exists (python_executable ):
46+ python_executable += '.exe'
4447
4548 print ('Re-executing with: {0}' .format (python_executable ))
46- print ('+ exec' , python_executable , self_path , '--no-env' )
47- os .execv (python_executable , [python_executable , self_path , '--no-env' ])
49+ print ('+ exec' , python_executable , __file__ , '--no-env' )
50+ os .execv (python_executable , [python_executable , __file__ , '--no-env' ])
4851
4952
5053def main ():
5154 import jinja2
5255
5356 print ('Project path: {0}' .format (base_path ))
5457
55- # noinspection JinjaAutoinspect
5658 jinja = jinja2 .Environment (
57- loader = jinja2 .FileSystemLoader (str ( template_path ) ),
59+ loader = jinja2 .FileSystemLoader (templates_path ),
5860 trim_blocks = True ,
5961 lstrip_blocks = True ,
60- keep_trailing_newline = True ,
62+ keep_trailing_newline = True
6163 )
6264
6365 tox_environments = [
@@ -71,13 +73,12 @@ def main():
7173 ]
7274 tox_environments = [line for line in tox_environments if line .startswith ('py' )]
7375
74- for path in template_path .rglob ('*' ):
75- if path .is_dir ():
76- continue
77- name = path .relative_to (template_path )
78- with base_path .joinpath (name ).open ('w' ) as fh :
79- fh .write (jinja .get_template (str (name )).render (tox_environments = tox_environments ))
80- print ('Wrote {}' .format (name ))
76+ for root , _ , files in os .walk (templates_path ):
77+ for name in files :
78+ relative = relpath (root , templates_path )
79+ with open (join (base_path , relative , name ), 'w' ) as fh :
80+ fh .write (jinja .get_template (join (relative , name )).render (tox_environments = tox_environments ))
81+ print ('Wrote {}' .format (name ))
8182 print ('DONE.' )
8283
8384
0 commit comments