Moved installer dir

This commit is contained in:
Kevin Veen-Birkenbach
2025-12-10 17:27:26 +01:00
parent e290043089
commit 900224ed2e
31 changed files with 132 additions and 132 deletions

View File

@@ -21,20 +21,20 @@ from pkgmgr.core.repository.identifier import get_repo_identifier
from pkgmgr.core.repository.dir import get_repo_dir from pkgmgr.core.repository.dir import get_repo_dir
from pkgmgr.core.repository.verify import verify_repository from pkgmgr.core.repository.verify import verify_repository
from pkgmgr.actions.repository.clone import clone_repos from pkgmgr.actions.repository.clone import clone_repos
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.os_packages import ( from pkgmgr.actions.install.installers.os_packages import (
ArchPkgbuildInstaller, ArchPkgbuildInstaller,
DebianControlInstaller, DebianControlInstaller,
RpmSpecInstaller, RpmSpecInstaller,
) )
from pkgmgr.actions.repository.install.installers.nix_flake import ( from pkgmgr.actions.install.installers.nix_flake import (
NixFlakeInstaller, NixFlakeInstaller,
) )
from pkgmgr.actions.repository.install.installers.python import PythonInstaller from pkgmgr.actions.install.installers.python import PythonInstaller
from pkgmgr.actions.repository.install.installers.makefile import ( from pkgmgr.actions.install.installers.makefile import (
MakefileInstaller, MakefileInstaller,
) )
from pkgmgr.actions.repository.install.pipeline import InstallationPipeline from pkgmgr.actions.install.pipeline import InstallationPipeline
Repository = Dict[str, Any] Repository = Dict[str, Any]

View File

@@ -38,7 +38,7 @@ from abc import ABC, abstractmethod
from typing import Iterable, TYPE_CHECKING from typing import Iterable, TYPE_CHECKING
if TYPE_CHECKING: if TYPE_CHECKING:
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Installer package for pkgmgr.
This exposes all installer classes so users can import them directly from
pkgmgr.actions.install.installers.
"""
from pkgmgr.actions.install.installers.base import BaseInstaller # noqa: F401
from pkgmgr.actions.install.installers.nix_flake import NixFlakeInstaller # noqa: F401
from pkgmgr.actions.install.installers.python import PythonInstaller # noqa: F401
from pkgmgr.actions.install.installers.makefile import MakefileInstaller # noqa: F401
# OS-specific installers
from pkgmgr.actions.install.installers.os_packages.arch_pkgbuild import ArchPkgbuildInstaller # noqa: F401
from pkgmgr.actions.install.installers.os_packages.debian_control import DebianControlInstaller # noqa: F401
from pkgmgr.actions.install.installers.os_packages.rpm_spec import RpmSpecInstaller # noqa: F401

View File

@@ -8,8 +8,8 @@ Base interface for all installer components in the pkgmgr installation pipeline.
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Set from typing import Set
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.capabilities import CAPABILITY_MATCHERS from pkgmgr.actions.install.capabilities import CAPABILITY_MATCHERS
class BaseInstaller(ABC): class BaseInstaller(ABC):

View File

@@ -3,8 +3,8 @@ from __future__ import annotations
import os import os
import re import re
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.base import BaseInstaller from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.core.command.run import run_command from pkgmgr.core.command.run import run_command

View File

@@ -29,12 +29,12 @@ import os
import shutil import shutil
from typing import TYPE_CHECKING, List, Tuple from typing import TYPE_CHECKING, List, Tuple
from pkgmgr.actions.repository.install.installers.base import BaseInstaller from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.core.command.run import run_command from pkgmgr.core.command.run import run_command
if TYPE_CHECKING: if TYPE_CHECKING:
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install import InstallContext from pkgmgr.actions.install import InstallContext
class NixFlakeInstaller(BaseInstaller): class NixFlakeInstaller(BaseInstaller):

View File

@@ -3,8 +3,8 @@
import os import os
import shutil import shutil
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.base import BaseInstaller from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.core.command.run import run_command from pkgmgr.core.command.run import run_command

View File

@@ -19,8 +19,8 @@ import os
import shutil import shutil
from typing import List from typing import List
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.base import BaseInstaller from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.core.command.run import run_command from pkgmgr.core.command.run import run_command

View File

@@ -21,8 +21,8 @@ import shutil
import tarfile import tarfile
from typing import List, Optional, Tuple from typing import List, Optional, Tuple
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.base import BaseInstaller from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.core.command.run import run_command from pkgmgr.core.command.run import run_command

View File

@@ -31,12 +31,12 @@ import sys
import subprocess import subprocess
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from pkgmgr.actions.repository.install.installers.base import BaseInstaller from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.core.command.run import run_command from pkgmgr.core.command.run import run_command
if TYPE_CHECKING: if TYPE_CHECKING:
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install import InstallContext from pkgmgr.actions.install import InstallContext
class PythonInstaller(BaseInstaller): class PythonInstaller(BaseInstaller):

View File

@@ -23,9 +23,9 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional, Sequence, Set from typing import Optional, Sequence, Set
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.base import BaseInstaller from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.actions.repository.install.layers import ( from pkgmgr.actions.install.layers import (
CliLayer, CliLayer,
classify_command_layer, classify_command_layer,
layer_priority, layer_priority,

View File

@@ -1,19 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Installer package for pkgmgr.
This exposes all installer classes so users can import them directly from
pkgmgr.actions.repository.install.installers.
"""
from pkgmgr.actions.repository.install.installers.base import BaseInstaller # noqa: F401
from pkgmgr.actions.repository.install.installers.nix_flake import NixFlakeInstaller # noqa: F401
from pkgmgr.actions.repository.install.installers.python import PythonInstaller # noqa: F401
from pkgmgr.actions.repository.install.installers.makefile import MakefileInstaller # noqa: F401
# OS-specific installers
from pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild import ArchPkgbuildInstaller # noqa: F401
from pkgmgr.actions.repository.install.installers.os_packages.debian_control import DebianControlInstaller # noqa: F401
from pkgmgr.actions.repository.install.installers.os_packages.rpm_spec import RpmSpecInstaller # noqa: F401

