Added requirements.yml interpretation and auto cloning in install

This commit is contained in:
Kevin Veen-Birkenbach
2025-03-13 20:19:12 +01:00
parent ee6fef8073
commit 7d3b05aa02

View File

@@ -1,6 +1,7 @@
import os
import subprocess
import sys
import yaml
from pkgmgr.get_repo_identifier import get_repo_identifier
from pkgmgr.get_repo_dir import get_repo_dir
from pkgmgr.create_ink import create_ink
@@ -9,16 +10,20 @@ from pkgmgr.verify import verify_repository
def install_repos(selected_repos, repositories_base_dir, bin_dir, all_repos, no_verification, preview=False, quiet=False):
"""
Install repositories by creating symbolic links and running setup commands.
Verifies repository state using verify_repository in local mode.
Install repositories by creating symbolic links, running setup commands, and
installing additional packages if a requirements.yml file is found.
"""
for repo in selected_repos:
repo_identifier = get_repo_identifier(repo, all_repos)
repo_dir = get_repo_dir(repositories_base_dir, repo)
# If the repository directory does not exist, clone it automatically.
if not os.path.exists(repo_dir):
print(f"Repository directory '{repo_dir}' does not exist. Clone it first.")
continue
print(f"Repository directory '{repo_dir}' does not exist. Cloning it now...")
clone_repos([repo], repositories_base_dir, all_repos, preview, no_verification)
if not os.path.exists(repo_dir):
print(f"Cloning failed for repository {repo_identifier}. Skipping installation.")
continue
verified_info = repo.get("verified")
verified_ok, errors, commit_hash, signing_key = verify_repository(repo, repo_dir, mode="local", no_verification=no_verification)
@@ -32,9 +37,44 @@ def install_repos(selected_repos, repositories_base_dir, bin_dir, all_repos, no_
print(f"Skipping installation for {repo_identifier}.")
continue
# Create the symlink using the create_ink function.
# Create the symlink using create_ink.
create_ink(repo, repositories_base_dir, bin_dir, all_repos, quiet=quiet, preview=preview)
setup_cmd = repo.get("setup")
if setup_cmd:
run_command(setup_cmd, cwd=repo_dir, preview=preview)
# Check if a requirements.yml file exists and install additional packages.
req_file = os.path.join(repo_dir, "requirements.yml")
if os.path.exists(req_file):
try:
with open(req_file, "r") as f:
requirements = yaml.safe_load(f)
except Exception as e:
print(f"Error loading requirements.yml in {repo_identifier}: {e}")
continue # Skip to next repository if error occurs
if requirements:
# Install pacman packages if defined.
if "pacman" in requirements:
pacman_packages = requirements["pacman"]
if pacman_packages:
cmd = "sudo pacman -S " + " ".join(pacman_packages)
run_command(cmd, preview=preview)
# Install yay packages if defined.
if "yay" in requirements:
yay_packages = requirements["yay"]
if yay_packages:
cmd = "yay -S " + " ".join(yay_packages)
run_command(cmd, preview=preview)
# Install pkgmgr packages if defined.
if "pkgmgr" in requirements:
pkgmgr_packages = requirements["pkgmgr"]
if pkgmgr_packages:
cmd = "pkgmgr install " + " ".join(pkgmgr_packages)
run_command(cmd, preview=preview)
# Install pip packages if defined.
if "pip" in requirements:
pip_packages = requirements["pip"]
if pip_packages:
cmd = "python3 -m pip install " + " ".join(pip_packages)
run_command(cmd, preview=preview)