1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!/usr/bin/env bash
#
# Copyright 2009-2024 Joshua Bronson. All rights reserved.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# shellcheck disable=SC1091
set -euo pipefail
declare -r hint="Hint: Use 'nix develop' to bootstrap a development environment"
source ./dev-deps/py_ver.env
for cmd in "$DEFAULT_PY" uv pre-commit; do
if ! type "$cmd"; then
>&2 echo "Error: No '$cmd' on PATH. $hint"
exit 1
fi
done
pre-commit install -f
export VENV_DIR=".venv"
if ! test -d "$VENV_DIR"; then
uv venv --python="$DEFAULT_PY" "$VENV_DIR"
fi
declare -r req_sets="dev docs test"
declare -r out_dir="dev-deps/$DEFAULT_PY"
mkdir -p "$out_dir"
for i in $req_sets; do
reqs_in="dev-deps/$i.in"
reqs_out="$out_dir/$i.txt"
# The following options should match those passed in dev-deps/update_dev_dependencies so that the
# resulting "autogenerated...via the following command:" comments match.
uv pip compile --generate-hashes --upgrade --python-version="$DEFAULT_PY_VER" "$reqs_in" -o "$reqs_out"
done
# TODO The following triggers https://github.com/astral-sh/uv/issues/1552
# uv pip sync $out_dir/*.txt
# so work around this as follows:
declare -r reqs=("$out_dir"/*.txt)
uv pip install "${reqs[@]/#/-r}"
# TODO Until https://github.com/astral-sh/uv/issues/1594 is fixed, we can't use the following:
# if ! uv pip show -qq bidict; then
# so work around this as follows:
if ! uv pip freeze | grep -q ^bidict; then
uv pip install -e .
fi
echo "Development virtualenv initialized: ./$VENV_DIR"
echo "To activate, run: source ./$VENV_DIR/bin/activate (or equivalent for your shell)"
|