16
16
# Source this script for initial configuration
17
17
# Use configure --help for details
18
18
#
19
+ # NOTE: please keep in sync with Windows script configure.bat
20
+ #
19
21
# This script will search for a virtualenv.pyz app in etc/thirdparty/virtualenv.pyz
20
22
# Otherwise it will download the latest from the VIRTUALENV_PYZ_URL default
21
23
# ###############################
@@ -32,10 +34,8 @@ DEV_REQUIREMENTS="--editable .[testing] --constraint requirements.txt --constrai
32
34
# where we create a virtualenv
33
35
VIRTUALENV_DIR=venv
34
36
35
- # Cleanable files and directories with the --clean option
36
- CLEANABLE="
37
- build
38
- venv"
37
+ # Cleanable files and directories to delete with the --clean option
38
+ CLEANABLE=" build venv"
39
39
40
40
# extra arguments passed to pip
41
41
PIP_EXTRA_ARGS=" "
@@ -50,11 +50,14 @@ VIRTUALENV_PYZ_URL=https://bootstrap.pypa.io/virtualenv.pyz
50
50
CFG_ROOT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
51
51
CFG_BIN_DIR=$CFG_ROOT_DIR /$VIRTUALENV_DIR /bin
52
52
53
+
54
+ # ###############################
55
+ # Thirdparty package locations and index handling
53
56
# Find packages from the local thirdparty directory or from thirdparty.aboutcode.org
54
57
if [ -f " $CFG_ROOT_DIR /thirdparty" ]; then
55
- PIP_EXTRA_ARGS=" --find-links $CFG_ROOT_DIR /thirdparty "
58
+ PIP_EXTRA_ARGS=" --find-links $CFG_ROOT_DIR /thirdparty"
56
59
fi
57
- PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS --find-links https://thirdparty.aboutcode.org/pypi"
60
+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS --find-links https://thirdparty.aboutcode.org/pypi/simple/links.html "
58
61
59
62
60
63
# ###############################
65
68
66
69
67
70
# ###############################
68
- # find a proper Python to run
69
- # Use environment variables or a file if available.
70
- # Otherwise the latest Python by default.
71
- if [[ " $PYTHON_EXECUTABLE " == " " ]]; then
72
- # check for a file named PYTHON_EXECUTABLE
73
- if [ -f " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" ]; then
74
- PYTHON_EXECUTABLE=$( cat " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" )
75
- else
76
- PYTHON_EXECUTABLE=python3
77
- fi
78
- fi
71
+ # Main command line entry point
72
+ main () {
73
+ CFG_REQUIREMENTS=$REQUIREMENTS
74
+ NO_INDEX=" --no-index"
75
+
76
+ # We are using getopts to parse option arguments that start with "-"
77
+ while getopts :-: optchar; do
78
+ case " ${optchar} " in
79
+ -)
80
+ case " ${OPTARG} " in
81
+ help ) cli_help;;
82
+ clean ) find_python && clean;;
83
+ dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " ;;
84
+ init ) NO_INDEX=" " ;;
85
+ esac ;;
86
+ esac
87
+ done
79
88
89
+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS $NO_INDEX "
80
90
81
- # ###############################
82
- cli_help () {
83
- echo An initial configuration script
84
- echo " usage: ./configure [options]"
85
- echo
86
- echo The default is to configure for regular use. Use --dev for development.
87
- echo Use the --init option if starting a new project and the project
88
- echo dependencies are not available on thirdparty.aboutcode.org/pypi/
89
- echo and requirements.txt and/or requirements-dev.txt has not been generated.
90
- echo
91
- echo The options are:
92
- echo " --clean: clean built and installed files and exit."
93
- echo " --dev: configure the environment for development."
94
- echo " --init: pull dependencies from PyPI. Used when first setting up a project."
95
- echo " --help: display this help message and exit."
96
- echo
97
- echo By default, the python interpreter version found in the path is used.
98
- echo Alternatively, the PYTHON_EXECUTABLE environment variable can be set to
99
- echo configure another Python executable interpreter to use. If this is not
100
- echo set, a file named PYTHON_EXECUTABLE containing a single line with the
101
- echo path of the Python executable to use will be checked last.
102
- set +e
103
- exit
91
+ find_python
92
+ create_virtualenv " $VIRTUALENV_DIR "
93
+ install_packages " $CFG_REQUIREMENTS "
94
+ . " $CFG_BIN_DIR /activate"
104
95
}
105
96
106
97
107
- clean () {
108
- # Remove cleanable file and directories and files from the root dir.
109
- echo " * Cleaning ..."
110
- for cln in $CLEANABLE ;
111
- do rm -rf " ${CFG_ROOT_DIR:? } /${cln:? } " ;
112
- done
113
- set +e
114
- exit
98
+ # ###############################
99
+ # Find a proper Python to run
100
+ # Use environment variables or a file if available.
101
+ # Otherwise the latest Python by default.
102
+ find_python () {
103
+ if [[ " $PYTHON_EXECUTABLE " == " " ]]; then
104
+ # check for a file named PYTHON_EXECUTABLE
105
+ if [ -f " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" ]; then
106
+ PYTHON_EXECUTABLE=$( cat " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" )
107
+ else
108
+ PYTHON_EXECUTABLE=python3
109
+ fi
110
+ fi
115
111
}
116
112
117
113
114
+ # ###############################
118
115
create_virtualenv () {
119
116
# create a virtualenv for Python
120
117
# Note: we do not use the bundled Python 3 "venv" because its behavior and
@@ -145,6 +142,7 @@ create_virtualenv() {
145
142
}
146
143
147
144
145
+ # ###############################
148
146
install_packages () {
149
147
# install requirements in virtualenv
150
148
# note: --no-build-isolation means that pip/wheel/setuptools will not
@@ -162,28 +160,43 @@ install_packages() {
162
160
163
161
164
162
# ###############################
165
- # Main command line entry point
166
- CFG_DEV_MODE=0
167
- CFG_REQUIREMENTS=$REQUIREMENTS
168
- NO_INDEX=" --no-index"
169
-
170
- # We are using getopts to parse option arguments that start with "-"
171
- while getopts :-: optchar; do
172
- case " ${optchar} " in
173
- -)
174
- case " ${OPTARG} " in
175
- help ) cli_help;;
176
- clean ) clean;;
177
- dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " && CFG_DEV_MODE=1;;
178
- init ) NO_INDEX=" " ;;
179
- esac ;;
180
- esac
181
- done
182
-
183
- PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS $NO_INDEX "
184
-
185
- create_virtualenv " $VIRTUALENV_DIR "
186
- install_packages " $CFG_REQUIREMENTS "
187
- . " $CFG_BIN_DIR /activate"
163
+ cli_help () {
164
+ echo An initial configuration script
165
+ echo " usage: ./configure [options]"
166
+ echo
167
+ echo The default is to configure for regular use. Use --dev for development.
168
+ echo Use the --init option if starting a new project and the project
169
+ echo dependencies are not available on thirdparty.aboutcode.org/pypi/
170
+ echo and requirements.txt and/or requirements-dev.txt has not been generated.
171
+ echo
172
+ echo The options are:
173
+ echo " --clean: clean built and installed files and exit."
174
+ echo " --dev: configure the environment for development."
175
+ echo " --init: pull dependencies from PyPI. Used when first setting up a project."
176
+ echo " --help: display this help message and exit."
177
+ echo
178
+ echo By default, the python interpreter version found in the path is used.
179
+ echo Alternatively, the PYTHON_EXECUTABLE environment variable can be set to
180
+ echo configure another Python executable interpreter to use. If this is not
181
+ echo set, a file named PYTHON_EXECUTABLE containing a single line with the
182
+ echo path of the Python executable to use will be checked last.
183
+ set +e
184
+ exit
185
+ }
186
+
187
+
188
+ # ###############################
189
+ clean () {
190
+ # Remove cleanable file and directories and files from the root dir.
191
+ echo " * Cleaning ..."
192
+ for cln in $CLEANABLE ;
193
+ do rm -rf " ${CFG_ROOT_DIR:? } /${cln:? } " ;
194
+ done
195
+ set +e
196
+ exit
197
+ }
198
+
199
+
200
+ main
188
201
189
202
set +e
0 commit comments