#! /usr/bin/env sh root="/prj/venv" url="http://localhost:8000" url_pypi="${url}/pypi/simple" activate() { echo export VIRTUAL_ENV="${1}" echo "→ ${VIRTUAL_ENV}" export OLD_PATH="${PATH}" export PATH="${VIRTUAL_ENV}/bin:${PATH}" echo "→ ${PATH}" python3 --version pip --version } caches() { local command="${1}" set \ ".cache/pip" \ ".cache/uv" \ ".local/share/pip" \ ".local/share/uv" echo echo "caches:" for cache in "${@}"; do "${command}" "${HOME}/${cache}" done } deactivate() { echo echo "← ${VIRTUAL_ENV}" export PATH="${OLD_PATH}" echo "← ${PATH}" unset OLD_PATH VIRTUAL_ENV } list() { echo ls -a -l "${1}/${2}" } list_venv() { list "${1}" "bin" } pip_install() { echo pip install \ --index-url "${url_pypi}" \ --no-cache-dir \ "${@}" } remove() { rm --force --recursive "${@}" } uv_install() { set \ "pelican" \ \ "hatch" \ \ "Sphinx" \ "sphinx-rtd-theme" \ \ "gitlint" \ \ "pydoclint" \ "pylint" \ "ruff" \ \ "pytest" \ \ "toml" \ \ "twine" \ \ "mypy" \ "pyright" \ \ "ruamel.yaml" \ "PyYAML" \ "types-PyYAML" echo uv pip install --index-url "${url_pypi}" "${@}" } uv_python() { echo export UV_PYTHON_INSTALL_MIRROR="${url}/cpypy" uv python install "${2}" unset UV_PYTHON_INSTALL_MIRROR } uv_venv() { echo uv venv \ --allow-existing \ --index-url "${url_pypi}" \ --python "${2}" \ --relocatable \ --seed \ "${1}" } venvs() { local action="${1}" local venv version set \ "3.12" \ "3.11" \ "3.10" for version in "${@}"; do venv="${root}/${version}" case "${action}" in *) ;; esac done } caches remove os="${root}/os" remove "${os}" python3 -m "venv" "${os}" activate "${os}" list_venv "${os}" pip_install --upgrade "pip" pip_install "uv" list_venv "${os}" for version in "${@}"; do py="${root}/${version}" remove "${py}" export UV_PYTHON_INSTALL_DIR="${py}/cpypy" echo "→ install python ${version}" uv_python "${py}" "${version}" echo "→ create venv ${version}" uv_venv "${py}" "${version}" unset UV_PYTHON_INSTALL_DIR done deactivate for version in "${@}"; do py="${root}/${version}" activate "${py}" list_venv "${py}" pip_install "uv" list_venv "${py}" deactivate done for version in "${@}"; do py="${root}/${version}" activate "${py}" uv_install for module in "rwx"; do ln --symbolic \ "/rwx/rwx/${module}" \ "${py}/lib/python${version}/site-packages/${module}" done list_venv "${py}" deactivate done caches list_venv