-
Notifications
You must be signed in to change notification settings - Fork 109
/
configure.bat
203 lines (162 loc) · 6.54 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
@echo OFF
@setlocal
@rem Copyright (c) nexB Inc. and others. All rights reserved.
@rem SPDX-License-Identifier: Apache-2.0
@rem See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
@rem See https://github.com/aboutcode-org/ for support or download.
@rem See https://aboutcode.org for more information about nexB OSS projects.
@rem ################################
@rem # A configuration script to set things up:
@rem # create a virtualenv and install or update thirdparty packages.
@rem # Source this script for initial configuration
@rem # Use configure --help for details
@rem # NOTE: please keep in sync with POSIX script configure
@rem # This script will search for a virtualenv.pyz app in etc\thirdparty\virtualenv.pyz
@rem # Otherwise it will download the latest from the VIRTUALENV_PYZ_URL default
@rem ################################
@rem ################################
@rem # Defaults. Change these variables to customize this script
@rem ################################
@rem # Requirement arguments passed to pip and used by default or with --dev.
set "REQUIREMENTS=--editable . "
set "DOCS_REQUIREMENTS=--editable .[docs]"
@rem # where we create a virtualenv
set "VIRTUALENV_DIR=venv"
@rem # Cleanable files and directories to delete with the --clean option
set "CLEANABLE=build dist venv .cache .eggs"
@rem # extra arguments passed to pip
set "PIP_EXTRA_ARGS= "
@rem # the URL to download virtualenv.pyz if needed
set VIRTUALENV_PYZ_URL=https://bootstrap.pypa.io/virtualenv.pyz
@rem ################################
@rem ################################
@rem # Current directory where this script lives
set CFG_ROOT_DIR=%~dp0
set "CFG_BIN_DIR=%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\Scripts"
@rem ################################
@rem # Thirdparty package locations and index handling
@rem # Find packages from the local thirdparty directory
if exist "%CFG_ROOT_DIR%\thirdparty" (
set PIP_EXTRA_ARGS=--find-links "%CFG_ROOT_DIR%\thirdparty"
)
@rem ################################
@rem # Set the quiet flag to empty if not defined
if not defined CFG_QUIET (
set "CFG_QUIET= "
)
@rem ################################
@rem # Main command line entry point
set "CFG_REQUIREMENTS=%REQUIREMENTS%"
:again
if not "%1" == "" (
if "%1" EQU "--help" (goto cli_help)
if "%1" EQU "--clean" (goto clean)
if "%1" EQU "--docs" (
set "CFG_REQUIREMENTS=%DOCS_REQUIREMENTS%"
)
shift
goto again
)
set "PIP_EXTRA_ARGS=%PIP_EXTRA_ARGS%"
@rem ################################
@rem # Find a proper Python to run
@rem # Use environment variables or a file if available.
@rem # Otherwise the latest Python by default.
if not defined PYTHON_EXECUTABLE (
@rem # check for a file named PYTHON_EXECUTABLE
if exist "%CFG_ROOT_DIR%\PYTHON_EXECUTABLE" (
set /p PYTHON_EXECUTABLE=<"%CFG_ROOT_DIR%\PYTHON_EXECUTABLE"
) else (
set "PYTHON_EXECUTABLE=py"
)
)
@rem ################################
:create_virtualenv
@rem # create a virtualenv for Python
@rem # Note: we do not use the bundled Python 3 "venv" because its behavior and
@rem # presence is not consistent across Linux distro and sometimes pip is not
@rem # included either by default. The virtualenv.pyz app cures all these issues.
if not exist "%CFG_BIN_DIR%\python.exe" (
if not exist "%CFG_BIN_DIR%" (
mkdir "%CFG_BIN_DIR%"
)
if exist "%CFG_ROOT_DIR%\etc\thirdparty\virtualenv.pyz" (
%PYTHON_EXECUTABLE% "%CFG_ROOT_DIR%\etc\thirdparty\virtualenv.pyz" ^
--wheel embed --pip embed --setuptools embed ^
--seeder pip ^
--never-download ^
--no-periodic-update ^
--no-vcs-ignore ^
%CFG_QUIET% ^
"%CFG_ROOT_DIR%\%VIRTUALENV_DIR%"
) else (
if not exist "%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\virtualenv.pyz" (
curl -o "%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\virtualenv.pyz" %VIRTUALENV_PYZ_URL%
if %ERRORLEVEL% neq 0 (
exit /b %ERRORLEVEL%
)
)
%PYTHON_EXECUTABLE% "%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\virtualenv.pyz" ^
--wheel embed --pip embed --setuptools embed ^
--seeder pip ^
--never-download ^
--no-periodic-update ^
--no-vcs-ignore ^
%CFG_QUIET% ^
"%CFG_ROOT_DIR%\%VIRTUALENV_DIR%"
)
)
if %ERRORLEVEL% neq 0 (
exit /b %ERRORLEVEL%
)
@rem ################################
:install_packages
@rem # install requirements in virtualenv
@rem # note: --no-build-isolation means that pip/wheel/setuptools will not
@rem # be reinstalled a second time and reused from the virtualenv and this
@rem # speeds up the installation.
@rem # We always have the PEP517 build dependencies installed already.
"%CFG_BIN_DIR%\pip" install ^
--upgrade ^
--no-build-isolation ^
%CFG_QUIET% ^
%PIP_EXTRA_ARGS% ^
%CFG_REQUIREMENTS%
@rem ################################
:create_bin_junction
@rem # Create junction to bin to have the same directory between linux and windows
if exist "%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\bin" (
rmdir /s /q "%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\bin"
)
mklink /J "%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\bin" "%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\Scripts"
if %ERRORLEVEL% neq 0 (
exit /b %ERRORLEVEL%
)
exit /b 0
@rem ################################
:cli_help
echo An initial configuration script
echo " usage: configure [options]"
echo " "
echo The default is to configure for regular use. Use --dev for development.
echo " "
echo The options are:
echo " --clean: clean built and installed files and exit."
echo " --dev: configure the environment for development."
echo " --help: display this help message and exit."
echo " "
echo By default, the python interpreter version found in the path is used.
echo Alternatively, the PYTHON_EXECUTABLE environment variable can be set to
echo configure another Python executable interpreter to use. If this is not
echo set, a file named PYTHON_EXECUTABLE containing a single line with the
echo path of the Python executable to use will be checked last.
exit /b 0
@rem ################################
:clean
@rem # Remove cleanable file and directories and files from the root dir.
echo "* Cleaning ..."
for %%F in (%CLEANABLE%) do (
rmdir /s /q "%CFG_ROOT_DIR%\%%F" >nul 2>&1
del /f /q "%CFG_ROOT_DIR%\%%F" >nul 2>&1
)
exit /b 0