def test_action_triggers_if_conditional_is_true(self) -> None: spy_action = SpyBuildAction() unit = BuildUnit(AlwaysRunBuildPredicate(), spy_action) unit.build() spy_action.assert_called()
def install_tmux(builder: Builder) -> None: # Create Tmux folders home_dir = os.path.expanduser("~") builder.add_unit(MakeDirectoryBuildUnit(f"{home_dir}/.tmux/")) builder.add_unit(MakeDirectoryBuildUnit(f"{home_dir}/.tmux/plugins")) # Install Tmux Plugin Manager (TPM) builder.add_unit( BuildUnit( DirectoryExistsBuildPredicate(f"{home_dir}/.tmux/plugins/tpm/"), RunShellCommandBuildAction([ "git", "clone", "https://github.com/tmux-plugins/tpm", f"{home_dir}/.tmux/plugins/tpm", ]), ), ) # Install Plugins builder.add_unit( BuildUnit( AlwaysRunBuildPredicate(), RunShellCommandBuildAction([ f"{home_dir}/.tmux/plugins/tpm/bin/install_plugins", ]), ), )
def install_vim(builder: Builder) -> None: # Create Vim folders home_dir = os.path.expanduser("~") builder.add_unit(MakeDirectoryBuildUnit(f"{home_dir}/.vim/")) for folder in ["swapfiles", "backups", "undodir"]: builder.add_unit(MakeDirectoryBuildUnit(f"{home_dir}/.vim/{folder}")) # Install VimPlug builder.add_unit( BuildUnit( FileExistsBuildPredicate(f"{home_dir}/.vim/autoload/plug.vim"), RunShellCommandBuildAction([ "curl", "-fLo", f"{home_dir}/.vim/autoload/plug.vim", "--create-dirs", "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim", ]), ), ) builder.add_unit( BuildUnit( DirectoryExistsBuildPredicate(f"{home_dir}/.vim/plugged"), RunShellCommandBuildAction([ "vim", "+PlugInstall", "+qa", ]), ), )
def test_to_str(self) -> None: spy_action = SpyBuildAction() unit = BuildUnit(AlwaysRunBuildPredicate(), spy_action) self.assertEqual( str(unit), "BuildUnit: { AlwaysRunBuildPredicate -> SpyBuildAction }" )
def install_common_dependencies(builder: Builder) -> None: """Installs common dependencies for Linux, Python, Git, etc.""" builder.add_unit(InstallSystemPackagesBuildUnit()) # Install Git Hook for pre-commit builder.add_unit( BuildUnit( FileExistsBuildPredicate(".git/hooks/pre-commit"), RunShellCommandBuildAction(["pre-commit", "install"]), ), )
def install_zsh(builder: Builder, home_dir: str) -> None: zsh_installer_path = "/tmp/zsh_installer.sh" # Download installer builder.add_unit( BuildUnit( FileExistsBuildPredicate(zsh_installer_path), RunShellCommandBuildAction([ "wget", "-O", zsh_installer_path, "https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh", ]), ), ) # Run installer builder.add_unit( BuildUnit( DirectoryExistsBuildPredicate(f"{home_dir}/.oh-my-zsh"), RunShellCommandBuildAction([ "sh", zsh_installer_path, "--unattended", "--keep-zshrc", ]), ), ) # Install powerlevel10k theme builder.add_unit( BuildUnit( DirectoryExistsBuildPredicate( f"{home_dir}/.oh-my-zsh/custom/themes/powerlevel10k"), RunShellCommandBuildAction([ "git", "clone", "--depth=1", "https://github.com/romkatv/powerlevel10k.git", f"{home_dir}/.oh-my-zsh/custom/themes/powerlevel10k", ]), ), )
def test_all_build_units_complete(self) -> None: builder = Builder(io_out=DEVNULL) spy_actions = [] for _ in range(3): spy_action = SpyBuildAction() spy_actions.append(spy_action) builder.add_unit( BuildUnit( AlwaysRunBuildPredicate(), spy_action, ), ) builder.build() for spy_action in spy_actions: spy_action.assert_called()
def create_symlinks(builder: Builder, source_dir: str, dest_dir: str) -> None: """ Crawl through the source_dir for any files that end in ".symlink" and create symlinks to them in the dest_dir """ sources = crawl_for_symlink_sources(source_dir) destinations = [ translate_symlink_to_destination(source, dest_dir) for source in sources ] for source, destination in zip(sources, destinations): builder.add_unit( BuildUnit( FileExistsBuildPredicate(destination), MakeSymlinkBuildAction(os.path.abspath(source), destination), ), )
def test_all_errors_are_thrown_at_end(self) -> None: builder = Builder(io_out=DEVNULL) num_errors = 3 for _ in range(num_errors): builder.add_unit(SaboteurBuildUnit()) spy_action = SpyBuildAction() builder.add_unit(BuildUnit( AlwaysRunBuildPredicate(), spy_action, ), ) try: builder.build() except Exception as e: self.assertEqual(len(e.args[0]), num_errors) spy_action.assert_called()