@@ -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# ###############################
@@ -28,14 +30,13 @@ CLI_ARGS=$1
2830# Requirement arguments passed to pip and used by default or with --dev.
2931REQUIREMENTS=" --editable .[full] --constraint requirements.txt"
3032DEV_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
3336VIRTUALENV_DIR=venv
3437
35- # Cleanable files and directories with the --clean option
36- CLEANABLE="
37- build
38- venv"
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=" "
@@ -50,11 +51,14 @@ VIRTUALENV_PYZ_URL=https://bootstrap.pypa.io/virtualenv.pyz
5051CFG_ROOT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
5152CFG_BIN_DIR=$CFG_ROOT_DIR /$VIRTUALENV_DIR /bin
5253
54+
55+ # ###############################
56+ # Thirdparty package locations and index handling
5357# Find packages from the local thirdparty directory or from thirdparty.aboutcode.org
54- if [ -f " $CFG_ROOT_DIR /thirdparty" ]; then
55- PIP_EXTRA_ARGS=" --find-links $CFG_ROOT_DIR /thirdparty "
58+ if [ -d " $CFG_ROOT_DIR /thirdparty" ]; then
59+ PIP_EXTRA_ARGS=" --find-links $CFG_ROOT_DIR /thirdparty"
5660fi
57- PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS --find-links https://thirdparty.aboutcode.org/pypi"
61+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS --find-links https://thirdparty.aboutcode.org/pypi/simple/links.html "
5862
5963
6064# ###############################
6569
6670
6771# ###############################
68- # find a proper Python to run
72+ # Find a proper Python to run
6973# Use environment variables or a file if available.
7074# 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
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
7783 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
11584}
11685
11786
87+ # ###############################
11888create_virtualenv () {
11989 # create a virtualenv for Python
12090 # Note: we do not use the bundled Python 3 "venv" because its behavior and
@@ -145,6 +115,7 @@ create_virtualenv() {
145115}
146116
147117
118+ # ###############################
148119install_packages () {
149120 # install requirements in virtualenv
150121 # note: --no-build-isolation means that pip/wheel/setuptools will not
@@ -161,29 +132,63 @@ install_packages() {
161132}
162133
163134
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+
164169# ###############################
165170# Main command line entry point
166- CFG_DEV_MODE=0
167171CFG_REQUIREMENTS=$REQUIREMENTS
168- NO_INDEX=" --no-index"
169172
170173# We are using getopts to parse option arguments that start with "-"
171174while getopts :-: optchar; do
172175 case " ${optchar} " in
173176 -)
174177 case " ${OPTARG} " in
175178 help ) cli_help;;
176- clean ) clean;;
177- dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " && CFG_DEV_MODE=1 ;;
178- init ) NO_INDEX= " " ;;
179+ clean ) find_python && clean;;
180+ dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " ;;
181+ docs ) CFG_REQUIREMENTS= " $DOCS_REQUIREMENTS " ;;
179182 esac ;;
180183esac
181184done
182185
183- PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS $NO_INDEX "
186+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS "
184187
188+ find_python
185189create_virtualenv " $VIRTUALENV_DIR "
186190install_packages " $CFG_REQUIREMENTS "
187191. " $CFG_BIN_DIR /activate"
188192
193+
189194set +e
0 commit comments