@@ -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 .[full]"
30- DEV_REQUIREMENTS=" --editable .[full,testing]"
31+ REQUIREMENTS=" --editable .[full] --constraint requirements.txt"
32+ DEV_REQUIREMENTS=" --editable .[full,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,38 @@ 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 or from thirdparty.aboutcode.org
58+ if [ -d " $CFG_ROOT_DIR /thirdparty" ]; then
59+ PIP_EXTRA_ARGS=" --find-links $CFG_ROOT_DIR /thirdparty"
60+ fi
61+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS --find-links https://thirdparty.aboutcode.org/pypi/simple/links.html"
62+
63+
64+ # ###############################
65+ # Set the quiet flag to empty if not defined
5666if [[ " $CFG_QUIET " == " " ]]; then
5767 CFG_QUIET=" "
5868fi
5969
6070
6171# ###############################
62- # find a proper Python to run
72+ # Find a proper Python to run
6373# Use environment variables or a file if available.
6474# 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
75+ find_python () {
76+ if [[ " $PYTHON_EXECUTABLE " == " " ]]; then
77+ # check for a file named PYTHON_EXECUTABLE
78+ if [ -f " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" ]; then
79+ PYTHON_EXECUTABLE=$( cat " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" )
80+ else
81+ PYTHON_EXECUTABLE=python3
82+ fi
7183 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
10584}
10685
10786
87+ # ###############################
10888create_virtualenv () {
10989 # create a virtualenv for Python
11090 # Note: we do not use the bundled Python 3 "venv" because its behavior and
@@ -120,7 +100,7 @@ create_virtualenv() {
120100 VIRTUALENV_PYZ=" $CFG_ROOT_DIR /etc/thirdparty/virtualenv.pyz"
121101 else
122102 VIRTUALENV_PYZ=" $CFG_ROOT_DIR /$VENV_DIR /virtualenv.pyz"
123- wget -O " $VIRTUALENV_PYZ " " $VIRTUALENV_PYZ_URL "
103+ wget -O " $VIRTUALENV_PYZ " " $VIRTUALENV_PYZ_URL " 2> /dev/null || curl -o " $VIRTUALENV_PYZ " " $VIRTUALENV_PYZ_URL "
124104 fi
125105
126106 $PYTHON_EXECUTABLE " $VIRTUALENV_PYZ " \
@@ -135,6 +115,7 @@ create_virtualenv() {
135115}
136116
137117
118+ # ###############################
138119install_packages () {
139120 # install requirements in virtualenv
140121 # note: --no-build-isolation means that pip/wheel/setuptools will not
@@ -151,19 +132,63 @@ install_packages() {
151132}
152133
153134
135+ # ###############################
136+ cli_help () {
137+ echo An initial configuration script
138+ echo " usage: ./configure [options]"
139+ echo
140+ echo The default is to configure for regular use. Use --dev for development.
141+ echo
142+ echo The options are:
143+ echo " --clean: clean built and installed files and exit."
144+ echo " --dev: configure the environment for development."
145+ echo " --help: display this help message and exit."
146+ echo
147+ echo By default, the python interpreter version found in the path is used.
148+ echo Alternatively, the PYTHON_EXECUTABLE environment variable can be set to
149+ echo configure another Python executable interpreter to use. If this is not
150+ echo set, a file named PYTHON_EXECUTABLE containing a single line with the
151+ echo path of the Python executable to use will be checked last.
152+ set +e
153+ exit
154+ }
155+
156+
157+ # ###############################
158+ clean () {
159+ # Remove cleanable file and directories and files from the root dir.
160+ echo " * Cleaning ..."
161+ for cln in $CLEANABLE ;
162+ do rm -rf " ${CFG_ROOT_DIR:? } /${cln:? } " ;
163+ done
164+ set +e
165+ exit
166+ }
167+
168+
154169# ###############################
155170# Main command line entry point
156- CFG_DEV_MODE=0
157171CFG_REQUIREMENTS=$REQUIREMENTS
158172
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-
173+ # We are using getopts to parse option arguments that start with "-"
174+ while getopts :-: optchar; do
175+ case " ${optchar} " in
176+ -)
177+ case " ${OPTARG} " in
178+ help ) cli_help;;
179+ clean ) find_python && clean;;
180+ dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " ;;
181+ docs ) CFG_REQUIREMENTS=" $DOCS_REQUIREMENTS " ;;
182+ esac ;;
183+ esac
184+ done
185+
186+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS "
187+
188+ find_python
165189create_virtualenv " $VIRTUALENV_DIR "
166190install_packages " $CFG_REQUIREMENTS "
167191. " $CFG_BIN_DIR /activate"
168192
193+
169194set +e
0 commit comments