Skip to content

Commit

Permalink
Break out python setup to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
fortes committed Jan 29, 2024
1 parent 0e79e07 commit 8eb51c5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 40 deletions.
43 changes: 43 additions & 0 deletions scripts/install_python_packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
# Install python pipx / venv packages
#
# Usage: install_python_packages

# Make sure to load `command_exists` helper as well as local paths
# shellcheck source=../stowed-files/bash/.profile
. "$HOME/dotfiles/stowed-files/bash/.profile"

install_python_packages() {
declare -r venv_path="$HOME/.local/venv"

if ! command_exists pipx; then
>&2 echo "⨯ pipx not installed!"
exit 1
fi

echo "Installing global pipx packages …"
# `--quiet` added to `pipx` in late 2023, waiting for version bump
# in Debian stable
grep -v "^#" "$HOME/dotfiles/scripts/pipx-packages" | \
xargs --no-run-if-empty -L 1 pipx install --force
echo "Pipx packages installed!"

if [[ ! -d "${venv_path}" ]]; then
echo "Creating default venv …"
python3 -m venv "${venv_path}"
echo "Default venv created!"
fi

# shellcheck source=/dev/null
. "${venv_path}/bin/activate"

echo "Installing venv libraries …"
grep -v "^#" "$HOME/dotfiles/scripts/python-libraries" | \
xargs --no-run-if-empty \
"${venv_path}/bin/python" -m pip install --quiet --upgrade
echo "venv libraries installed!"
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
install_python_packages "${@}"
fi
43 changes: 3 additions & 40 deletions scripts/setup_machine
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Make your machine usable
#
# Usage: setup_machine [--apt-only] [--node-only] [--python-only]
# Usage: setup_machine [--apt-only]

set -euo pipefail
IFS=$'\n\t'
Expand All @@ -12,7 +12,7 @@ export DEBIAN_FRONTEND=noninteractive
has_updated=""

usage() {
echo "Usage: setup_machine [--apt-only] [--node-only] [--python-only]"
echo "Usage: setup_machine [--apt-only]"
}

# Avoid running multiple times
Expand Down Expand Up @@ -72,26 +72,6 @@ install_apt_packages() {
echo "Apt packages installed"
}

install_python_packages() {
declare -r venv_path="$HOME/.local/venv"

echo "Installing global python packages"
grep -v "^#" "$HOME/dotfiles/scripts/pipx-packages" | xargs --no-run-if-empty -L 1 pipx install --force
echo "Python packages installed"

if [[ ! -d "${venv_path}" ]]; then
echo "Creating default venv"
python3 -m venv "${venv_path}"
fi

# shellcheck source=/dev/null
. "${venv_path}/bin/activate"

echo "Installing venv libraries"
grep -v "^#" "$HOME/dotfiles/scripts/python-libraries" | xargs --no-run-if-empty "${venv_path}/bin/python" -m pip install --quiet --upgrade
echo "venv libraries installed"
}

is_package_installed() {
if dpkg-query -l "$1" | grep -q "^ii"; then
return 0
Expand Down Expand Up @@ -257,21 +237,13 @@ main() {
declare -r local_profile_path="$HOME/.profile.local"

declare apt_only=''
declare node_only=''
declare python_only=''

# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--apt-only)
apt_only=1
;;
--node-only)
node_only=1
;;
--python-only)
python_only=1
;;
--help)
usage
exit 0
Expand All @@ -288,12 +260,6 @@ main() {
if [[ -n "${apt_only}" ]]; then
install_apt_packages
exit 0
elif [[ -n "${node_only}" ]]; then
install_node_packages
exit 0
elif [[ -n "${python_only}" ]]; then
install_python_packages
exit 0
fi

check_prerequisites
Expand Down Expand Up @@ -325,7 +291,6 @@ main() {
# Misc system configs
increase_max_watchers
pushd "${dotfiles_path}" > /dev/null
# shellcheck source=./lock_local_files
"${dotfiles_path}/scripts/lock_local_files"
popd > /dev/null
set_default_applications
Expand All @@ -334,11 +299,9 @@ main() {
setup_locale

# Non-apt package managers
# shellcheck source=./install_node_packages
"${dotfiles_path}/scripts/install_node_packages"
install_python_packages
"${dotfiles_path}/scripts/install_python_packages"

# shellcheck source=./generate_completions
"${dotfiles_path}/scripts/generate_completions"

echo "Setup complete!"
Expand Down

0 comments on commit 8eb51c5

Please sign in to comment.