Skip to content

Commit

Permalink
refinements to build-reelase.sh
Browse files Browse the repository at this point in the history
- use `echo` where feasible to avoid explicit newlines
- use `function` syntax out of habit
- deduplicate release invocation
- make `venv` based invocation less verbose
- make help-text in non-venv more prominent
  • Loading branch information
Byron committed Sep 15, 2023
1 parent 5919f8d commit 1e0b3f9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@

set -eEu

function release_with() {
$1 -m build --sdist --wheel
}

if test -n "${VIRTUAL_ENV:-}"; then
deps=(build twine) # Install twine along with build, as we need it later.
printf 'Virtual environment detected. Adding packages: %s\n' "${deps[*]}"
pip install -U "${deps[@]}"
printf 'Starting the build.\n'
python -m build --sdist --wheel
echo "Virtual environment detected. Adding packages: ${deps[*]}"
pip install --quiet --upgrade "${deps[@]}"
echo 'Starting the build.'
release_with python
else
suggest_venv() {
function suggest_venv() {
venv_cmd='python -m venv env && source env/bin/activate'
printf "Use a virtual-env with '%s' instead.\n" "$venv_cmd"
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.
printf 'Starting the build.\n'
python3 -m build --sdist --wheel # Outside a venv, use python3.
echo 'Starting the build.'
release_with python3 # Outside a venv, use python3.
fi

0 comments on commit 1e0b3f9

Please sign in to comment.