168 lines
2.5 KiB
Bash
Executable file
168 lines
2.5 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}"
|
|
echo
|
|
echo "${venv} ← ${action}"
|
|
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
|
|
;;
|
|
"init")
|
|
activate "${venv}"
|
|
pip_install "uv"
|
|
deactivate
|
|
;;
|
|
"install")
|
|
activate "${venv}"
|
|
uv_install
|
|
deactivate
|
|
;;
|
|
"link")
|
|
activate "${venv}"
|
|
for module in "rwx"; do
|
|
ln --symbolic \
|
|
"/rwx/rwx/${module}" \
|
|
"${venv}/lib/python${version}/site-packages/${module}"
|
|
done
|
|
deactivate
|
|
;;
|
|
"list")
|
|
activate "${venv}"
|
|
list_venv "${venv}"
|
|
deactivate
|
|
;;
|
|
*) ;;
|
|
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
|
|
|
|
venvs init
|
|
venvs link
|
|
venvs install
|
|
venvs list
|
|
|
|
caches list_venv
|