def METHOD_NAME(
    packages_source_type: str,
    packages_source: str,
    package_builder: Union[
        Type[LinuxAIOPackagesBuilder], Type[LinuxNonAIOPackageBuilder]
    ],
    package_type: str,
    stable_packages_version: str,
    output_dir: pl.Path,
):
    output_dir.mkdir(parents=True, exist_ok=True)
    packages_repo_root = output_dir / "packages_repo_root"
    packages_repo_root.mkdir()
    if packages_source_type == "repo-tarball":
        # Extract repo directory from tarball.
        with tarfile.open(packages_source) as tf:
            tf.extractall(packages_repo_root)
    elif packages_source_type == "dir":
        if packages_source is None:
            # Build packages now.
            builder = package_builder()
            builder.build(
                package_type=package_type,
            )
            packages_dir = builder.result_dir / package_type
        else:
            packages_dir = pl.Path(packages_source)
        all_packages_dir = output_dir / "all_packages"
        all_packages_dir.mkdir(parents=True)
        shutil.copytree(packages_dir, all_packages_dir, dirs_exist_ok=True)
        download_stable_packages(
            package_type=package_type,
            packages_version=stable_packages_version,
            output_dir=all_packages_dir,
        )
        # Build mock repo from packages.
        if package_type == "deb":
            repo_type = "apt"
        elif package_type == "rpm":
            repo_type = "yum"
        else:
            raise Exception(f"Unknown package type: {package_type}")
        build_repo(
            repo_type=repo_type,
            packages_dir=all_packages_dir,
            output_dir=packages_repo_root,
        )
    return packages_repo_root