diff --git a/pyproject.toml b/pyproject.toml index 52a3a57fff..146684e160 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,7 +101,7 @@ name = "dycw-utilities" readme = "README.md" requires-python = ">= 3.12" - version = "0.174.19" + version = "0.174.20" [project.entry-points.pytest11] pytest-randomly = "utilities.pytest_plugins.pytest_randomly" @@ -135,7 +135,7 @@ # bump-my-version [tool.bumpversion] allow_dirty = true - current_version = "0.174.19" + current_version = "0.174.20" [[tool.bumpversion.files]] filename = "src/utilities/__init__.py" diff --git a/src/tests/test_subprocess.py b/src/tests/test_subprocess.py index 96af63649c..272960417a 100644 --- a/src/tests/test_subprocess.py +++ b/src/tests/test_subprocess.py @@ -38,7 +38,6 @@ git_checkout_cmd, git_clone, git_clone_cmd, - git_hard_reset_cmd, maybe_parent, maybe_sudo_cmd, mkdir, @@ -240,7 +239,6 @@ def test_subs(self) -> None: class TestGitBranchCurrent: @throttle(delta=5 * MINUTE) - @mark.only def test_main(self, *, git_repo_url: str, tmp_path: Path) -> None: git_clone(git_repo_url, tmp_path) result = git_branch_current(tmp_path) @@ -249,7 +247,6 @@ def test_main(self, *, git_repo_url: str, tmp_path: Path) -> None: class TestGitCheckout: @throttle(delta=5 * MINUTE) - @mark.only def test_main(self, *, git_repo_url: str, tmp_path: Path) -> None: git_clone(git_repo_url, tmp_path) git_checkout("branch", tmp_path) @@ -284,18 +281,6 @@ def test_main(self, *, git_repo_url: str) -> None: assert result == expected -class TestGitHardResetCmd: - def test_main(self) -> None: - result = git_hard_reset_cmd() - expected = ["git", "hard-reset", "master"] - assert result == expected - - def test_branch(self) -> None: - result = git_hard_reset_cmd(branch="dev") - expected = ["git", "hard-reset", "dev"] - assert result == expected - - class TestMaybeParent: def test_main(self) -> None: result = maybe_parent("~/path") diff --git a/src/utilities/__init__.py b/src/utilities/__init__.py index a60fe75346..b992bfe185 100644 --- a/src/utilities/__init__.py +++ b/src/utilities/__init__.py @@ -1,3 +1,3 @@ from __future__ import annotations -__version__ = "0.174.19" +__version__ = "0.174.20" diff --git a/src/utilities/subprocess.py b/src/utilities/subprocess.py index 744f55cb0a..fc7618f058 100644 --- a/src/utilities/subprocess.py +++ b/src/utilities/subprocess.py @@ -49,6 +49,13 @@ ## +def apt_install(package: str, /, *, update: bool = False, sudo: bool = False) -> None: + """Install a package.""" + if update: # pragma: no cover + run(*maybe_sudo_cmd(*APT_UPDATE, sudo=sudo)) + run(*maybe_sudo_cmd(*apt_install_cmd(package), sudo=sudo)) + + def apt_install_cmd(package: str, /) -> list[str]: """Command to use 'apt' to install a package.""" return ["apt", "install", "-y", package] @@ -250,7 +257,7 @@ def git_clone( rm(path, sudo=sudo) run(*maybe_sudo_cmd(*git_clone_cmd(url, path), sudo=sudo)) if branch is not None: - run(*maybe_sudo_cmd(*git_hard_reset_cmd(branch=branch), sudo=sudo), cwd=path) + git_checkout(branch, path) def git_clone_cmd(url: str, path: PathLike, /) -> list[str]: @@ -261,15 +268,6 @@ def git_clone_cmd(url: str, path: PathLike, /) -> list[str]: ## -def git_hard_reset_cmd(*, branch: str | None = None) -> list[str]: - """Command to use 'git hard-reset' to hard reset a repository.""" - branch_use = "master" if branch is None else branch - return ["git", "hard-reset", branch_use] - - -## - - def maybe_parent(path: PathLike, /, *, parent: bool = False) -> Path: """Get the parent of a path, if required.""" path = Path(path) @@ -1207,6 +1205,7 @@ def yield_ssh_temp_dir( "RsyncCmdError", "RsyncCmdNoSourcesError", "RsyncCmdSourcesNotFoundError", + "apt_install", "apt_install_cmd", "cd_cmd", "chmod", @@ -1222,7 +1221,6 @@ def yield_ssh_temp_dir( "git_checkout_cmd", "git_clone", "git_clone_cmd", - "git_hard_reset_cmd", "maybe_parent", "maybe_sudo_cmd", "mkdir", diff --git a/uv.lock b/uv.lock index e4ad426b98..52979f784e 100644 --- a/uv.lock +++ b/uv.lock @@ -634,7 +634,7 @@ wheels = [ [[package]] name = "dycw-utilities" -version = "0.174.19" +version = "0.174.20" source = { editable = "." } dependencies = [ { name = "atomicwrites" },