Debian Codegraph @

init_dev_env

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