Skip to content

Commit

Permalink
feat: add install-python-pkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia committed May 24, 2023
1 parent 4d24f74 commit e59ffa5
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions chezmoi/dot_local/bin/executable_dotfiles-install-python-pkgs.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
# {{ template "scripts-library" }}

# check if --update or -u flag is set
set +u
if [[ "${1}" == "--update" ]] || [[ "${1}" == "-u" ]]; then
UPDATE=true
else
UPDATE=false
fi
set -u
log_task "Installing python packages"

# shellcheck source=/dev/null
source "${HOME}/.config/shrc/05-package-list"

ensure_path_entry "${HOME}/.local/bin"

DOTFILES_PKGS_PIP=${DOTFILES_PKGS_PIP:-()}
DOTFILES_PKGS_PIPX=${DOTFILES_PKGS_PIPX:-()}
DOTFILES_PKGS_TO_INSTALL=${DOTFILES_PKGS_TO_INSTALL:-()}

wanted_packages=()
for package in "${DOTFILES_PKGS_PIP[@]}"; do
if is_item_in_array "${package}" "${DOTFILES_PKGS_PIP[@]}"; then
wanted_packages+=("${package}")
fi
done
log_info "Wanted packages: ${wanted_packages[*]}"

{{- range .packages }}
{{- if and (hasKey . "pip") ( .pip ) }}
# installing {{ .name }}
PKG_NAME="{{ .name }}"
if is_item_in_array "${PKG_NAME}" "${wanted_packages[@]}"; then
if {{ if and (hasKey . "check_prereqs") ( .check_prereqs ) }}{{ .check_prereqs }}{{ else }}true{{ end }}; then
if [[ "${UPDATE}" == "true" ]]; then
c /usr/bin/pip3 install --user --upgrade "${PKG_NAME}"
elif {{ if and (hasKey . "check_installed") ( .check_installed ) }}{{ .check_installed }}{{ else }}false{{ end }}; then
log_info "Package ${PKG_NAME} is already installed"
else
log_task "Installing ${PKG_NAME}"
c /usr/bin/pip3 install --user --upgrade "${PKG_NAME}"
fi
else
log_error "Prerequisites for ${PKG_NAME} not met"
fi
fi
{{- end }}
{{- end }}

log_green "✅ Python packages installed successfully. ✨ 🌟 ✨"

0 comments on commit e59ffa5

Please sign in to comment.