venv/re.sh
2024-09-29 17:16:17 +02:00

158 lines
2.4 KiB
Bash
Executable file

#! /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
"create")
export UV_PYTHON_INSTALL_DIR="${venv}/cpypy"
echo "→ install python ${version}"
uv_python "${venv}" "${version}"
echo "→ create venv ${version}"
uv_venv "${venv}" "${version}"
unset UV_PYTHON_INSTALL_DIR
;;
*) ;;
esac
done
}
caches remove
remove "${root}"
os="${root}/os"
python3 -m "venv" "${os}"
activate "${os}"
list_venv "${os}"
pip_install --upgrade "pip"
pip_install "uv"
list_venv "${os}"
venvs create
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