Here's a bash/zsh function that will do that:
uvenv () {
if [[ $# -ne 1 ]]; then
echo "No venv name provided, exiting."
kill -INT $$
fi
if [[ ! -d $1 ]]; then
echo "Provided venv name '$1' does not exist, exiting."
kill -INT $$
fi
if [[ ! -f "pyproject-$1.toml" ]]; then
echo "Required file 'pyproject-$1.toml' does not exist, exiting."
kill -INT $$
fi
if [[ -f $1/bin/activate ]]; then
echo "Activating the '$1' venv."
source "$1/bin/activate"
ln -s "pyproject-$1.toml" pyproject.toml
else
"$1/bin/activate not found."
fi
}
Put it in your
.bash_profile
or
.zprofile
.
Usage:
mkdir my-project
cd my-project
uv venv venv-gradio
uv venv venv-streamlit
uv init
cp pyproject.toml pyproject-gradio.toml
mv pyproject.toml pyproject-streamlit.toml
uvenv gradio
uvenv streamlit
Should work. :β)