@@ -11,11 +11,13 @@ set -e
1111# set -x
1212
1313# ###############################
14- # A configuration script to set things up:
14+ # A configuration script to set things up:
1515# create a virtualenv and install or update thirdparty packages.
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# ###############################
@@ -26,16 +28,15 @@ CLI_ARGS=$1
2628# ###############################
2729
2830# Requirement arguments passed to pip and used by default or with --dev.
29- REQUIREMENTS=" --editable ."
30- DEV_REQUIREMENTS=" --editable .[testing]"
31+ REQUIREMENTS=" --editable . --constraint requirements.txt"
32+ DEV_REQUIREMENTS=" --editable .[testing] --constraint requirements.txt --constraint requirements-dev.txt"
33+ DOCS_REQUIREMENTS=" --editable .[docs] --constraint requirements.txt"
3134
3235# where we create a virtualenv
33- VIRTUALENV_DIR=tmp
36+ VIRTUALENV_DIR=venv
3437
35- # Cleanable files and directories with the --clean option
36- CLEANABLE="
37- build
38- tmp"
38+ # Cleanable files and directories to delete with the --clean option
39+ CLEANABLE=" build venv"
3940
4041# extra arguments passed to pip
4142PIP_EXTRA_ARGS=" "
@@ -52,59 +53,37 @@ CFG_BIN_DIR=$CFG_ROOT_DIR/$VIRTUALENV_DIR/bin
5253
5354
5455# ###############################
55- # Set the quiet flag to empty if not defined
56+ # Thirdparty package locations and index handling
57+ # Find packages from the local thirdparty directory
58+ if [ -d " $CFG_ROOT_DIR /thirdparty" ]; then
59+ PIP_EXTRA_ARGS=" --find-links $CFG_ROOT_DIR /thirdparty"
60+ fi
61+
62+
63+ # ###############################
64+ # Set the quiet flag to empty if not defined
5665if [[ " $CFG_QUIET " == " " ]]; then
5766 CFG_QUIET=" "
5867fi
5968
6069
6170# ###############################
62- # find a proper Python to run
71+ # Find a proper Python to run
6372# Use environment variables or a file if available.
6473# Otherwise the latest Python by default.
65- if [[ " $PYTHON_EXECUTABLE " == " " ]]; then
66- # check for a file named PYTHON_EXECUTABLE
67- if [ -f " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" ]; then
68- PYTHON_EXECUTABLE=$( cat " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" )
69- else
70- 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
7182 fi
72- fi
73-
74-
75- # ###############################
76- cli_help () {
77- echo An initial configuration script
78- echo " usage: ./configure [options]"
79- echo
80- echo The default is to configure for regular use. Use --dev for development.
81- echo
82- echo The options are:
83- echo " --clean: clean built and installed files and exit."
84- echo " --dev: configure the environment for development."
85- echo " --help: display this help message and exit."
86- echo
87- echo By default, the python interpreter version found in the path is used.
88- echo Alternatively, the PYTHON_EXECUTABLE environment variable can be set to
89- echo configure another Python executable interpreter to use. If this is not
90- echo set, a file named PYTHON_EXECUTABLE containing a single line with the
91- echo path of the Python executable to use will be checked last.
92- set +e
93- exit
94- }
95-
96-
97- clean () {
98- # Remove cleanable file and directories and files from the root dir.
99- echo " * Cleaning ..."
100- for cln in $CLEANABLE ;
101- do rm -rf " ${CFG_ROOT_DIR:? } /${cln:? } " ;
102- done
103- set +e
104- exit
10583}
10684
10785
86+ # ###############################
10887create_virtualenv () {
10988 # create a virtualenv for Python
11089 # Note: we do not use the bundled Python 3 "venv" because its behavior and
@@ -120,7 +99,7 @@ create_virtualenv() {
12099 VIRTUALENV_PYZ=" $CFG_ROOT_DIR /etc/thirdparty/virtualenv.pyz"
121100 else
122101 VIRTUALENV_PYZ=" $CFG_ROOT_DIR /$VENV_DIR /virtualenv.pyz"
123- 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 "
124103 fi
125104
126105 $PYTHON_EXECUTABLE " $VIRTUALENV_PYZ " \
@@ -135,6 +114,7 @@ create_virtualenv() {
135114}
136115
137116
117+ # ###############################
138118install_packages () {
139119 # install requirements in virtualenv
140120 # note: --no-build-isolation means that pip/wheel/setuptools will not
@@ -151,19 +131,63 @@ install_packages() {
151131}
152132
153133
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+
154168# ###############################
155169# Main command line entry point
156- CFG_DEV_MODE=0
157170CFG_REQUIREMENTS=$REQUIREMENTS
158171
159- case " $CLI_ARGS " in
160- --help) cli_help;;
161- --clean) clean;;
162- --dev) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " && CFG_DEV_MODE=1;;
163- esac
164-
172+ # We are using getopts to parse option arguments that start with "-"
173+ while getopts :-: optchar; do
174+ case " ${optchar} " in
175+ -)
176+ case " ${OPTARG} " in
177+ help ) cli_help;;
178+ clean ) find_python && clean;;
179+ dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " ;;
180+ docs ) CFG_REQUIREMENTS=" $DOCS_REQUIREMENTS " ;;
181+ esac ;;
182+ esac
183+ done
184+
185+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS "
186+
187+ find_python
165188create_virtualenv " $VIRTUALENV_DIR "
166189install_packages " $CFG_REQUIREMENTS "
167190. " $CFG_BIN_DIR /activate"
168191
192+
169193set +e
0 commit comments