Skip to content

factory

get_package_manager(*, distro, manager)

Return a unified package manager backend for the given environment.

Parameters:

Name Type Description Default
distro str

A normalized distro identifier (e.g. "ubuntu").

required
manager str

The package manager identifier (e.g. "apt").

required

Returns:

Type Description
PackageManager | None

A PackageManager instance if supported, otherwise None.

Source code in src/personal_os_setup/tasks/factory.py
def get_package_manager(*, distro: str, manager: str) -> PackageManager | None:
    """Return a unified package manager backend for the given environment.

    Args:
        distro: A normalized distro identifier (e.g. `"ubuntu"`).
        manager: The package manager identifier (e.g. `"apt"`).

    Returns:
        A `PackageManager` instance if supported, otherwise `None`.
    """
    factory = _PACKAGE_MANAGER_FACTORY_BY_DISTRO.get(distro, {}).get(manager)
    return factory() if factory else None

get_system_action_sections(*, system, distro, info, packages=None)

Build the ordered list of (section_name, [SystemAction]) tuples for this OS/distro.

Sections are assembled conditionally on system/distro: package-manager sections always come first, then zsh/chezmoi/docker (Linux+macOS), NVIDIA (Windows+Linux), and WSL/Windows-utility sections (Windows only).

Parameters:

Name Type Description Default
system str

Normalized OS family (e.g. "windows", "darwin", "linux").

required
distro str

Normalized distro identifier (e.g. "ubuntu").

required
info str | None

Extra environment info (e.g. WSL detection note), or None.

required
packages list[PackageRef] | None

The full package catalog for this distro, used to populate the "install default packages" action in the dotfiles section (packages tagged with the "core" category in packages.yaml).

None
Source code in src/personal_os_setup/tasks/factory.py
def get_system_action_sections(
    *, system: str, distro: str, info: str | None, packages: list[PackageRef] | None = None
) -> list[Section]:
    """Build the ordered list of `(section_name, [SystemAction])` tuples for this OS/distro.

    Sections are assembled conditionally on `system`/`distro`: package-manager
    sections always come first, then zsh/chezmoi/docker (Linux+macOS), NVIDIA
    (Windows+Linux), and WSL/Windows-utility sections (Windows only).

    Args:
        system: Normalized OS family (e.g. `"windows"`, `"darwin"`, `"linux"`).
        distro: Normalized distro identifier (e.g. `"ubuntu"`).
        info: Extra environment info (e.g. WSL detection note), or `None`.
        packages: The full package catalog for this distro, used to populate the
            "install default packages" action in the dotfiles section (packages
            tagged with the `"core"` category in `packages.yaml`).
    """
    sections: list[Section] = []

    # Package managers (apt, snap, brew...) - at the top for quick access.
    sections.extend(_package_manager_sections(distro))

    #################
    ## Linux & Darwin
    #################
    if system in {"darwin", "linux"}:
        sections.append(_help_section())
        sections.append(_dotfiles_section(distro, packages or []))
        sections.append(_zsh_uninstall_section(distro))

    ########
    ## Docker
    ########
    if distro in {"ubuntu", "cachyos"}:
        sections.append(_docker_section())

    ########
    ## NVIDIA
    ########
    if system in {"windows", "linux"}:
        sections.append(_nvidia_section(system=system, distro=distro))

    ########
    ## Windows
    ########
    if system == "windows":
        settings_path = _windows_terminal_settings_path()
        sections.append(_wsl_section(settings_path))
        sections.append(_advanced_wsl_section())
        sections.append(_windows_utilities_section(settings_path))

    return sections