1616# Source this script for initial configuration
1717# Use configure --help for details
1818#
19+ # NOTE: please keep in sync with Windows script configure.bat
20+ #
1921# This script will search for a virtualenv.pyz app in etc/thirdparty/virtualenv.pyz
2022# Otherwise it will download the latest from the VIRTUALENV_PYZ_URL default
2123# ###############################
@@ -32,10 +34,8 @@ DEV_REQUIREMENTS="--editable .[testing] --constraint requirements.txt --constrai
3234# where we create a virtualenv
3335VIRTUALENV_DIR=venv
3436
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"
3939
4040# extra arguments passed to pip
4141PIP_EXTRA_ARGS=" "
@@ -50,11 +50,14 @@ VIRTUALENV_PYZ_URL=https://bootstrap.pypa.io/virtualenv.pyz
5050CFG_ROOT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
5151CFG_BIN_DIR=$CFG_ROOT_DIR /$VIRTUALENV_DIR /bin
5252
53+
54+ # ###############################
55+ # Thirdparty package locations and index handling
5356# Find packages from the local thirdparty directory or from thirdparty.aboutcode.org
5457if [ -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"
5659fi
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 "
5861
5962
6063# ###############################
6568
6669
6770# ###############################
68- # find a proper Python to run
71+ # Find a proper Python to run
6972# Use environment variables or a file if available.
7073# 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
74+ find_python () {
75+ if [[ " $PYTHON_EXECUTABLE " == " " ]]; then
76+ # check for a file named PYTHON_EXECUTABLE
77+ if [ -f " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" ]; then
78+ PYTHON_EXECUTABLE=$( cat " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" )
79+ else
80+ PYTHON_EXECUTABLE=python3
81+ fi
7782 fi
78- fi
79-
80-
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
104- }
105-
106-
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
11583}
11684
11785
86+ # ###############################
11887create_virtualenv () {
11988 # create a virtualenv for Python
12089 # Note: we do not use the bundled Python 3 "venv" because its behavior and
@@ -145,6 +114,7 @@ create_virtualenv() {
145114}
146115
147116
117+ # ###############################
148118install_packages () {
149119 # install requirements in virtualenv
150120 # note: --no-build-isolation means that pip/wheel/setuptools will not
@@ -161,29 +131,62 @@ install_packages() {
161131}
162132
163133
134+ # ###############################
135+ cli_help () {
136+ echo An initial configuration script
137+ echo " usage: ./configure [options]"
138+ echo
139+ echo The default is to configure for regular use. Use --dev for development.
140+ echo
141+ echo The options are:
142+ echo " --clean: clean built and installed files and exit."
143+ echo " --dev: configure the environment for development."
144+ echo " --help: display this help message and exit."
145+ echo
146+ echo By default, the python interpreter version found in the path is used.
147+ echo Alternatively, the PYTHON_EXECUTABLE environment variable can be set to
148+ echo configure another Python executable interpreter to use. If this is not
149+ echo set, a file named PYTHON_EXECUTABLE containing a single line with the
150+ echo path of the Python executable to use will be checked last.
151+ set +e
152+ exit
153+ }
154+
155+
156+ # ###############################
157+ clean () {
158+ # Remove cleanable file and directories and files from the root dir.
159+ echo " * Cleaning ..."
160+ for cln in $CLEANABLE ;
161+ do rm -rf " ${CFG_ROOT_DIR:? } /${cln:? } " ;
162+ done
163+ set +e
164+ exit
165+ }
166+
167+
164168# ###############################
165169# Main command line entry point
166- CFG_DEV_MODE=0
167170CFG_REQUIREMENTS=$REQUIREMENTS
168- NO_INDEX=" --no-index"
169171
170172# We are using getopts to parse option arguments that start with "-"
171173while getopts :-: optchar; do
172174 case " ${optchar} " in
173175 -)
174176 case " ${OPTARG} " in
175177 help ) cli_help;;
176- clean ) clean;;
177- dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " && CFG_DEV_MODE=1;;
178- init ) NO_INDEX=" " ;;
178+ clean ) find_python && clean;;
179+ dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " ;;
179180 esac ;;
180181 esac
181182done
182183
183- PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS $NO_INDEX "
184+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS "
184185
186+ find_python
185187create_virtualenv " $VIRTUALENV_DIR "
186188install_packages " $CFG_REQUIREMENTS "
187189. " $CFG_BIN_DIR /activate"
188190
191+
189192set +e
0 commit comments