|
1 |
| -@echo OFF |
2 |
| -@setlocal |
3 |
| -@rem Copyright (c) nexB Inc. http://www.nexb.com/ - All rights reserved. |
4 |
| - |
5 |
| -@rem ################################ |
6 |
| -@rem # A configuration script for Windows |
7 |
| -@rem # |
8 |
| -@rem # The options and (optional) arguments are: |
9 |
| -@rem # --clean : this is exclusive of anything else and cleans the environment |
10 |
| -@rem # from built and installed files |
11 |
| -@rem # |
12 |
| -@rem # --python < path to python.exe> : this must be the first argument and set |
13 |
| -@rem # the path to the Python executable to use. If < path to python.exe> is |
14 |
| -@rem # set to "path", then the executable will be the python.exe available |
15 |
| -@rem # in the PATH. |
16 |
| -@rem ################################ |
17 |
| - |
18 |
| -@rem Current directory where this .bat files lives |
19 |
| -set CFG_ROOT_DIR=%~dp0 |
20 |
| -@rem path where a configured Python should live in the current virtualenv if installed |
21 |
| -set CONFIGURED_PYTHON=%CFG_ROOT_DIR%tmp\Scripts\python.exe |
22 |
| -set PYTHON_EXECUTABLE= |
23 |
| - |
24 |
| - |
25 |
| -@rem parse command line options and arguments |
26 |
| -:collectopts |
27 |
| -if "%1" EQU "--help" (goto cli_help) |
28 |
| -if "%1" EQU "--clean" (call rmdir /s /q "%CFG_ROOT_DIR%tmp") && call exit /b |
29 |
| -if "%1" EQU "--python" (set PROVIDED_PYTHON=%~2) && shift && shift && goto collectopts |
30 |
| - |
31 |
| -@rem If we have a pre-configured Python in our virtualenv, reuse this as-is and run |
32 |
| -if exist ""%CONFIGURED_PYTHON%"" ( |
33 |
| - set PYTHON_EXECUTABLE=%CONFIGURED_PYTHON% |
34 |
| - goto run |
35 |
| -) |
36 |
| - |
37 |
| -@rem If we have a command arg for Python use this as-is |
38 |
| -if ""%PROVIDED_PYTHON%""==""path"" ( |
39 |
| - @rem use a bare python available in the PATH |
40 |
| - set PYTHON_EXECUTABLE=python |
41 |
| - goto run |
42 |
| -) |
43 |
| -if exist ""%PROVIDED_PYTHON%"" ( |
44 |
| - set PYTHON_EXECUTABLE=%PROVIDED_PYTHON% |
45 |
| - goto run |
46 |
| -) |
47 |
| - |
48 |
| - |
49 |
| -@rem otherwise we search for a suitable Python interpreter |
50 |
| -:find_python |
51 |
| -@rem First check the existence of the "py" launcher (available in Python 3) |
52 |
| -@rem if we have it, check if we have a py -3 installed with the good version or a py 2.7 |
53 |
| -@rem if not, check if we have an old py 2.7 |
54 |
| -@rem exist if all fails |
55 |
| - |
56 |
| -where py >nul 2>nul |
57 |
| -if %ERRORLEVEL% == 0 ( |
58 |
| - @rem we have a py launcher, check for the availability of our required Python 3 version |
59 |
| - py -3.6 --version >nul 2>nul |
60 |
| - if %ERRORLEVEL% == 0 ( |
61 |
| - set PYTHON_EXECUTABLE=py -3.6 |
62 |
| - ) else ( |
63 |
| - @rem we have no required python 3, let's try python 2: |
64 |
| - py -2 --version >nul 2>nul |
65 |
| - if %ERRORLEVEL% == 0 ( |
66 |
| - set PYTHON_EXECUTABLE=py -2 |
67 |
| - ) else ( |
68 |
| - @rem we have py and no python 3 and 2, exit |
69 |
| - echo * Unable to find an installation of Python. |
70 |
| - exit /b 1 |
71 |
| - ) |
72 |
| - ) |
73 |
| -) else ( |
74 |
| - @rem we have no py launcher, check for a default Python 2 installation |
75 |
| - if not exist ""%DEFAULT_PYTHON2%"" ( |
76 |
| - echo * Unable to find an installation of Python. |
77 |
| - exit /b 1 |
78 |
| - ) else ( |
79 |
| - set PYTHON_EXECUTABLE=%DEFAULT_PYTHON2% |
80 |
| - ) |
81 |
| -) |
82 |
| - |
83 |
| - |
84 |
| -:run |
85 |
| -@rem without this things may not always work on Windows 10, but this makes things slower |
86 |
| -set PYTHONDONTWRITEBYTECODE=1 |
87 |
| - |
88 |
| -call mkdir "%CFG_ROOT_DIR%tmp" |
89 |
| -call curl -o "%CFG_ROOT_DIR%tmp\virtualenv.pyz" https://bootstrap.pypa.io/virtualenv.pyz |
90 |
| -call %PYTHON_EXECUTABLE% "%CFG_ROOT_DIR%tmp\virtualenv.pyz" "%CFG_ROOT_DIR%tmp" |
91 |
| -call "%CFG_ROOT_DIR%tmp\Scripts\activate" |
92 |
| -call "%CFG_ROOT_DIR%tmp\Scripts\pip" install --upgrade pip virtualenv setuptools wheel |
93 |
| -call "%CFG_ROOT_DIR%tmp\Scripts\pip" install -e .[testing] |
94 |
| - |
95 |
| -@rem Return a proper return code on failure |
96 |
| -if %ERRORLEVEL% neq 0 ( |
97 |
| - exit /b %ERRORLEVEL% |
98 |
| -) |
99 |
| -endlocal |
100 |
| -goto activate |
101 |
| - |
102 |
| - |
103 |
| -:cli_help |
104 |
| -echo A configuration script for Windows |
105 |
| -echo usage: configure [options] [path/to/config/directory] |
106 |
| -echo. |
107 |
| -echo The options and arguments are: |
108 |
| -echo --clean : this is exclusive of anything else and cleans the environment |
109 |
| -echo from built and installed files |
110 |
| -echo. |
111 |
| -echo --python path/to/python.exe : this is set to the path of an alternative |
112 |
| -echo Python executable to use. If path/to/python.exe is set to "path", |
113 |
| -echo then the executable will be the python.exe available in the PATH. |
114 |
| -echo. |
115 |
| - |
116 |
| - |
117 |
| -:activate |
118 |
| -@rem Activate the virtualenv |
119 |
| -if exist "%CFG_ROOT_DIR%tmp\Scripts\activate" ( |
120 |
| - "%CFG_ROOT_DIR%tmp\Scripts\activate" |
121 |
| -) |
| 1 | +@echo OFF |
| 2 | +@setlocal |
| 3 | +@rem Copyright (c) nexB Inc. http://www.nexb.com/ - All rights reserved. |
| 4 | + |
| 5 | +@rem ################################ |
| 6 | +@rem # A configuration script for Windows |
| 7 | +@rem # |
| 8 | +@rem # The options and (optional) arguments are: |
| 9 | +@rem # --clean : this is exclusive of anything else and cleans the environment |
| 10 | +@rem # from built and installed files |
| 11 | +@rem # |
| 12 | +@rem # --python < path to python.exe> : this must be the first argument and set |
| 13 | +@rem # the path to the Python executable to use. If < path to python.exe> is |
| 14 | +@rem # set to "path", then the executable will be the python.exe available |
| 15 | +@rem # in the PATH. |
| 16 | +@rem ################################ |
| 17 | + |
| 18 | +@rem Current directory where this .bat files lives |
| 19 | +set CFG_ROOT_DIR=%~dp0 |
| 20 | +@rem path where a configured Python should live in the current virtualenv if installed |
| 21 | +set CONFIGURED_PYTHON=%CFG_ROOT_DIR%tmp\Scripts\python.exe |
| 22 | +set PYTHON_EXECUTABLE= |
| 23 | + |
| 24 | + |
| 25 | +@rem parse command line options and arguments |
| 26 | +:collectopts |
| 27 | +if "%1" EQU "--help" (goto cli_help) |
| 28 | +if "%1" EQU "--clean" (call rmdir /s /q "%CFG_ROOT_DIR%tmp") && call exit /b |
| 29 | +if "%1" EQU "--python" (set PROVIDED_PYTHON=%~2) && shift && shift && goto collectopts |
| 30 | + |
| 31 | +@rem If we have a pre-configured Python in our virtualenv, reuse this as-is and run |
| 32 | +if exist ""%CONFIGURED_PYTHON%"" ( |
| 33 | + set PYTHON_EXECUTABLE=%CONFIGURED_PYTHON% |
| 34 | + goto run |
| 35 | +) |
| 36 | + |
| 37 | +@rem If we have a command arg for Python use this as-is |
| 38 | +if ""%PROVIDED_PYTHON%""==""path"" ( |
| 39 | + @rem use a bare python available in the PATH |
| 40 | + set PYTHON_EXECUTABLE=python |
| 41 | + goto run |
| 42 | +) |
| 43 | +if exist ""%PROVIDED_PYTHON%"" ( |
| 44 | + set PYTHON_EXECUTABLE=%PROVIDED_PYTHON% |
| 45 | + goto run |
| 46 | +) |
| 47 | + |
| 48 | + |
| 49 | +@rem otherwise we search for a suitable Python interpreter |
| 50 | +:find_python |
| 51 | +@rem First check the existence of the "py" launcher (available in Python 3) |
| 52 | +@rem if we have it, check if we have a py -3 installed with the good version or a py 2.7 |
| 53 | +@rem if not, check if we have an old py 2.7 |
| 54 | +@rem exist if all fails |
| 55 | + |
| 56 | +where py >nul 2>nul |
| 57 | +if %ERRORLEVEL% == 0 ( |
| 58 | + @rem we have a py launcher, check for the availability of our required Python 3 version |
| 59 | + py -3.6 --version >nul 2>nul |
| 60 | + if %ERRORLEVEL% == 0 ( |
| 61 | + set PYTHON_EXECUTABLE=py -3.6 |
| 62 | + ) else ( |
| 63 | + @rem we have no required python 3, let's try python 2: |
| 64 | + py -2 --version >nul 2>nul |
| 65 | + if %ERRORLEVEL% == 0 ( |
| 66 | + set PYTHON_EXECUTABLE=py -2 |
| 67 | + ) else ( |
| 68 | + @rem we have py and no python 3 and 2, exit |
| 69 | + echo * Unable to find an installation of Python. |
| 70 | + exit /b 1 |
| 71 | + ) |
| 72 | + ) |
| 73 | +) else ( |
| 74 | + @rem we have no py launcher, check for a default Python 2 installation |
| 75 | + if not exist ""%DEFAULT_PYTHON2%"" ( |
| 76 | + echo * Unable to find an installation of Python. |
| 77 | + exit /b 1 |
| 78 | + ) else ( |
| 79 | + set PYTHON_EXECUTABLE=%DEFAULT_PYTHON2% |
| 80 | + ) |
| 81 | +) |
| 82 | + |
| 83 | + |
| 84 | +:run |
| 85 | +@rem without this things may not always work on Windows 10, but this makes things slower |
| 86 | +set PYTHONDONTWRITEBYTECODE=1 |
| 87 | + |
| 88 | +call mkdir "%CFG_ROOT_DIR%tmp" |
| 89 | +call curl -o "%CFG_ROOT_DIR%tmp\virtualenv.pyz" https://bootstrap.pypa.io/virtualenv.pyz |
| 90 | +call %PYTHON_EXECUTABLE% "%CFG_ROOT_DIR%tmp\virtualenv.pyz" "%CFG_ROOT_DIR%tmp" |
| 91 | +call "%CFG_ROOT_DIR%tmp\Scripts\activate" |
| 92 | +call "%CFG_ROOT_DIR%tmp\Scripts\pip" install --upgrade pip virtualenv setuptools wheel |
| 93 | +call "%CFG_ROOT_DIR%tmp\Scripts\pip" install -e .[testing] |
| 94 | + |
| 95 | +@rem Return a proper return code on failure |
| 96 | +if %ERRORLEVEL% neq 0 ( |
| 97 | + exit /b %ERRORLEVEL% |
| 98 | +) |
| 99 | +endlocal |
| 100 | +goto activate |
| 101 | + |
| 102 | + |
| 103 | +:cli_help |
| 104 | +echo A configuration script for Windows |
| 105 | +echo usage: configure [options] [path/to/config/directory] |
| 106 | +echo. |
| 107 | +echo The options and arguments are: |
| 108 | +echo --clean : this is exclusive of anything else and cleans the environment |
| 109 | +echo from built and installed files |
| 110 | +echo. |
| 111 | +echo --python path/to/python.exe : this is set to the path of an alternative |
| 112 | +echo Python executable to use. If path/to/python.exe is set to "path", |
| 113 | +echo then the executable will be the python.exe available in the PATH. |
| 114 | +echo. |
| 115 | + |
| 116 | + |
| 117 | +:activate |
| 118 | +@rem Activate the virtualenv |
| 119 | +if exist "%CFG_ROOT_DIR%tmp\Scripts\activate" ( |
| 120 | + "%CFG_ROOT_DIR%tmp\Scripts\activate" |
| 121 | +) |
0 commit comments