Environment and PATH โ
Control the environment variables, working directory and binary lookup of a command.
Set the environment and PATH โ
python
from pathlib import Path
from proclet import Command, EnvCmd, PathCmd
env = (
EnvCmd.inherit(lambda key, _: key.startswith("LC_"))
.add({"PATH": PathCmd.inherit().add("/opt/tools/bin").build()})
.build()
)
Command("deploy").env(env).cwd(Path("infra")).exec()
Command("python", search_path=["/opt/python3.13/bin"]).args("--version").exec()- Without
env(...)a command inherits the current environment; once set, it gets exactly that mapping, so build onEnvCmd.inherit()to keep it. EnvCmd.inherit(predicate)keeps only the variablespredicate(key, value)accepts;EnvCmd.empty()starts from nothing.PathCmd.add(...)prepends a directory, so it takes precedence over the inheritedPATH.search_pathlooks the binary up in the given directories instead ofPATH.