mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-12 20:52:35 +00:00
refactor(python): migrate pip to uv and inline packages
Replace pip install --user with uv tool install for CLI tools (ansible) and uv pip install --system for libraries (libtmux, pynvim). Drop pipx and pipenv (uv replaces both), delete the external config/asdf/python-packages file, and rename the script to install-python-packages to reflect the broader scope.
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
ansible
|
|
||||||
pipenv
|
|
||||||
neovim
|
|
||||||
libtmux
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
# install-pip-packages
|
|
||||||
|
|
||||||
Installs Python packages from `config/pip/packages` using `pip`.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scripts/install-pip-packages.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
The script uses `pip install --user` for each package entry.
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# @description Install python/pip packages.
|
|
||||||
#
|
|
||||||
# shellcheck source=shared.sh
|
|
||||||
source "${DOTFILES}/config/shared.sh"
|
|
||||||
|
|
||||||
# Enable verbosity with VERBOSE=1
|
|
||||||
VERBOSE="${VERBOSE:-0}"
|
|
||||||
|
|
||||||
msgr run "Starting to install pip packages"
|
|
||||||
|
|
||||||
if ! command -v python3 &> /dev/null; then
|
|
||||||
msgr err "Could not find python3, something really weird is going on."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
msgr nested "Upgrading pip"
|
|
||||||
python3 -m pip install --user --upgrade pip
|
|
||||||
|
|
||||||
packages=(
|
|
||||||
"pipx"
|
|
||||||
"libtmux"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Function to install pip packages
|
|
||||||
install_packages()
|
|
||||||
{
|
|
||||||
for pkg in "${packages[@]}"; do
|
|
||||||
# Trim spaces
|
|
||||||
pkg=${pkg// /}
|
|
||||||
# Skip comments
|
|
||||||
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
|
|
||||||
|
|
||||||
msgr nested "Installing pip package: $pkg"
|
|
||||||
python3 -m pip install --user --upgrade "$pkg"
|
|
||||||
echo ""
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
install_packages
|
|
||||||
msgr run_done "Run pip package installations"
|
|
||||||
18
scripts/install-python-packages.md
Normal file
18
scripts/install-python-packages.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# install-python-packages
|
||||||
|
|
||||||
|
Install Python packages defined in the script using `uv`.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/install-python-packages.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## What it does
|
||||||
|
|
||||||
|
1. Checks that `uv` is available; if missing, installs it via the official installer.
|
||||||
|
2. Installs each CLI tool from the inline `tools` array using `uv tool install --upgrade`.
|
||||||
|
3. Installs each library from the inline `libraries` array using `uv pip install --system --upgrade`.
|
||||||
|
4. Upgrades all uv-managed tools with `uv tool upgrade --all`.
|
||||||
|
|
||||||
|
To add or remove packages, edit the `tools` or `libraries` arrays in `scripts/install-python-packages.sh`.
|
||||||
77
scripts/install-python-packages.sh
Executable file
77
scripts/install-python-packages.sh
Executable file
@@ -0,0 +1,77 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# @description Install Python packages using uv.
|
||||||
|
#
|
||||||
|
# shellcheck source=shared.sh
|
||||||
|
source "$DOTFILES/config/shared.sh"
|
||||||
|
|
||||||
|
# Enable verbosity with VERBOSE=1
|
||||||
|
VERBOSE="${VERBOSE:-0}"
|
||||||
|
|
||||||
|
msgr run "Starting to install Python packages"
|
||||||
|
|
||||||
|
# Ensure uv is available
|
||||||
|
if ! command -v uv &> /dev/null; then
|
||||||
|
msgr nested "uv not found, installing via official installer"
|
||||||
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||||
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# CLI tools — installed isolated with `uv tool install`
|
||||||
|
tools=(
|
||||||
|
ansible # IT automation and configuration management
|
||||||
|
)
|
||||||
|
|
||||||
|
# Library packages — installed into system Python with `uv pip install --system`
|
||||||
|
libraries=(
|
||||||
|
libtmux # Python API for tmux
|
||||||
|
pynvim # Neovim Python client
|
||||||
|
)
|
||||||
|
|
||||||
|
# Function to install CLI tools via uv tool install
|
||||||
|
install_tools()
|
||||||
|
{
|
||||||
|
msgr run "Installing Python CLI tools"
|
||||||
|
for pkg in "${tools[@]}"; do
|
||||||
|
# Strip inline comments and trim whitespace
|
||||||
|
pkg="${pkg%%#*}"
|
||||||
|
pkg="${pkg// /}"
|
||||||
|
[[ -z "$pkg" ]] && continue
|
||||||
|
|
||||||
|
msgr nested "Installing tool: $pkg"
|
||||||
|
uv tool install --upgrade "$pkg"
|
||||||
|
echo ""
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to install library packages via uv pip install
|
||||||
|
install_libraries()
|
||||||
|
{
|
||||||
|
msgr run "Installing Python libraries"
|
||||||
|
for pkg in "${libraries[@]}"; do
|
||||||
|
# Strip inline comments and trim whitespace
|
||||||
|
pkg="${pkg%%#*}"
|
||||||
|
pkg="${pkg// /}"
|
||||||
|
[[ -z "$pkg" ]] && continue
|
||||||
|
|
||||||
|
msgr nested "Installing library: $pkg"
|
||||||
|
uv pip install --system --upgrade "$pkg"
|
||||||
|
echo ""
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to upgrade all uv-managed tools
|
||||||
|
upgrade_tools()
|
||||||
|
{
|
||||||
|
msgr run "Upgrading all uv-managed tools"
|
||||||
|
uv tool upgrade --all
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
install_tools
|
||||||
|
install_libraries
|
||||||
|
upgrade_tools
|
||||||
|
msgr yay "Python package installations complete"
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
Reference in New Issue
Block a user