Skip to content

Commit

Permalink
Extract suggest_venv out of the else block
Browse files Browse the repository at this point in the history
I think this is easier to read, but this is admittedly subjective.

This commit also makes the separate change of adjusting comment
spacing for consistency within the script. (Two spaces before "#"
is not widely regarded as better than one in shell scripting, so
unlike Python where PEP-8 recommends that, it would be equally good
to have changed all the other places in the shell scrips to have
just one.)
  • Loading branch information
EliahKagan committed Oct 3, 2023
1 parent 21875b5 commit 0920371
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ function release_with() {
"$1" -m build --sdist --wheel
}

function suggest_venv() {
local venv_cmd='python -m venv env && source env/bin/activate'
printf "HELP: To avoid this error, use a virtual-env with '%s' instead.\n" "$venv_cmd"
}

if test -n "${VIRTUAL_ENV:-}"; then
deps=(build twine) # Install twine along with build, as we need it later.
echo "Virtual environment detected. Adding packages: ${deps[*]}"
pip install --quiet --upgrade "${deps[@]}"
echo 'Starting the build.'
release_with python
else
function suggest_venv() {
venv_cmd='python -m venv env && source env/bin/activate'
printf "HELP: To avoid this error, use a virtual-env with '%s' instead.\n" "$venv_cmd"
}
trap suggest_venv ERR # This keeps the original exit (error) code.
echo 'Starting the build.'
release_with python3 # Outside a venv, use python3.
release_with python3 # Outside a venv, use python3.
fi

0 comments on commit 0920371

Please sign in to comment.