Refactor pkgmgr self-install handling, add pip-enabled Python env to flake, and fix Nix/pip integration
- Rename requirements.txt to _requirements.txt to avoid unintended self-install via PythonInstaller. - Update flake.nix to provide Python with pip in both devShell and runtime closure. - Generate a wrapper for pkgmgr that uses the pip-enabled interpreter. - Adjust NixFlakeInstaller to correctly handle old profile removal and install outputs. - Update run_command to support string commands and allow_failure. - Improve integration test by adding nix profile cleanup and debugging output. Reference: https://chatgpt.com/share/69345df2-a960-800f-8395-92a7c3a6629f
This commit is contained in:
@@ -1,43 +1,71 @@
|
||||
"""
|
||||
Integration test: install all configured repositories using
|
||||
--clone-mode shallow (HTTPS shallow clone) and --no-verification.
|
||||
|
||||
This test is intended to be run inside the Docker container where:
|
||||
- network access is available,
|
||||
- the config/config.yaml is present,
|
||||
- and it is safe to perform real git operations.
|
||||
|
||||
It passes if the command completes without raising an exception.
|
||||
"""
|
||||
|
||||
import runpy
|
||||
import sys
|
||||
import unittest
|
||||
import subprocess
|
||||
|
||||
|
||||
class TestIntegrationInstallAllShallow(unittest.TestCase):
|
||||
def test_install_pkgmgr_self_install(self):
|
||||
"""
|
||||
Run: pkgmgr install --all --clone-mode shallow --no-verification
|
||||
def nix_profile_list_debug(label: str) -> None:
|
||||
"""
|
||||
Print `nix profile list` for debugging inside the test container.
|
||||
Never fails the test.
|
||||
"""
|
||||
print(f"\n--- NIX PROFILE LIST ({label}) ---")
|
||||
proc = subprocess.run(
|
||||
["nix", "profile", "list"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
stdout = proc.stdout.strip()
|
||||
stderr = proc.stderr.strip()
|
||||
|
||||
if stdout:
|
||||
print(stdout)
|
||||
if stderr:
|
||||
print("stderr:", stderr)
|
||||
print("--- END ---\n")
|
||||
|
||||
|
||||
def remove_pkgmgr_from_nix_profile() -> None:
|
||||
"""
|
||||
Best-effort cleanup before running the integration test.
|
||||
|
||||
We *do not* try to parse profile indices here, because modern `nix profile list`
|
||||
prints a descriptive format without an index column inside the container.
|
||||
|
||||
Instead, we directly try to remove possible names:
|
||||
- 'pkgmgr' (the actual name shown in `nix profile list`)
|
||||
- 'package-manager' (the name mentioned in Nix's own error hints)
|
||||
"""
|
||||
for spec in ("pkgmgr", "package-manager"):
|
||||
subprocess.run(
|
||||
["nix", "profile", "remove", spec],
|
||||
check=False, # never fail on cleanup
|
||||
)
|
||||
|
||||
|
||||
class TestIntegrationInstalPKGMGRShallow(unittest.TestCase):
|
||||
def test_install_pkgmgr_self_install(self) -> None:
|
||||
# Debug before cleanup
|
||||
nix_profile_list_debug("BEFORE CLEANUP")
|
||||
|
||||
# Cleanup: aggressively try to drop any pkgmgr/profile entries
|
||||
remove_pkgmgr_from_nix_profile()
|
||||
|
||||
# Debug after cleanup
|
||||
nix_profile_list_debug("AFTER CLEANUP")
|
||||
|
||||
This will perform real installations/clones inside the container.
|
||||
The test succeeds if no exception is raised.
|
||||
"""
|
||||
original_argv = sys.argv
|
||||
try:
|
||||
sys.argv = [
|
||||
"pkgmgr",
|
||||
"python",
|
||||
"install",
|
||||
"pkgmgr",
|
||||
"--clone-mode",
|
||||
"shallow",
|
||||
"--no-verification",
|
||||
]
|
||||
|
||||
# Execute main.py as if it was called from CLI.
|
||||
# This will run the full install pipeline inside the container.
|
||||
runpy.run_module("main", run_name="__main__")
|
||||
|
||||
finally:
|
||||
sys.argv = original_argv
|
||||
|
||||
|
||||
Reference in New Issue
Block a user