Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
15 changes: 0 additions & 15 deletions src/tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
git_checkout_cmd,
git_clone,
git_clone_cmd,
git_hard_reset_cmd,
maybe_parent,
maybe_sudo_cmd,
mkdir,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions src/utilities/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]:
Expand All @@ -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)
Expand Down Expand Up @@ -1207,6 +1205,7 @@ def yield_ssh_temp_dir(
"RsyncCmdError",
"RsyncCmdNoSourcesError",
"RsyncCmdSourcesNotFoundError",
"apt_install",
"apt_install_cmd",
"cd_cmd",
"chmod",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading