Refactor pkgmgr into modular installer pipeline with Nix flake support, PKGBUILD build workflow, local Nix cache, and full test suite restructuring.

See conversation: https://chatgpt.com/share/69332519-7ff4-800f-bc21-7fcd24a66c10
This commit is contained in:
Kevin Veen-Birkenbach
2025-12-05 19:32:42 +01:00
parent 341ec1179e
commit f5475d86e2
35 changed files with 1684 additions and 524 deletions

View File

@@ -1,31 +1,53 @@
.PHONY: install setup uninstall aur_builder_setup
.PHONY: install setup uninstall aur_builder_setup test
# Local Nix cache directories in the repo
NIX_STORE_DIR := .nix/store
NIX_CACHE_DIR := .nix/cache
setup: install
@python3 main.py install
@echo "Running pkgmgr setup via main.py..."
@if [ -x "$$HOME/.venvs/pkgmgr/bin/python" ]; then \
echo "Using virtualenv Python at $$HOME/.venvs/pkgmgr/bin/python"; \
"$$HOME/.venvs/pkgmgr/bin/python" main.py install; \
else \
echo "Virtualenv not found, falling back to system python3"; \
python3 main.py install; \
fi
test:
@echo "Ensuring local Nix cache directories exist..."
@mkdir -p "$(NIX_STORE_DIR)" "$(NIX_CACHE_DIR)"
@echo "Building test image 'package-manager-test'..."
docker build -t package-manager-test .
docker run --rm --entrypoint python package-manager-test -m unittest discover -s tests -p "test_*.py"
@echo "Running tests inside Nix devShell with local cache..."
docker run --rm \
-v "$$(pwd)/$(NIX_STORE_DIR):/nix" \
-v "$$(pwd)/$(NIX_CACHE_DIR):/root/.cache/nix" \
--workdir /src \
--entrypoint nix \
package-manager-test \
develop .#default --no-write-lock-file -c \
python -m unittest discover -s tests -p "test_*.py"
install:
@echo "Making 'main.py' executable..."
@chmod +x main.py
@echo "Checking if global user virtual environment exists..."
@mkdir -p ~/.venvs
@if [ ! -d ~/.venvs/pkgmgr ]; then \
echo "Creating global venv at ~/.venvs/pkgmgr..."; \
python3 -m venv ~/.venvs/pkgmgr; \
@mkdir -p "$$HOME/.venvs"
@if [ ! -d "$$HOME/.venvs/pkgmgr" ]; then \
echo "Creating global venv at $$HOME/.venvs/pkgmgr..."; \
python3 -m venv "$$HOME/.venvs/pkgmgr"; \
fi
@echo "Installing required Python packages into ~/.venvs/pkgmgr..."
@~/.venvs/pkgmgr/bin/python -m ensurepip --upgrade
@~/.venvs/pkgmgr/bin/pip install --upgrade pip setuptools wheel
@~/.venvs/pkgmgr/bin/pip install -r requirements.txt
@echo "Ensuring ~/.bashrc and ~/.zshrc exist..."
@touch ~/.bashrc ~/.zshrc
@echo "Ensuring automatic activation of ~/.venvs/pkgmgr for this user..."
@for rc in ~/.bashrc ~/.zshrc; do \
rc_line='if [ -d "$${HOME}/.venvs/pkgmgr" ]; then . "$${HOME}/.venvs/pkgmgr/bin/activate"; echo "Global Python virtual environment '\''~/.venvs/pkgmgr'\'' activated."; fi'; \
grep -qxF "$${rc_line}" $$rc || echo "$${rc_line}" >> $$rc; \
@echo "Installing required Python packages into $$HOME/.venvs/pkgmgr..."
@$$HOME/.venvs/pkgmgr/bin/python -m ensurepip --upgrade
@$$HOME/.venvs/pkgmgr/bin/pip install --upgrade pip setuptools wheel
@$$HOME/.venvs/pkgmgr/bin/pip install -r requirements.txt
@echo "Ensuring $$HOME/.bashrc and $$HOME/.zshrc exist..."
@touch "$$HOME/.bashrc" "$$HOME/.zshrc"
@echo "Ensuring automatic activation of $$HOME/.venvs/pkgmgr for this user..."
@for rc in "$$HOME/.bashrc" "$$HOME/.zshrc"; do \
rc_line='if [ -d "$${HOME}/.venvs/pkgmgr" ]; then . "$${HOME}/.venvs/pkgmgr/bin/activate"; if [ -n "$${PS1:-}" ]; then echo "Global Python virtual environment '\''~/.venvs/pkgmgr'\'' activated."; fi; fi'; \
grep -qxF "$${rc_line}" "$$rc" || echo "$${rc_line}" >> "$$rc"; \
done
@echo "Arch/Manjaro detection and optional AUR setup..."
@if command -v pacman >/dev/null 2>&1; then \
@@ -56,9 +78,9 @@ aur_builder_setup:
uninstall:
@echo "Removing global user virtual environment if it exists..."
@rm -rf ~/.venvs/pkgmgr
@echo "Cleaning up ~/.bashrc and ~/.zshrc entries..."
@for rc in ~/.bashrc ~/.zshrc; do \
sed -i '/\.venvs\/pkgmgr\/bin\/activate"; echo "Global Python virtual environment '\''~\/\.venvs\/pkgmgr'\'' activated."; fi/d' $$rc; \
@rm -rf "$$HOME/.venvs/pkgmgr"
@echo "Cleaning up $$HOME/.bashrc and $$HOME/.zshrc entries..."
@for rc in "$$HOME/.bashrc" "$$HOME/.zshrc"; do \
sed -i '/\.venvs\/pkgmgr\/bin\/activate"; if \[ -n "\$${PS1:-}" \]; then echo "Global Python virtual environment '\''~\/\.venvs\/pkgmgr'\'' activated."; fi; fi/d' "$$rc"; \
done
@echo "Uninstallation complete. Please restart your shell (or 'exec bash' or 'exec zsh') for the changes to fully apply."