References: - Current ChatGPT conversation: https://chatgpt.com/share/6935d6d7-0ae4-800f-988a-44a50c17ba48 - Extended discussion: https://chatgpt.com/share/6935d734-fd84-800f-9755-290902b8cee8 Summary: This commit performs a major cleanup and modernization of the installation pipeline: 1. Introduced a new capability-detection subsystem: - Capabilities (python-runtime, make-install, nix-flake) are detected per installer/layer. - Installers run only when they add new capabilities. - Prevents duplicated work such as Python installers running when Nix already provides the runtime. 2. Removed deprecated pkgmgr.yml manifest installer: - Dependency resolution is now delegated entirely to real package managers (Nix, pip, make, distro build tools). - Simplifies layering and avoids unnecessary recursion. 3. Reworked OS-specific installers: - Arch PKGBUILD now uses 'makepkg --syncdeps --cleanbuild --install --noconfirm'. - Debian installer now builds proper .deb packages via dpkg-buildpackage + installs them. - RPM installer now builds packages using rpmbuild and installs them via rpm. 4. Switched from remote GitHub flakes to local-flake execution: - Wrapper now executes: nix run /usr/lib/package-manager#pkgmgr - Avoids lock-file write attempts and improves reliability in CI. 5. Added bash -i based integration test: - Correctly sources ~/.bashrc and evaluates alias + venv activation. - ‘pkgmgr --help’ is now printed for debugging without failing tests. 6. Updated unit tests across all installers: - Removed references to manifest installer. - Adjusted expectations for new behaviors (makepkg, dpkg-buildpackage, rpmbuild). - Added capability subsystem tests. 7. Improved flake.nix packaging logic: - The entire project source tree is copied into the runtime closure. - pkgmgr wrapper now executes runpy inside the packaged directory. Together, these changes create a predictable, layered, capability-driven installer pipeline with consistent behavior across Arch, Debian, RPM, Nix, and Python layers.
69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Installer for Python projects based on pyproject.toml.
|
|
|
|
Strategy:
|
|
- Determine a pip command in this order:
|
|
1. $PKGMGR_PIP (explicit override, e.g. ~/.venvs/pkgmgr/bin/pip)
|
|
2. sys.executable -m pip (current interpreter)
|
|
3. "pip" from PATH as last resort
|
|
- If pyproject.toml exists: pip install .
|
|
|
|
All installation failures are treated as fatal errors (SystemExit).
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
from pkgmgr.installers.base import BaseInstaller
|
|
from pkgmgr.run_command import run_command
|
|
|
|
|
|
class PythonInstaller(BaseInstaller):
|
|
"""Install Python projects and dependencies via pip."""
|
|
|
|
# Logical layer name, used by capability matchers.
|
|
layer = "python"
|
|
|
|
def supports(self, ctx) -> bool:
|
|
"""
|
|
Return True if this installer should handle the given repository.
|
|
|
|
Only pyproject.toml is supported as the single source of truth
|
|
for Python dependencies and packaging metadata.
|
|
"""
|
|
repo_dir = ctx.repo_dir
|
|
return os.path.exists(os.path.join(repo_dir, "pyproject.toml"))
|
|
|
|
def _pip_cmd(self) -> str:
|
|
"""
|
|
Resolve the pip command to use.
|
|
"""
|
|
explicit = os.environ.get("PKGMGR_PIP", "").strip()
|
|
if explicit:
|
|
return explicit
|
|
|
|
if sys.executable:
|
|
return f"{sys.executable} -m pip"
|
|
|
|
return "pip"
|
|
|
|
def run(self, ctx) -> None:
|
|
"""
|
|
Install Python project defined via pyproject.toml.
|
|
|
|
Any pip failure is propagated as SystemExit.
|
|
"""
|
|
pip_cmd = self._pip_cmd()
|
|
|
|
pyproject = os.path.join(ctx.repo_dir, "pyproject.toml")
|
|
if os.path.exists(pyproject):
|
|
print(
|
|
f"pyproject.toml found in {ctx.identifier}, "
|
|
f"installing Python project..."
|
|
)
|
|
cmd = f"{pip_cmd} install ."
|
|
run_command(cmd, cwd=ctx.repo_dir, preview=ctx.preview)
|