View File

@@ -2,7 +2,7 @@ import sys
import shutil import shutil
from pkgmgr.actions.repository.pull import pull_with_verification from pkgmgr.actions.repository.pull import pull_with_verification
from pkgmgr.actions.repository.install import install_repos from pkgmgr.actions.install import install_repos
def update_repos( def update_repos(

View File

@@ -7,7 +7,7 @@ import sys
from typing import Any, Dict, List from typing import Any, Dict, List
from pkgmgr.cli.context import CLIContext from pkgmgr.cli.context import CLIContext
from pkgmgr.actions.repository.install import install_repos from pkgmgr.actions.install import install_repos
from pkgmgr.actions.repository.deinstall import deinstall_repos from pkgmgr.actions.repository.deinstall import deinstall_repos
from pkgmgr.actions.repository.delete import delete_repos from pkgmgr.actions.repository.delete import delete_repos
from pkgmgr.actions.repository.update import update_repos from pkgmgr.actions.repository.update import update_repos

View File

@@ -6,9 +6,9 @@ import tempfile
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
import pkgmgr.actions.repository.install as install_module import pkgmgr.actions.install as install_module
from pkgmgr.actions.repository.install import install_repos from pkgmgr.actions.install import install_repos
from pkgmgr.actions.repository.install.installers.base import BaseInstaller from pkgmgr.actions.install.installers.base import BaseInstaller
class DummyInstaller(BaseInstaller): class DummyInstaller(BaseInstaller):
@@ -27,10 +27,10 @@ class DummyInstaller(BaseInstaller):
class TestInstallReposIntegration(unittest.TestCase): class TestInstallReposIntegration(unittest.TestCase):
@patch("pkgmgr.actions.repository.install.verify_repository") @patch("pkgmgr.actions.install.verify_repository")
@patch("pkgmgr.actions.repository.install.clone_repos") @patch("pkgmgr.actions.install.clone_repos")
@patch("pkgmgr.actions.repository.install.get_repo_dir") @patch("pkgmgr.actions.install.get_repo_dir")
@patch("pkgmgr.actions.repository.install.get_repo_identifier") @patch("pkgmgr.actions.install.get_repo_identifier")
def test_system_binary_vs_nix_binary( def test_system_binary_vs_nix_binary(
self, self,
mock_get_repo_identifier, mock_get_repo_identifier,
@@ -104,9 +104,9 @@ class TestInstallReposIntegration(unittest.TestCase):
# Patch resolve_command_for_repo at the *pipeline* module level, # Patch resolve_command_for_repo at the *pipeline* module level,
# because InstallationPipeline imports it there. # because InstallationPipeline imports it there.
with patch( with patch(
"pkgmgr.actions.repository.install.pipeline.resolve_command_for_repo" "pkgmgr.actions.install.pipeline.resolve_command_for_repo"
) as mock_resolve, patch( ) as mock_resolve, patch(
"pkgmgr.actions.repository.install.os.path.exists" "pkgmgr.actions.install.os.path.exists"
) as mock_exists_install: ) as mock_exists_install:
def fake_resolve(repo, repo_identifier: str, repo_dir: str): def fake_resolve(repo, repo_identifier: str, repo_dir: str):

View File

@@ -20,14 +20,14 @@ import unittest
from typing import List, Sequence, Tuple from typing import List, Sequence, Tuple
from unittest.mock import patch from unittest.mock import patch
import pkgmgr.actions.repository.install as install_mod import pkgmgr.actions.install as install_mod
from pkgmgr.actions.repository.install import install_repos from pkgmgr.actions.install import install_repos
from pkgmgr.actions.repository.install.installers.makefile import MakefileInstaller from pkgmgr.actions.install.installers.makefile import MakefileInstaller
from pkgmgr.actions.repository.install.installers.nix_flake import NixFlakeInstaller from pkgmgr.actions.install.installers.nix_flake import NixFlakeInstaller
from pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild import ( from pkgmgr.actions.install.installers.os_packages.arch_pkgbuild import (
ArchPkgbuildInstaller, ArchPkgbuildInstaller,
) )
from pkgmgr.actions.repository.install.installers.python import PythonInstaller from pkgmgr.actions.install.installers.python import PythonInstaller
InstallerSpec = Tuple[str, object] InstallerSpec = Tuple[str, object]

View File

@@ -4,8 +4,8 @@ import os
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild import ArchPkgbuildInstaller from pkgmgr.actions.install.installers.os_packages.arch_pkgbuild import ArchPkgbuildInstaller
class TestArchPkgbuildInstaller(unittest.TestCase): class TestArchPkgbuildInstaller(unittest.TestCase):
@@ -26,7 +26,7 @@ class TestArchPkgbuildInstaller(unittest.TestCase):
) )
self.installer = ArchPkgbuildInstaller() self.installer = ArchPkgbuildInstaller()
@patch("pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000) @patch("pkgmgr.actions.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000)
@patch("os.path.exists", return_value=True) @patch("os.path.exists", return_value=True)
@patch("shutil.which") @patch("shutil.which")
def test_supports_true_when_tools_and_pkgbuild_exist( def test_supports_true_when_tools_and_pkgbuild_exist(
@@ -46,7 +46,7 @@ class TestArchPkgbuildInstaller(unittest.TestCase):
self.assertIn("makepkg", calls) self.assertIn("makepkg", calls)
mock_exists.assert_called_with(os.path.join(self.ctx.repo_dir, "PKGBUILD")) mock_exists.assert_called_with(os.path.join(self.ctx.repo_dir, "PKGBUILD"))
@patch("pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=0) @patch("pkgmgr.actions.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=0)
@patch("os.path.exists", return_value=True) @patch("os.path.exists", return_value=True)
@patch("shutil.which") @patch("shutil.which")
def test_supports_false_when_running_as_root( def test_supports_false_when_running_as_root(
@@ -55,7 +55,7 @@ class TestArchPkgbuildInstaller(unittest.TestCase):
mock_which.return_value = "/usr/bin/pacman" mock_which.return_value = "/usr/bin/pacman"
self.assertFalse(self.installer.supports(self.ctx)) self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000) @patch("pkgmgr.actions.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000)
@patch("os.path.exists", return_value=False) @patch("os.path.exists", return_value=False)
@patch("shutil.which") @patch("shutil.which")
def test_supports_false_when_pkgbuild_missing( def test_supports_false_when_pkgbuild_missing(
@@ -64,8 +64,8 @@ class TestArchPkgbuildInstaller(unittest.TestCase):
mock_which.return_value = "/usr/bin/pacman" mock_which.return_value = "/usr/bin/pacman"
self.assertFalse(self.installer.supports(self.ctx)) self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild.run_command") @patch("pkgmgr.actions.install.installers.os_packages.arch_pkgbuild.run_command")
@patch("pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000) @patch("pkgmgr.actions.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000)
@patch("os.path.exists", return_value=True) @patch("os.path.exists", return_value=True)
@patch("shutil.which") @patch("shutil.which")
def test_run_builds_and_installs_with_makepkg( def test_run_builds_and_installs_with_makepkg(

View File

@@ -1,8 +1,8 @@
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.os_packages.debian_control import ( from pkgmgr.actions.install.installers.os_packages.debian_control import (
DebianControlInstaller, DebianControlInstaller,
) )
@@ -44,7 +44,7 @@ class TestDebianControlInstaller(unittest.TestCase):
self.assertFalse(self.installer.supports(self.ctx)) self.assertFalse(self.installer.supports(self.ctx))
@patch( @patch(
"pkgmgr.actions.repository.install.installers.os_packages.debian_control.run_command" "pkgmgr.actions.install.installers.os_packages.debian_control.run_command"
) )
@patch("glob.glob", return_value=["/tmp/package-manager_0.1.1_all.deb"]) @patch("glob.glob", return_value=["/tmp/package-manager_0.1.1_all.deb"])
@patch("os.path.exists", return_value=True) @patch("os.path.exists", return_value=True)

View File

@@ -1,8 +1,8 @@
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.os_packages.rpm_spec import ( from pkgmgr.actions.install.installers.os_packages.rpm_spec import (
RpmSpecInstaller, RpmSpecInstaller,
) )
@@ -57,7 +57,7 @@ class TestRpmSpecInstaller(unittest.TestCase):
self.assertFalse(self.installer.supports(self.ctx)) self.assertFalse(self.installer.supports(self.ctx))
@patch.object(RpmSpecInstaller, "_prepare_source_tarball") @patch.object(RpmSpecInstaller, "_prepare_source_tarball")
@patch("pkgmgr.actions.repository.install.installers.os_packages.rpm_spec.run_command") @patch("pkgmgr.actions.install.installers.os_packages.rpm_spec.run_command")
@patch("glob.glob") @patch("glob.glob")
@patch("shutil.which") @patch("shutil.which")
def test_run_builds_and_installs_rpms( def test_run_builds_and_installs_rpms(

View File

@@ -1,8 +1,8 @@
# tests/unit/pkgmgr/installers/test_base.py # tests/unit/pkgmgr/installers/test_base.py
import unittest import unittest
from pkgmgr.actions.repository.install.installers.base import BaseInstaller from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
class DummyInstaller(BaseInstaller): class DummyInstaller(BaseInstaller):

View File

@@ -4,8 +4,8 @@ import os
import unittest import unittest
from unittest.mock import patch, mock_open from unittest.mock import patch, mock_open
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.makefile import MakefileInstaller from pkgmgr.actions.install.installers.makefile import MakefileInstaller
class TestMakefileInstaller(unittest.TestCase): class TestMakefileInstaller(unittest.TestCase):
@@ -35,7 +35,7 @@ class TestMakefileInstaller(unittest.TestCase):
def test_supports_false_when_makefile_missing(self, mock_exists): def test_supports_false_when_makefile_missing(self, mock_exists):
self.assertFalse(self.installer.supports(self.ctx)) self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.makefile.run_command") @patch("pkgmgr.actions.install.installers.makefile.run_command")
@patch( @patch(
"builtins.open", "builtins.open",
new_callable=mock_open, new_callable=mock_open,
@@ -62,7 +62,7 @@ class TestMakefileInstaller(unittest.TestCase):
self.ctx.repo_dir, self.ctx.repo_dir,
) )
@patch("pkgmgr.actions.repository.install.installers.makefile.run_command") @patch("pkgmgr.actions.install.installers.makefile.run_command")
@patch( @patch(
"builtins.open", "builtins.open",
new_callable=mock_open, new_callable=mock_open,

View File

@@ -6,8 +6,8 @@ import unittest
from unittest import mock from unittest import mock
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.nix_flake import NixFlakeInstaller from pkgmgr.actions.install.installers.nix_flake import NixFlakeInstaller
class TestNixFlakeInstaller(unittest.TestCase): class TestNixFlakeInstaller(unittest.TestCase):
@@ -29,8 +29,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
) )
self.installer = NixFlakeInstaller() self.installer = NixFlakeInstaller()
@patch("pkgmgr.actions.repository.install.installers.nix_flake.os.path.exists") @patch("pkgmgr.actions.install.installers.nix_flake.os.path.exists")
@patch("pkgmgr.actions.repository.install.installers.nix_flake.shutil.which") @patch("pkgmgr.actions.install.installers.nix_flake.shutil.which")
def test_supports_true_when_nix_and_flake_exist( def test_supports_true_when_nix_and_flake_exist(
self, self,
mock_which: MagicMock, mock_which: MagicMock,
@@ -47,8 +47,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
os.path.join(self.ctx.repo_dir, self.installer.FLAKE_FILE) os.path.join(self.ctx.repo_dir, self.installer.FLAKE_FILE)
) )
@patch("pkgmgr.actions.repository.install.installers.nix_flake.os.path.exists") @patch("pkgmgr.actions.install.installers.nix_flake.os.path.exists")
@patch("pkgmgr.actions.repository.install.installers.nix_flake.shutil.which") @patch("pkgmgr.actions.install.installers.nix_flake.shutil.which")
def test_supports_false_when_nix_missing( def test_supports_false_when_nix_missing(
self, self,
mock_which: MagicMock, mock_which: MagicMock,
@@ -60,8 +60,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
with patch.dict(os.environ, {"PKGMGR_DISABLE_NIX_FLAKE_INSTALLER": ""}, clear=False): with patch.dict(os.environ, {"PKGMGR_DISABLE_NIX_FLAKE_INSTALLER": ""}, clear=False):
self.assertFalse(self.installer.supports(self.ctx)) self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.nix_flake.os.path.exists") @patch("pkgmgr.actions.install.installers.nix_flake.os.path.exists")
@patch("pkgmgr.actions.repository.install.installers.nix_flake.shutil.which") @patch("pkgmgr.actions.install.installers.nix_flake.shutil.which")
def test_supports_false_when_disabled_via_env( def test_supports_false_when_disabled_via_env(
self, self,
mock_which: MagicMock, mock_which: MagicMock,
@@ -77,8 +77,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
): ):
self.assertFalse(self.installer.supports(self.ctx)) self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.nix_flake.NixFlakeInstaller.supports") @patch("pkgmgr.actions.install.installers.nix_flake.NixFlakeInstaller.supports")
@patch("pkgmgr.actions.repository.install.installers.nix_flake.run_command") @patch("pkgmgr.actions.install.installers.nix_flake.run_command")
def test_run_removes_old_profile_and_installs_outputs( def test_run_removes_old_profile_and_installs_outputs(
self, self,
mock_run_command: MagicMock, mock_run_command: MagicMock,
@@ -112,8 +112,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
self.assertEqual(commands[0], remove_cmd) self.assertEqual(commands[0], remove_cmd)
@patch("pkgmgr.actions.repository.install.installers.nix_flake.shutil.which") @patch("pkgmgr.actions.install.installers.nix_flake.shutil.which")
@patch("pkgmgr.actions.repository.install.installers.nix_flake.run_command") @patch("pkgmgr.actions.install.installers.nix_flake.run_command")
def test_ensure_old_profile_removed_ignores_systemexit( def test_ensure_old_profile_removed_ignores_systemexit(
self, self,
mock_run_command: MagicMock, mock_run_command: MagicMock,

View File

@@ -2,8 +2,8 @@ import os
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.python import PythonInstaller from pkgmgr.actions.install.installers.python import PythonInstaller
class TestPythonInstaller(unittest.TestCase): class TestPythonInstaller(unittest.TestCase):
@@ -41,7 +41,7 @@ class TestPythonInstaller(unittest.TestCase):
with patch.dict(os.environ, {"IN_NIX_SHELL": ""}, clear=False): with patch.dict(os.environ, {"IN_NIX_SHELL": ""}, clear=False):
self.assertFalse(self.installer.supports(self.ctx)) self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.python.run_command") @patch("pkgmgr.actions.install.installers.python.run_command")
@patch("os.path.exists", side_effect=lambda path: path.endswith("pyproject.toml")) @patch("os.path.exists", side_effect=lambda path: path.endswith("pyproject.toml"))
def test_run_installs_project_from_pyproject(self, mock_exists, mock_run_command): def test_run_installs_project_from_pyproject(self, mock_exists, mock_run_command):
""" """

View File

@@ -4,7 +4,7 @@ import os
import unittest import unittest
from unittest.mock import patch, mock_open from unittest.mock import patch, mock_open
from pkgmgr.actions.repository.install.capabilities import ( from pkgmgr.actions.install.capabilities import (
PythonRuntimeCapability, PythonRuntimeCapability,
MakeInstallCapability, MakeInstallCapability,
NixFlakeCapability, NixFlakeCapability,
@@ -31,7 +31,7 @@ class TestCapabilitiesDetectors(unittest.TestCase):
def setUp(self): def setUp(self):
self.ctx = DummyCtx("/tmp/repo") self.ctx = DummyCtx("/tmp/repo")
@patch("pkgmgr.actions.repository.install.capabilities.os.path.exists") @patch("pkgmgr.actions.install.capabilities.os.path.exists")
def test_python_runtime_python_layer_pyproject(self, mock_exists): def test_python_runtime_python_layer_pyproject(self, mock_exists):
"""PythonRuntimeCapability: python layer is provided if pyproject.toml exists.""" """PythonRuntimeCapability: python layer is provided if pyproject.toml exists."""
cap = PythonRuntimeCapability() cap = PythonRuntimeCapability()
@@ -47,8 +47,8 @@ class TestCapabilitiesDetectors(unittest.TestCase):
self.assertFalse(cap.is_provided(self.ctx, "nix")) self.assertFalse(cap.is_provided(self.ctx, "nix"))
self.assertFalse(cap.is_provided(self.ctx, "os-packages")) self.assertFalse(cap.is_provided(self.ctx, "os-packages"))
@patch("pkgmgr.actions.repository.install.capabilities._read_text_if_exists") @patch("pkgmgr.actions.install.capabilities._read_text_if_exists")
@patch("pkgmgr.actions.repository.install.capabilities.os.path.exists") @patch("pkgmgr.actions.install.capabilities.os.path.exists")
def test_python_runtime_nix_layer_flake(self, mock_exists, mock_read): def test_python_runtime_nix_layer_flake(self, mock_exists, mock_read):
""" """
PythonRuntimeCapability: nix layer is provided if flake.nix contains PythonRuntimeCapability: nix layer is provided if flake.nix contains
@@ -65,7 +65,7 @@ class TestCapabilitiesDetectors(unittest.TestCase):
self.assertTrue(cap.applies_to_layer("nix")) self.assertTrue(cap.applies_to_layer("nix"))
self.assertTrue(cap.is_provided(self.ctx, "nix")) self.assertTrue(cap.is_provided(self.ctx, "nix"))
@patch("pkgmgr.actions.repository.install.capabilities.os.path.exists", return_value=True) @patch("pkgmgr.actions.install.capabilities.os.path.exists", return_value=True)
@patch( @patch(
"builtins.open", "builtins.open",
new_callable=mock_open, new_callable=mock_open,
@@ -78,7 +78,7 @@ class TestCapabilitiesDetectors(unittest.TestCase):
self.assertTrue(cap.applies_to_layer("makefile")) self.assertTrue(cap.applies_to_layer("makefile"))
self.assertTrue(cap.is_provided(self.ctx, "makefile")) self.assertTrue(cap.is_provided(self.ctx, "makefile"))
@patch("pkgmgr.actions.repository.install.capabilities.os.path.exists") @patch("pkgmgr.actions.install.capabilities.os.path.exists")
def test_nix_flake_capability_on_nix_layer(self, mock_exists): def test_nix_flake_capability_on_nix_layer(self, mock_exists):
"""NixFlakeCapability: nix layer is provided if flake.nix exists.""" """NixFlakeCapability: nix layer is provided if flake.nix exists."""
cap = NixFlakeCapability() cap = NixFlakeCapability()
@@ -153,7 +153,7 @@ class TestDetectCapabilities(unittest.TestCase):
}, },
) )
with patch("pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS", [dummy1, dummy2]): with patch("pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS", [dummy1, dummy2]):
caps = detect_capabilities(self.ctx, layers) caps = detect_capabilities(self.ctx, layers)
self.assertEqual( self.assertEqual(
@@ -221,7 +221,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
) )
with patch( with patch(
"pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS", "pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS",
[cap_make_install, cap_python_runtime, cap_nix_flake], [cap_make_install, cap_python_runtime, cap_nix_flake],
): ):
effective = resolve_effective_capabilities(self.ctx, layers) effective = resolve_effective_capabilities(self.ctx, layers)
@@ -258,7 +258,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
) )
with patch( with patch(
"pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS", "pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS",
[cap_python_runtime], [cap_python_runtime],
): ):
effective = resolve_effective_capabilities(self.ctx, layers) effective = resolve_effective_capabilities(self.ctx, layers)
@@ -283,7 +283,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
}, },
) )
with patch("pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS", [cap_only_make]): with patch("pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS", [cap_only_make]):
effective = resolve_effective_capabilities(self.ctx, layers) effective = resolve_effective_capabilities(self.ctx, layers)
self.assertEqual(effective["makefile"], {"make-install"}) self.assertEqual(effective["makefile"], {"make-install"})
@@ -306,7 +306,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
}, },
) )
with patch("pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS", [cap_only_nix]): with patch("pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS", [cap_only_nix]):
effective = resolve_effective_capabilities(self.ctx, layers) effective = resolve_effective_capabilities(self.ctx, layers)
self.assertEqual(effective["makefile"], set()) self.assertEqual(effective["makefile"], set())
@@ -337,7 +337,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
) )
with patch( with patch(
"pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS", "pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS",
[cap_python_runtime], [cap_python_runtime],
): ):
effective = resolve_effective_capabilities(self.ctx, layers) effective = resolve_effective_capabilities(self.ctx, layers)
@@ -359,7 +359,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
) )
with patch( with patch(
"pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS", "pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS",
[cap_dummy], [cap_dummy],
): ):
effective = resolve_effective_capabilities(self.ctx) effective = resolve_effective_capabilities(self.ctx)

View File

@@ -1,5 +1,5 @@
import unittest import unittest
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
class TestRepoContext(unittest.TestCase): class TestRepoContext(unittest.TestCase):

View File

@@ -6,7 +6,7 @@ import unittest
from typing import Any, Dict, List from typing import Any, Dict, List
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from pkgmgr.actions.repository.install import install_repos from pkgmgr.actions.install import install_repos
Repository = Dict[str, Any] Repository = Dict[str, Any]
@@ -31,12 +31,12 @@ class TestInstallReposOrchestration(unittest.TestCase):
} }
self.all_repos: List[Repository] = [self.repo1, self.repo2] self.all_repos: List[Repository] = [self.repo1, self.repo2]
@patch("pkgmgr.actions.repository.install.InstallationPipeline") @patch("pkgmgr.actions.install.InstallationPipeline")
@patch("pkgmgr.actions.repository.install.clone_repos") @patch("pkgmgr.actions.install.clone_repos")
@patch("pkgmgr.actions.repository.install.get_repo_dir") @patch("pkgmgr.actions.install.get_repo_dir")
@patch("pkgmgr.actions.repository.install.os.path.exists", return_value=True) @patch("pkgmgr.actions.install.os.path.exists", return_value=True)
@patch( @patch(
"pkgmgr.actions.repository.install.verify_repository", "pkgmgr.actions.install.verify_repository",
return_value=(True, [], "hash", "key"), return_value=(True, [], "hash", "key"),
) )
def test_install_repos_runs_pipeline_for_each_repo( def test_install_repos_runs_pipeline_for_each_repo(
@@ -79,12 +79,12 @@ class TestInstallReposOrchestration(unittest.TestCase):
pipeline_instance = mock_pipeline_cls.return_value pipeline_instance = mock_pipeline_cls.return_value
self.assertEqual(pipeline_instance.run.call_count, len(selected)) self.assertEqual(pipeline_instance.run.call_count, len(selected))
@patch("pkgmgr.actions.repository.install.InstallationPipeline") @patch("pkgmgr.actions.install.InstallationPipeline")
@patch("pkgmgr.actions.repository.install.clone_repos") @patch("pkgmgr.actions.install.clone_repos")
@patch("pkgmgr.actions.repository.install.get_repo_dir") @patch("pkgmgr.actions.install.get_repo_dir")
@patch("pkgmgr.actions.repository.install.os.path.exists", return_value=True) @patch("pkgmgr.actions.install.os.path.exists", return_value=True)
@patch( @patch(
"pkgmgr.actions.repository.install.verify_repository", "pkgmgr.actions.install.verify_repository",
return_value=(False, ["invalid signature"], None, None), return_value=(False, ["invalid signature"], None, None),
) )
@patch("builtins.input", return_value="n") @patch("builtins.input", return_value="n")

View File

@@ -4,7 +4,7 @@
import os import os
import unittest import unittest
from pkgmgr.actions.repository.install.layers import ( from pkgmgr.actions.install.layers import (
CliLayer, CliLayer,
CLI_LAYERS, CLI_LAYERS,
classify_command_layer, classify_command_layer,

View File

@@ -4,10 +4,10 @@
import unittest import unittest
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from pkgmgr.actions.repository.install.context import RepoContext from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.base import BaseInstaller from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.actions.repository.install.layers import CliLayer from pkgmgr.actions.install.layers import CliLayer
from pkgmgr.actions.repository.install.pipeline import InstallationPipeline from pkgmgr.actions.install.pipeline import InstallationPipeline
class DummyInstaller(BaseInstaller): class DummyInstaller(BaseInstaller):
@@ -61,8 +61,8 @@ def _minimal_context() -> RepoContext:
class TestInstallationPipeline(unittest.TestCase): class TestInstallationPipeline(unittest.TestCase):
@patch("pkgmgr.actions.repository.install.pipeline.create_ink") @patch("pkgmgr.actions.install.pipeline.create_ink")
@patch("pkgmgr.actions.repository.install.pipeline.resolve_command_for_repo") @patch("pkgmgr.actions.install.pipeline.resolve_command_for_repo")
def test_create_ink_called_when_command_resolved( def test_create_ink_called_when_command_resolved(
self, self,
mock_resolve_command_for_repo: MagicMock, mock_resolve_command_for_repo: MagicMock,
@@ -86,8 +86,8 @@ class TestInstallationPipeline(unittest.TestCase):
"/usr/local/bin/test-repo", "/usr/local/bin/test-repo",
) )
@patch("pkgmgr.actions.repository.install.pipeline.create_ink") @patch("pkgmgr.actions.install.pipeline.create_ink")
@patch("pkgmgr.actions.repository.install.pipeline.resolve_command_for_repo") @patch("pkgmgr.actions.install.pipeline.resolve_command_for_repo")
def test_lower_priority_installers_are_skipped_if_cli_exists( def test_lower_priority_installers_are_skipped_if_cli_exists(
self, self,
mock_resolve_command_for_repo: MagicMock, mock_resolve_command_for_repo: MagicMock,
@@ -116,8 +116,8 @@ class TestInstallationPipeline(unittest.TestCase):
) )
self.assertEqual(ctx.repo.get("command"), "/usr/bin/test-repo") self.assertEqual(ctx.repo.get("command"), "/usr/bin/test-repo")
@patch("pkgmgr.actions.repository.install.pipeline.create_ink") @patch("pkgmgr.actions.install.pipeline.create_ink")
@patch("pkgmgr.actions.repository.install.pipeline.resolve_command_for_repo") @patch("pkgmgr.actions.install.pipeline.resolve_command_for_repo")
def test_capabilities_prevent_duplicate_installers( def test_capabilities_prevent_duplicate_installers(
self, self,
mock_resolve_command_for_repo: MagicMock, mock_resolve_command_for_repo: MagicMock,