File: .envrc.use_venv

package info (click to toggle)
python-parse-type 0.6.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 772 kB
  • sloc: python: 5,273; sh: 9; makefile: 6
file content (53 lines) | stat: -rw-r--r-- 1,827 bytes parent folder | download
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
# ===========================================================================
# PROJECT ENVIRONMENT SETUP: .envrc.use_venv
# ===========================================================================
# REQUIRES: direnv >= 2.21.0  -- NEEDED FOR: venv support
# REQUIRES: uv -- pipx install uv
# DESCRIPTION:
#   Setup and use a Python virtual environment (venv).
#   On entering the directory: Creates and activates a venv for a python version.
#   On leaving  the directory: Deactivates the venv (virtual environment).
#
# ENABLE/DISABLE THIS OPTIONAL PART:
#   * TO ENABLE:  Rename ".envrc.use_venv.DISABLED" to ".envrc.use_venv"
#   * TO DISABLE: Rename ".envrc.use_venv" to ".envrc.use_venv.DISABLED"
#
# SEE ALSO:
#   * https://direnv.net/
#   * https://github.com/direnv/direnv/wiki/Python
#   * https://direnv.net/man/direnv-stdlib.1.html#codelayout-python-ltpythonexegtcode
# ===========================================================================

# -- BASED ON:
# * https://www.pythonbynight.com/blog/terminal
# * https://github.com/tataraba/dotfiles/blob/main/.config/direnv/direnvrc
function layout_uv() {
    # MAYBE: UV_PROJECT_ENVIRONMENT
    if [[ -d ".venv" ]]; then
        VIRTUAL_ENV="$(pwd)/.venv"
    fi

    if [[ -z $VIRTUAL_ENV || ! -d $VIRTUAL_ENV ]]; then
        log_status "CREATE_VENV: Using uv venv ..."
        uv venv
        uv pip install -r py.requirements/all.txt
        VIRTUAL_ENV="$(pwd)/.venv"
    fi

    PATH_add "$VIRTUAL_ENV/bin"
    export UV_ACTIVE=1  # or VENV_ACTIVE=1
    export VIRTUAL_ENV
}

function use_venv() {
    uv venv
    source .venv/bin/activate
    export UV_ACTIVE=1
}

# -- VIRTUAL ENVIRONMENT SUPPORT: layout python python3
# VENV LOCATION: .direnv/python-$(PYTHON_VERSION)
# OLD: layout python python3

# -- VIRTUAL ENVIRONMENT SUPPORT: With uv
layout uv