forked from aboutcode-org/scancode-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.bat
156 lines (128 loc) · 4.77 KB
/
configure.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
@echo OFF
@setlocal
@rem Copyright (c) nexB Inc. http://www.nexb.com/ - All rights reserved.
@rem ################################
@rem # A configuration script for Windows
@rem #
@rem # The options and (optional) arguments are:
@rem # --clean : this is exclusive of anything else and cleans the environment
@rem # from built and installed files
@rem #
@rem # --python < path to python.exe> : this must be the first argument and set
@rem # the path to the Python executable to use. If < path to python.exe> is
@rem # set to "path", then the executable will be the python.exe available
@rem # in the PATH.
@rem #
@rem # <some conf path> : this must be the last argument and sets the path to a
@rem # configuration directory to use.
@rem ################################
@rem ################################
@rem # Defaults. Change these variables to customize this script locally
@rem ################################
@rem # you can define one or more thirdparty dirs, each where the varibale name
@rem # is prefixed with TPP_DIR
set "TPP_DIR=thirdparty"
@rem # default configurations for dev
set "CONF_DEFAULT=etc/conf/dev"
@rem # default thirdparty dist for dev
if ""%CONF_DEFAULT%""==""etc/conf/dev"" (
set "TPP_DIR_DEV=thirdparty/dev"
)
@rem # default supported version for Python 3
set SUPPORTED_PYTHON3=3.6
@rem #################################
@rem python --version
@rem python -c "import sys;print(sys.executable)"
@rem Current directory where this .bat files lives
set CFG_ROOT_DIR=%~dp0
@rem path where a configured Python should live in the current virtualenv if installed
set CONFIGURED_PYTHON=%CFG_ROOT_DIR%Scripts\python.exe
set PYTHON_EXECUTABLE=
@rem parse command line options and arguments
:collectopts
if "%1" EQU "--help" (goto cli_help)
if "%1" EQU "--clean" (set CFG_CMD_LINE_ARGS=--clean) && goto find_python
if "%1" EQU "--python" (set PROVIDED_PYTHON=%~2) && shift && shift && goto collectopts
@rem We are not cleaning: Either we have a provided configure config path or we use a default.
if ""%1""=="""" (
set CFG_CMD_LINE_ARGS=%CONF_DEFAULT%
) else (
set CFG_CMD_LINE_ARGS=%1
)
@rem If we have a pre-configured Python in our virtualenv, reuse this as-is and run
if exist ""%CONFIGURED_PYTHON%"" (
set PYTHON_EXECUTABLE=%CONFIGURED_PYTHON%
goto run
)
@rem If we have a command arg for Python use this as-is
if ""%PROVIDED_PYTHON%""==""path"" (
@rem use a bare python available in the PATH
set PYTHON_EXECUTABLE=python
goto run
)
if exist ""%PROVIDED_PYTHON%"" (
set PYTHON_EXECUTABLE=%PROVIDED_PYTHON%
goto run
)
@rem otherwise we search for a suitable Python interpreter
:find_python
@rem First check the existence of the "py" launcher (available in Python 3)
@rem if we have it, check if we have a py -3 installed with the good version or a py 2.7
@rem if not, check if we have an old py 2.7
@rem exist if all fails
where py >nul 2>nul
if %ERRORLEVEL% == 0 (
@rem we have a py launcher, check for the availability of our required Python 3 version
py -3.6 --version >nul 2>nul
if %ERRORLEVEL% == 0 (
set PYTHON_EXECUTABLE=py -3.6
) else (
@rem we have no required python 3, let's try python 2:
py -2 --version >nul 2>nul
if %ERRORLEVEL% == 0 (
set PYTHON_EXECUTABLE=py -2
) else (
@rem we have py and no python 3 and 2, exit
echo * Unable to find an installation of Python.
exit /b 1
)
)
) else (
@rem we have no py launcher, check for a default Python 2 installation
if not exist ""%DEFAULT_PYTHON2%"" (
echo * Unable to find an installation of Python.
exit /b 1
) else (
set PYTHON_EXECUTABLE=%DEFAULT_PYTHON2%
)
)
:run
@rem without this things may not always work on Windows 10, but this makes things slower
set PYTHONDONTWRITEBYTECODE=1
call %PYTHON_EXECUTABLE% "%CFG_ROOT_DIR%etc\configure.py" %CFG_CMD_LINE_ARGS%
@rem Return a proper return code on failure
if %ERRORLEVEL% neq 0 (
exit /b %ERRORLEVEL%
)
endlocal
goto activate
:cli_help
echo A configuration script for Windows
echo usage: configure [options] [path/to/config/directory]
echo.
echo The options and arguments are:
echo [path/to/config/directory] : this optionally sets the path to a
echo configuration directory to use. Defaults to etc/conf/dev if not set
echo.
echo --clean : this is exclusive of anything else and cleans the environment
echo from built and installed files
echo.
echo --python path/to/python.exe : this is set to the path of an alternative
echo Python executable to use. If path/to/python.exe is set to "path",
echo then the executable will be the python.exe available in the PATH.
echo.
:activate
@rem Activate the virtualenv
if exist "%CFG_ROOT_DIR%Scripts\activate" (
"%CFG_ROOT_DIR%Scripts\activate"
)