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
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
7988
89+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS $NO_INDEX "
8090
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"
10495}
10596
10697
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
115111}
116112
117113
114+ # ###############################
118115create_virtualenv () {
119116 # create a virtualenv for Python
120117 # Note: we do not use the bundled Python 3 "venv" because its behavior and
@@ -145,6 +142,7 @@ create_virtualenv() {
145142}
146143
147144
145+ # ###############################
148146install_packages () {
149147 # install requirements in virtualenv
150148 # note: --no-build-isolation means that pip/wheel/setuptools will not
@@ -162,28 +160,43 @@ install_packages() {
162160
163161
164162# ###############################
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
188201
189202set +e
0 commit comments