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
@@ -26,16 +26,16 @@ CLI_ARGS=$1
2626# ###############################
2727
2828# Requirement arguments passed to pip and used by default or with --dev.
29- REQUIREMENTS=" --editable ."
30- DEV_REQUIREMENTS=" --editable .[testing]"
29+ REQUIREMENTS=" --editable . --constraint requirements.txt "
30+ DEV_REQUIREMENTS=" --editable .[testing] --constraint requirements.txt --constraint requirements-dev.txt "
3131
3232# where we create a virtualenv
33- VIRTUALENV_DIR=tmp
33+ VIRTUALENV_DIR=venv
3434
3535# Cleanable files and directories with the --clean option
3636CLEANABLE="
3737 build
38- tmp "
38+ venv "
3939
4040# extra arguments passed to pip
4141PIP_EXTRA_ARGS=" "
@@ -50,9 +50,15 @@ 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+ # 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 "
56+ fi
57+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS --find-links https://thirdparty.aboutcode.org/pypi"
58+
5359
5460# ###############################
55- # Set the quiet flag to empty if not defined
61+ # Set the quiet flag to empty if not defined
5662if [[ " $CFG_QUIET " == " " ]]; then
5763 CFG_QUIET=" "
5864fi
6369# Use environment variables or a file if available.
6470# Otherwise the latest Python by default.
6571if [[ " $PYTHON_EXECUTABLE " == " " ]]; then
66- # check for a file named PYTHON_EXECUTABLE
72+ # check for a file named PYTHON_EXECUTABLE
6773 if [ -f " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" ]; then
6874 PYTHON_EXECUTABLE=$( cat " $CFG_ROOT_DIR /PYTHON_EXECUTABLE" )
6975 else
@@ -78,10 +84,14 @@ cli_help() {
7884 echo " usage: ./configure [options]"
7985 echo
8086 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.
8190 echo
8291 echo The options are:
8392 echo " --clean: clean built and installed files and exit."
8493 echo " --dev: configure the environment for development."
94+ echo " --init: pull dependencies from PyPI. Used when first setting up a project."
8595 echo " --help: display this help message and exit."
8696 echo
8797 echo By default, the python interpreter version found in the path is used.
@@ -120,7 +130,7 @@ create_virtualenv() {
120130 VIRTUALENV_PYZ=" $CFG_ROOT_DIR /etc/thirdparty/virtualenv.pyz"
121131 else
122132 VIRTUALENV_PYZ=" $CFG_ROOT_DIR /$VENV_DIR /virtualenv.pyz"
123- wget -O " $VIRTUALENV_PYZ " " $VIRTUALENV_PYZ_URL "
133+ wget -O " $VIRTUALENV_PYZ " " $VIRTUALENV_PYZ_URL " 2> /dev/null || curl -o " $VIRTUALENV_PYZ " " $VIRTUALENV_PYZ_URL "
124134 fi
125135
126136 $PYTHON_EXECUTABLE " $VIRTUALENV_PYZ " \
@@ -155,12 +165,22 @@ install_packages() {
155165# Main command line entry point
156166CFG_DEV_MODE=0
157167CFG_REQUIREMENTS=$REQUIREMENTS
158-
159- case " $CLI_ARGS " in
160- --help) cli_help;;
161- --clean) clean;;
162- --dev) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " && CFG_DEV_MODE=1;;
163- esac
168+ NO_INDEX=" --no-index"
169+
170+ # We are using getopts to parse option arguments that start with "-"
171+ while getopts :-: optchar; do
172+ case " ${optchar} " in
173+ -)
174+ case " ${OPTARG} " in
175+ help ) cli_help;;
176+ clean ) clean;;
177+ dev ) CFG_REQUIREMENTS=" $DEV_REQUIREMENTS " && CFG_DEV_MODE=1;;
178+ init ) NO_INDEX=" " ;;
179+ esac ;;
180+ esac
181+ done
182+
183+ PIP_EXTRA_ARGS=" $PIP_EXTRA_ARGS $NO_INDEX "
164184
165185create_virtualenv " $VIRTUALENV_DIR "
166186install_packages " $CFG_REQUIREMENTS "
0 commit comments