Skip to content

Run

run

run(
    command: str | list[str], cluster: str
) -> CompletedProcess[str]

Runs a command in the synced project on a potentially remote cluster.

Similar in spirit to uv run, but runs a command in the synced project on a potentially remote cluster. - Idea is that this could maybe be a building block for other commands.

Parameters:

Name Type Description Default
command str | list[str]

The command to run, as a string or list of strings.

required
cluster str

The cluster to run the command on.

required

Returns: the subprocess.CompletedProcess object returned by the command.

Source code in cluv/cli/run.py
async def run(command: str | list[str], cluster: str) -> CompletedProcess[str]:
    """Runs a command in the synced project on a potentially remote cluster.

    Similar in spirit to `uv run`, but runs a command in the synced project on a potentially remote cluster.
    - Idea is that this could maybe be a building block for other commands.

    Parameters:
        command: The command to run, as a string or list of strings.
        cluster: The cluster to run the command on.
    Returns:
        the `subprocess.CompletedProcess` object returned by the command.
    """
    if not isinstance(command, str):
        command = shlex.join(command)
    logger.debug(f"About to run {command=} on {cluster=}")
    remote = (await sync(clusters=[cluster]))[0]
    project_path = find_pyproject().parent.relative_to(Path.home())
    return await remote.run(f"bash -l -c 'uv run --directory={project_path} {command}'")