Skip to content

Commit b0a20bd

Browse files
authored
Adding bash "unoffical strict mode" to setup scripts. (#512)
1 parent cc3fcaf commit b0a20bd

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

python-project-template/.initialize_new_project.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
#!/usr/bin/env bash
22

3+
# Bash Unofficial strict mode (http://redsymbol.net/articles/unofficial-bash-strict-mode/)
4+
# and (https://disconnected.systems/blog/another-bash-strict-mode/)
5+
set -o nounset # Any uninitialized variable is an error
6+
set -o errexit # Exit the script on the failure of any command to execute without error
7+
set -o pipefail # Fail command pipelines on the failure of any individual step
8+
IFS=$'\n\t' #set internal field separator to avoid iteration errors
9+
# Trap all exits and output something helpful
10+
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
11+
312
echo "Checking virtual environment"
4-
if [ -z "${VIRTUAL_ENV}" ] && [ -z "${CONDA_PREFIX}" ]; then
13+
if [ "${VIRTUAL_ENV:-missing}" = "missing" ] && [ "${CONDA_PREFIX:-missing}" = "missing" ]; then
514
echo 'No virtual environment detected: none of $VIRTUAL_ENV or $CONDA_PREFIX is set.'
615
echo
716
echo "=== This script is going to install the project in the system python environment ==="
@@ -17,7 +26,7 @@ fi
1726

1827
echo "Checking pip version"
1928
MINIMUM_PIP_VERSION=22
20-
pipversion=( $(python -m pip --version | awk '{print $2}' | sed 's/\./ /g') )
29+
pipversion=( $(python -m pip --version | awk '{print $2}' | sed 's/\./\n\t/g') )
2130
if let "${pipversion[0]}<${MINIMUM_PIP_VERSION}"; then
2231
echo "Insufficient version of pip found. Requires at least version ${MINIMUM_PIP_VERSION}."
2332
echo "See https://lincc-ppt.readthedocs.io/ for details."
@@ -26,7 +35,7 @@ fi
2635

2736
echo "Initializing local git repository"
2837
{
29-
gitversion=( $(git version | git version | awk '{print $3}' | sed 's/\./ /g') )
38+
gitversion=( $(git version | git version | awk '{print $3}' | sed 's/\./\n\t/g') )
3039
if let "${gitversion[0]}<2"; then
3140
# manipulate directly
3241
git init . && echo 'ref: refs/heads/main' >.git/HEAD

python-project-template/.setup_dev.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#!/usr/bin/env bash
22

3+
# Bash Unofficial strict mode (http://redsymbol.net/articles/unofficial-bash-strict-mode/)
4+
# and (https://disconnected.systems/blog/another-bash-strict-mode/)
5+
set -o nounset # Any uninitialized variable is an error
6+
set -o errexit # Exit the script on the failure of any command to execute without error
7+
set -o pipefail # Fail command pipelines on the failure of any individual step
8+
IFS=$'\n\t' #set internal field separator to avoid iteration errors
9+
# Trap all exits and output something helpful
10+
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
11+
312
# This script should be run by new developers to install this package in
413
# editable mode and configure their local environment
514

615
echo "Checking virtual environment"
7-
if [ -z "${VIRTUAL_ENV}" ] && [ -z "${CONDA_PREFIX}" ]; then
16+
if [ "${VIRTUAL_ENV:-missing}" = "missing" ] && [ "${CONDA_PREFIX:-missing}" = "missing" ]; then
817
echo 'No virtual environment detected: none of $VIRTUAL_ENV or $CONDA_PREFIX is set.'
918
echo
1019
echo "=== This script is going to install the project in the system python environment ==="
@@ -20,7 +29,7 @@ fi
2029

2130
echo "Checking pip version"
2231
MINIMUM_PIP_VERSION=22
23-
pipversion=( $(python -m pip --version | awk '{print $2}' | sed 's/\./ /g') )
32+
pipversion=( $(python -m pip --version | awk '{print $2}' | sed 's/\./\n\t/g') )
2433
if let "${pipversion[0]}<${MINIMUM_PIP_VERSION}"; then
2534
echo "Insufficient version of pip found. Requires at least version ${MINIMUM_PIP_VERSION}."
2635
echo "See https://lincc-ppt.readthedocs.io/ for details."

0 commit comments

Comments
 (0)