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,8 +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
54- PIP_EXTRA_ARGS=" --find-links $CFG_ROOT_DIR /thirdparty --find-links https://thirdparty.aboutcode.org/pypi"
57+ if [ -f " $CFG_ROOT_DIR /thirdparty" ]; then
58+ PIP_EXTRA_ARGS=" --find-links $CFG_ROOT_DIR /thirdparty"
59+ fi
60+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS --find-links https://thirdparty.aboutcode.org/pypi/simple/links.html"
5561
5662
5763# ###############################
6268
6369
6470# ###############################
65- # find a proper Python to run
71+ # Find a proper Python to run
6672# Use environment variables or a file if available.
6773# Otherwise the latest Python by default.
68- if [[ " $PYTHON_EXECUTABLE " == " " ]]; then
69- # check for a file named PYTHON_EXECUTABLE
70- if [ -f " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" ]; then
71- PYTHON_EXECUTABLE=$( cat " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" )
72- else
73- 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
7482 fi
75- fi
76-
77-
78- # ###############################
79- cli_help () {
80- echo An initial configuration script
81- echo " usage: ./configure [options]"
82- echo
83- echo The default is to configure for regular use. Use --dev for development.
84- echo Use the --init option if starting a new project and the project
85- echo dependencies are not available on thirdparty.aboutcode.org/pypi/
86- echo and requirements.txt and/or requirements-dev.txt has not been generated.
87- echo
88- echo The options are:
89- echo " --clean: clean built and installed files and exit."
90- echo " --dev: configure the environment for development."
91- echo " --init: pull dependencies from PyPI. Used when first setting up a project."
92- echo " --help: display this help message and exit."
93- echo
94- echo By default, the python interpreter version found in the path is used.
95- echo Alternatively, the PYTHON_EXECUTABLE environment variable can be set to
96- echo configure another Python executable interpreter to use. If this is not
97- echo set, a file named PYTHON_EXECUTABLE containing a single line with the
98- echo path of the Python executable to use will be checked last.
99- set +e
100- exit
101- }
102-
103-
104- clean () {
105- # Remove cleanable file and directories and files from the root dir.
106- echo " * Cleaning ..."
107- for cln in $CLEANABLE ;
108- do rm -rf " ${CFG_ROOT_DIR:? } /${cln:? } " ;
109- done
110- set +e
111- exit
11283}
11384
11485
86+ # ###############################
11587create_virtualenv () {
11688 # create a virtualenv for Python
11789 # Note: we do not use the bundled Python 3 "venv" because its behavior and
@@ -127,7 +99,7 @@ create_virtualenv() {
12799 VIRTUALENV_PYZ=" $CFG_ROOT_DIR /etc/thirdparty/virtualenv.pyz"
128100 else
129101 VIRTUALENV_PYZ=" $CFG_ROOT_DIR /$VENV_DIR /virtualenv.pyz"
130- wget -O " $VIRTUALENV_PYZ " " $VIRTUALENV_PYZ_URL "
102+ wget -O " $VIRTUALENV_PYZ " " $VIRTUALENV_PYZ_URL " 2> /dev/null || curl -o " $VIRTUALENV_PYZ " " $VIRTUALENV_PYZ_URL "
131103 fi
132104
133105 $PYTHON_EXECUTABLE " $VIRTUALENV_PYZ " \
@@ -142,6 +114,7 @@ create_virtualenv() {
142114}
143115
144116
117+ # ###############################
145118install_packages () {
146119 # install requirements in virtualenv
147120 # note: --no-build-isolation means that pip/wheel/setuptools will not
@@ -158,29 +131,62 @@ install_packages() {
158131}
159132
160133
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+
161168# ###############################
162169# Main command line entry point
163- CFG_DEV_MODE=0
164170CFG_REQUIREMENTS=$REQUIREMENTS
165- NO_INDEX=" --no-index"
166171
167172# We are using getopts to parse option arguments that start with "-"
168173while getopts :-: optchar; do
169174 case " ${optchar} " in
170175 -)
171176 case " ${OPTARG} " in
172177 help ) cli_help;;
173- clean ) clean;;
174- dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " && CFG_DEV_MODE=1;;
175- init ) NO_INDEX=" " ;;
178+ clean ) find_python && clean;;
179+ dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " ;;
176180 esac ;;
177181 esac
178182done
179183
180- PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS $NO_INDEX "
184+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS "
181185
186+ find_python
182187create_virtualenv " $VIRTUALENV_DIR "
183188install_packages " $CFG_REQUIREMENTS "
184189. " $CFG_BIN_DIR /activate"
185190
191+
186192set +e
0 commit comments