2025-02-07 08:38:58 -05:00
|
|
|
#!/usr/bin/env sh
|
2025-02-11 14:00:07 -05:00
|
|
|
# Copyright 2025 New Vector Ltd.
|
2025-02-07 08:38:58 -05:00
|
|
|
#
|
2025-02-10 15:01:20 -05:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
|
# Please see LICENSE files in the repository root for full details.
|
2025-02-07 08:38:58 -05:00
|
|
|
|
|
|
|
|
# A script to run a command in a python virtual environment that is stored in
|
|
|
|
|
# `<repo-root>/.venv`. If the virtual environment doesn't exist yet, it will
|
|
|
|
|
# be created.
|
|
|
|
|
#
|
|
|
|
|
# Example: $ ./run_in_venv.sh python --version
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
2025-02-07 10:06:01 -05:00
|
|
|
cd -- "$(dirname -- "$0")/.."
|
2025-02-07 08:38:58 -05:00
|
|
|
|
|
|
|
|
repo_root=$(git rev-parse --show-cdup)
|
|
|
|
|
venv_path=${repo_root:-./}.venv
|
|
|
|
|
|
2025-02-07 11:36:10 -05:00
|
|
|
if [ ! -d "$venv_path" ]; then
|
|
|
|
|
"python${PYTHON_VERSION:-3}" -m venv "$venv_path"
|
|
|
|
|
"$venv_path/bin/pip" install -e ."[dev]"
|
|
|
|
|
fi
|
2025-02-07 08:38:58 -05:00
|
|
|
|
2025-02-07 11:36:10 -05:00
|
|
|
[ $# -gt 1 ] && . "$venv_path/bin/activate" && "$@"
|