From da0a64ccbd48e5261c3f1f7f57fe142ba90cc091 Mon Sep 17 00:00:00 2001 From: bretello Date: Wed, 25 Dec 2024 20:59:30 +0100 Subject: [PATCH] zsh: functions: add uv support in mkvenv --- functions/python.zsh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/functions/python.zsh b/functions/python.zsh index 13c2e94..0015ed2 100644 --- a/functions/python.zsh +++ b/functions/python.zsh @@ -32,9 +32,16 @@ mkvenv(){ info "Creating virtualenv ${venv_name}... " - if ! python -m virtualenv $@ ${venv_name} ; then - error "Failed to create virtualenv. Is virtualenv installed? Try:\n $ pip install virtualenv" - return 1 + + if (( ${+commands[uv]} )); then + info "Creating venv using uv" + uv venv $@ ${venv_name} + else + warning "uv is not available, falling back to virtualenv module" + if ! python -m virtualenv $@ ${venv_name} ; then + warning "virtualenv module is not available, virtualenv creation will be slow. Install uv or virtualenv." + python -m venv $@ ${venv_name} + fi fi if [[ -z ${source_venv} ]]; then