From 48fb2ad8e857de0dc9358bf4917d405066e8e8ba Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Fri, 27 Nov 2026 16:57:00 +0100 Subject: [PATCH 1/4] feat: let Command.copy() duplicate a command without argument copy() with no argument returns an independent command running the same binary with the same settings, without looking the binary up again. copy(other) keeps copying another command's settings into this one. --- CHANGELOG.md | 2 ++ docs/guide/reuse-and-wrap.md | 7 ++++--- src/proclet/bind.py | 2 +- src/proclet/process.py | 19 ++++++++++++++++--- tests/test_process.py | 19 +++++++++++++++++++ 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c166dcf..74d084b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Documentation site at : guides, recipes, migration guides from `sh` and plumbum, and an API reference generated from the docstrings. - Docstrings for the public type aliases (`Process`, `RedirectIn`, `RedirectOut`...). +- `Command.copy()` without argument returns an independent duplicate of the command, without + looking the binary up again. ## [0.1.1] - 2026-11-26 diff --git a/docs/guide/reuse-and-wrap.md b/docs/guide/reuse-and-wrap.md index 9ab1592..8706842 100644 --- a/docs/guide/reuse-and-wrap.md +++ b/docs/guide/reuse-and-wrap.md @@ -9,11 +9,12 @@ from pathlib import Path from proclet import Command base = Command("git").cwd(Path("repo")).timeout(30) -Command("git").copy(base).args("fetch", "--all").exec() -Command("git").copy(base).args("gc").exec() +base.copy().args("fetch", "--all").exec() +base.copy().args("gc").exec() ``` -- `copy(other)` takes every setting of `other` (args, env, cwd, redirects, timeout, exit codes, privileges, niceness, observers) while keeping its own binary. +- `copy()` returns a new command with the same binary and every setting (args, env, cwd, redirects, timeout, exit codes, privileges, niceness, observers), without looking the binary up again. Changing the copy leaves `base` untouched. +- `copy(other)` takes every setting of `other` into an existing command while keeping its own binary. ## Wrap a binary into a typed API diff --git a/src/proclet/bind.py b/src/proclet/bind.py index a106bf8..0b26e82 100644 --- a/src/proclet/bind.py +++ b/src/proclet/bind.py @@ -44,7 +44,7 @@ def _command(self, *args: str) -> Command: Returns: a new command, independent from the bind and from other operations. """ - cmd = Command(self._template.binary_path()).copy(self._template) + cmd = self._template.copy() return cmd.args(*args) if args else cmd def add_observer(self, observer: ProcessObserver) -> Self: diff --git a/src/proclet/process.py b/src/proclet/process.py index 591f819..7ef1405 100644 --- a/src/proclet/process.py +++ b/src/proclet/process.py @@ -441,16 +441,29 @@ def add_observer(self, observer: ProcessObserver) -> Self: self.__observers.append(observer) return self - def copy(self, cmd: Command) -> Self: - """Copy all parameters from another command, keeping this one's binary. + @overload + def copy(self) -> Command: ... + + @overload + def copy(self, cmd: Command, /) -> Self: ... + + def copy(self, cmd: Command | None = None) -> Command | Self: + """Duplicate this command, or copy all parameters from another one. + + Without argument, returns a new command running the same binary with the + same parameters, without looking the binary up again. With a command, + copies its parameters into this one, keeping this one's binary. Collections are copied; redirect targets and observers are shared. Args: cmd: the command to copy parameters from. Returns: - self for chaining. + a new command if no command is provided, otherwise self for chaining. """ + if cmd is None: + return Command(Path(self.__cmd_path)).copy(self) + self.__env = None if cmd.__env is None else cmd.__env.copy() self.__cwd = cmd.__cwd self.__args = cmd.__args diff --git a/tests/test_process.py b/tests/test_process.py index 0c1a4ea..d86e9d0 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -306,6 +306,25 @@ def test_copy_from_another_command(self) -> None: assert dst.group() == os.getgid() assert dst.extra_groups() == [] + def test_copy_without_argument_duplicates(self) -> None: + src = Command(PYTHON).args("hello").env({"X": "1"}).cwd(Path("sub")) + dup = src.copy() + assert dup is not src + assert dup.binary_path() == src.binary_path() + assert dup.args() == ("hello",) + assert dup.env() == {"X": "1"} + assert dup.cwd() == Path("sub") + dup.args("other").env({"Y": "2"}) + assert src.args() == ("hello",) + assert src.env() == {"X": "1"} + + def test_copy_without_argument_skips_lookup( + self, monkeypatch: pytest.MonkeyPatch + ) -> None: + src = Command(PYTHON) + monkeypatch.setenv("PATH", "") + assert src.copy().binary_path() == src.binary_path() + def test_exec_success(self) -> None: cmd = echo("hello") process = cmd.exec() From 853e339332888022e4f97ad5d031637140b6686a Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Fri, 27 Nov 2026 16:57:00 +0100 Subject: [PATCH 2/4] docs: list uv, Poetry, PDM and pipenv install commands The home page install box gets one tab per package manager, the getting started page and the README list the same commands. --- README.md | 9 ++ .../theme/components/InstallCommand.vue | 106 ++++++++++++++++-- docs/guide/getting-started.md | 12 ++ 3 files changed, 119 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c575db0..6a13a21 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,15 @@ Requires Python 3.12 or newer, on Linux, macOS or Windows. No runtime dependency pip install proclet ``` +Or with another package manager: + +```bash +uv add proclet +poetry add proclet +pdm add proclet +pipenv install proclet +``` + ```python import asyncio from io import StringIO diff --git a/docs/.vitepress/theme/components/InstallCommand.vue b/docs/.vitepress/theme/components/InstallCommand.vue index 213e8f2..5875116 100644 --- a/docs/.vitepress/theme/components/InstallCommand.vue +++ b/docs/.vitepress/theme/components/InstallCommand.vue @@ -1,13 +1,37 @@