Skip to content

Commit

Permalink
Merge pull request #5581 from pypa/fix-verbose-logging
Browse files Browse the repository at this point in the history
Fix verbose logging
  • Loading branch information
oz123 authored Jan 30, 2023
2 parents 4cb2644 + b4c000a commit 36ecc14
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repos:
exclude: tests/data

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
files: \.py$
Expand Down
1 change: 1 addition & 0 deletions news/5530.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix overwriting of output in verbose mode
26 changes: 9 additions & 17 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ def ensure_pipfile(project, validate=True, skip_requirements=False, system=False
except Exception:
err.print(environments.PIPENV_SPINNER_FAIL_TEXT.format("Failed..."))
else:
st.update(environments.PIPENV_SPINNER_OK_TEXT.format("Success!"))
st.console.print(
environments.PIPENV_SPINNER_OK_TEXT.format("Success!")
)
# Warn the user of side-effects.
click.echo(
"{0}: Your {1} now contains pinned versions, if your {2} did. \n"
Expand Down Expand Up @@ -2305,7 +2307,7 @@ def do_install(
os.environ["PIP_USER"] = "0"
if "PYTHONHOME" in os.environ:
del os.environ["PYTHONHOME"]
st.update(f"Resolving {pkg_line}...")
st.console.print(f"Resolving {pkg_line}...")
try:
pkg_requirement = Requirement.from_line(pkg_line)
except ValueError as e:
Expand All @@ -2316,11 +2318,11 @@ def do_install(
)
)
sys.exit(1)
st.update("Installing...")
st.console.print("Installing...")
try:
st.update(f"Installing {pkg_requirement.name}...")
if project.s.is_verbose():
st.update(
st.console.print(
f"Installing package: {pkg_requirement.as_line(include_hashes=False)}"
)
c = pip_install(
Expand Down Expand Up @@ -2393,18 +2395,8 @@ def do_install(
pipfile_sections = "[dev-packages]"
else:
pipfile_sections = "[packages]"
st.update(
"{} {} {} {}{}".format(
click.style("Adding", bold=True),
click.style(f"{pkg_requirement.name}", fg="green", bold=True),
click.style("to Pipfile's", bold=True),
click.style(
pipfile_sections,
fg="yellow",
bold=True,
),
click.style(fix_utf8("..."), bold=True),
)
st.console.print(
f"[bold]Adding [green]{pkg_requirement.name}[/green][/bold] to Pipfile's [yellow]\\{pipfile_sections}[/yellow] ..."
)
# Add the package to the Pipfile.
if index_url:
Expand Down Expand Up @@ -2433,7 +2425,7 @@ def do_install(
)
)
# ok has a nice v in front, should do something similir with rich
st.update(
st.console.print(
environments.PIPENV_SPINNER_OK_TEXT.format("Installation Succeeded")
)
# Update project settings with pre preference.
Expand Down
14 changes: 8 additions & 6 deletions pipenv/utils/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,13 +925,13 @@ def resolve(cmd, st, project):
continue
err += line
if is_verbose:
st.update(line.rstrip())
st.console.print(line.rstrip())

c.wait()
returncode = c.poll()
out = c.stdout.read()
if returncode != 0:
st.update(environments.PIPENV_SPINNER_FAIL_TEXT.format("Locking Failed!"))
st.console.print(environments.PIPENV_SPINNER_FAIL_TEXT.format("Locking Failed!"))
echo(out.strip(), err=True)
if not is_verbose:
echo(err, err=True)
Expand Down Expand Up @@ -1031,7 +1031,7 @@ def venv_resolve_deps(
# we now download those requirements / make temporary folders to perform
# dependency resolution on them, so we are including this step inside the
# spinner context manager for the UX improvement
st.update("Building requirements...")
st.console.print("Building requirements...")
deps = convert_deps_to_pip(deps, project, include_index=True)
constraints = set(deps)
with tempfile.NamedTemporaryFile(
Expand All @@ -1040,14 +1040,16 @@ def venv_resolve_deps(
constraints_file.write(str("\n".join(constraints)))
cmd.append("--constraints-file")
cmd.append(constraints_file.name)
st.update("Resolving dependencies...")
st.console.print("Resolving dependencies...")
c = resolve(cmd, st, project=project)
if c.returncode == 0:
st.update(environments.PIPENV_SPINNER_OK_TEXT.format("Success!"))
st.console.print(environments.PIPENV_SPINNER_OK_TEXT.format("Success!"))
if not project.s.is_verbose() and c.stderr.strip():
click.echo(click.style(f"Warning: {c.stderr.strip()}"), err=True)
else:
st.update(environments.PIPENV_SPINNER_FAIL_TEXT.format("Locking Failed!"))
st.console.print(
environments.PIPENV_SPINNER_FAIL_TEXT.format("Locking Failed!")
)
click.echo(f"Output: {c.stdout.strip()}", err=True)
click.echo(f"Error: {c.stderr.strip()}", err=True)
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def test_update_outdated_with_outdated_package(pipenv_instance_private_pypi, cmd
p.pipenv(f"install {cmd_option} {package_name}==1.11")
c = p.pipenv("update --outdated")
assert isinstance(c.exception, SystemExit)
assert c.stdout_bytes.decode("utf-8").startswith(f"Package '{package_name}' out-of-date:")
assert f"Package '{package_name}' out-of-date:" in c.stdout_bytes.decode("utf-8")

0 comments on commit 36ecc14

Please sign in to comment.