Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemporaryPipInstallResolver: Prevent pip install from polluting stdout #361

Merged
merged 1 commit into from
Aug 30, 2023
Merged
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
24 changes: 21 additions & 3 deletions fawltydeps/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,33 @@ def installed_requirements(
marker_file = venv_dir / ".installed"
if not marker_file.is_file():
venv.create(venv_dir, clear=True, with_pip=True)
argv = [f"{venv_dir}/bin/pip", "install", "--no-deps"]
proc = subprocess.run(argv + requirements, check=False)
# Capture output from `pip install` to prevent polluting our own stdout
pip_install_runner = partial(
subprocess.run,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
check=False,
)
Nour-Mws marked this conversation as resolved.
Show resolved Hide resolved
argv = [
f"{venv_dir}/bin/pip",
"install",
"--no-deps",
"--quiet",
"--disable-pip-version-check",
]
proc = pip_install_runner(argv + requirements)
if proc.returncode: # pip install failed
logger.warning("Command failed: %s", argv + requirements)
if proc.stdout.strip():
logger.warning("Output:\n%s", proc.stdout)
logger.info("Retrying each requirement individually...")
for req in requirements:
proc = subprocess.run(argv + [req], check=False)
proc = pip_install_runner(argv + [req])
if proc.returncode: # pip install failed
logger.warning("Failed to install %s", repr(req))
if proc.stdout.strip():
logger.warning("Output:\n%s", proc.stdout)
Nour-Mws marked this conversation as resolved.
Show resolved Hide resolved
marker_file.touch()
yield venv_dir

Expand Down
Loading