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,19 +30,13 @@ CLI_ARGS=$1
2830# Requirement arguments passed to pip and used by default or with --dev.
2931REQUIREMENTS=" --editable . --constraint requirements.txt"
3032DEV_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
3336VIRTUALENV_DIR=venv
3437
35- # Cleanable files and directories with the --clean option
36- CLEANABLE="
37- build
38- tmp
39- bin
40- Lib
41- Scripts
42- include
43- venv"
38+ # Cleanable files and directories to delete with the --clean option
39+ CLEANABLE=" build venv"
4440
4541# extra arguments passed to pip
4642PIP_EXTRA_ARGS=" "
@@ -55,11 +51,13 @@ VIRTUALENV_PYZ_URL=https://bootstrap.pypa.io/virtualenv.pyz
5551CFG_ROOT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
5652CFG_BIN_DIR=$CFG_ROOT_DIR /$VIRTUALENV_DIR /bin
5753
58- # Find packages from the local thirdparty directory or from thirdparty.aboutcode.org
59- if [ -f " $CFG_ROOT_DIR /thirdparty" ]; then
60- PIP_EXTRA_ARGS=" --find-links $CFG_ROOT_DIR /thirdparty "
54+
55+ # ###############################
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"
6160fi
62- PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS --find-links https://thirdparty.aboutcode.org/pypi"
6361
6462
6563# ###############################
7068
7169
7270# ###############################
73- # find a proper Python to run
71+ # Find a proper Python to run
7472# Use environment variables or a file if available.
7573# Otherwise the latest Python by default.
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
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
8282 fi
83- fi
84-
85-
86- # ###############################
87- cli_help () {
88- echo An initial configuration script
89- echo " usage: ./configure [options]"
90- echo
91- echo The default is to configure for regular use. Use --dev for development.
92- echo Use the --init option if starting a new project and the project
93- echo dependencies are not available on thirdparty.aboutcode.org/pypi/
94- echo and requirements.txt and/or requirements-dev.txt has not been generated.
95- echo
96- echo The options are:
97- echo " --clean: clean built and installed files and exit."
98- echo " --dev: configure the environment for development."
99- echo " --init: pull dependencies from PyPI. Used when first setting up a project."
100- echo " --help: display this help message and exit."
101- echo
102- echo By default, the python interpreter version found in the path is used.
103- echo Alternatively, the PYTHON_EXECUTABLE environment variable can be set to
104- echo configure another Python executable interpreter to use. If this is not
105- echo set, a file named PYTHON_EXECUTABLE containing a single line with the
106- echo path of the Python executable to use will be checked last.
107- set +e
108- exit
109- }
110-
111-
112- clean () {
113- # Remove cleanable file and directories and files from the root dir.
114- echo " * Cleaning ..."
115- for cln in $CLEANABLE ;
116- do rm -rf " ${CFG_ROOT_DIR:? } /${cln:? } " ;
117- done
118- set +e
119- exit
12083}
12184
12285
86+ # ###############################
12387create_virtualenv () {
12488 # create a virtualenv for Python
12589 # Note: we do not use the bundled Python 3 "venv" because its behavior and
@@ -150,6 +114,7 @@ create_virtualenv() {
150114}
151115
152116
117+ # ###############################
153118install_packages () {
154119 # install requirements in virtualenv
155120 # note: --no-build-isolation means that pip/wheel/setuptools will not
@@ -166,29 +131,63 @@ install_packages() {
166131}
167132
168133
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+
169168# ###############################
170169# Main command line entry point
171- CFG_DEV_MODE=0
172170CFG_REQUIREMENTS=$REQUIREMENTS
173- NO_INDEX=" --no-index"
174171
175172# We are using getopts to parse option arguments that start with "-"
176173while getopts :-: optchar; do
177174 case " ${optchar} " in
178175 -)
179176 case " ${OPTARG} " in
180177 help ) cli_help;;
181- clean ) clean;;
182- dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " && CFG_DEV_MODE=1 ;;
183- init ) NO_INDEX= " " ;;
178+ clean ) find_python && clean;;
179+ dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " ;;
180+ docs ) CFG_REQUIREMENTS= " $DOCS_REQUIREMENTS " ;;
184181 esac ;;
185182 esac
186183done
187184
188- PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS $NO_INDEX "
185+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS "
189186
187+ find_python
190188create_virtualenv " $VIRTUALENV_DIR "
191189install_packages " $CFG_REQUIREMENTS "
192190. " $CFG_BIN_DIR /activate"
193191
192+
194193set +e
0 commit comments