Skip to content

_install_tool() needs to output pip's stderr and stdout #141

@2bndy5

Description

@2bndy5

def _install_tool(tool: str, version: str) -> Optional[Path]:
"""Install a tool using pip, suppressing output."""
try:
subprocess.check_call(
[sys.executable, "-m", "pip", "install", f"{tool}=={version}"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
return shutil.which(tool)
except subprocess.CalledProcessError:
return None

It seems this function fails with _install_tool("clang-format", "9"). It would be nice to know why, but this function does not forward any output from pip when invoking pip exits with non-zero code.

Proposal

For a full descriptiopn of what happened:

    try:
        subprocess.run(
            [sys.executable, "-m", "pip", "install", f"{tool}=={version}"],
            capture=True,
            check=True,
        )
        return shutil.which(tool)
    except subprocess.CalledProcessError as exc: 
        LOG.error("pip failed to install %s %s", tool, version)
        LOG.error(exc.stdout.decode(encoding="utf-8"))
        LOG.error(exc.stderr.decode(encoding="utf-8"))
        return None

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions