Skip to content

Commit

Permalink
Remove secho from pipenv.utils.pipfile
Browse files Browse the repository at this point in the history
  • Loading branch information
oz123 committed Jul 21, 2023
1 parent 9f7ca6d commit 8b118c1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pipenv/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from pipenv.patched.pip._vendor import rich
`

logging.basicConfig(level=logging.ERROR)

console = rich.console.Console()
Expand Down
9 changes: 5 additions & 4 deletions pipenv/utils/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pipenv.patched.pip._internal.build_env import get_runnable_pip
from pipenv.project import Project
from pipenv.utils import console, err
from pipenv.utils import err
from pipenv.utils.dependencies import get_constraints_from_deps, prepare_constraint_file
from pipenv.utils.indexes import get_source_list, prepare_pip_source_args
from pipenv.utils.processes import subprocess_run
Expand All @@ -30,15 +30,16 @@ def gen(out):


def format_pip_error(error):
error = error.replace("Expected", "[bold green]Expected[/bold green]", fg="green", bold=True)))
error = error.replace("Expected", "[bold green]Expected[/bold green]")
error = error.replace("Got", "[bold red]Got[/red bold]")
error = error.replace(
"THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE",
"[bold red]THESE PACKAGES DO NOT MATCH THE HASHES FROM Pipfile.lock![/bold red]",
)
)
error = error.replace(
"someone may have tampered with them",
"[red]someone may have tampered with them[/red]")
"[red]someone may have tampered with them[/red]",
)
error = error.replace("option to pip install", "option to 'pipenv install'")
return error

Expand Down
35 changes: 11 additions & 24 deletions pipenv/utils/pipfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import os

from pipenv import environments, exceptions
from pipenv.patched.pip._vendor import rich
from pipenv.utils import console, err
from pipenv.utils.requirements import import_requirements
from pipenv.vendor import click

console = rich.console.Console()
err = rich.console.Console(stderr=True)


def walk_up(bottom):
Expand Down Expand Up @@ -74,12 +70,9 @@ def ensure_pipfile(project, validate=True, skip_requirements=False, system=False
# If there's a requirements file, but no Pipfile...
if project.requirements_exists and not skip_requirements:
requirements_dir_path = os.path.dirname(project.requirements_location)
click.echo(
"{} found in {} instead of {}! Converting...".format(
click.style("requirements.txt", bold=True),
click.style(requirements_dir_path, fg="yellow", bold=True),
click.style("Pipfile", bold=True),
)
console.print(
f"[bold]requirements.txt[/bold] found in [bold yellow]{requirements_dir_path}"
"[/bold yellow] instead of [bold]Pipfile[/bold]! Converting..."
)
# Create a Pipfile...
project.create_pipfile(python=python)
Expand All @@ -96,18 +89,14 @@ def ensure_pipfile(project, validate=True, skip_requirements=False, system=False
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"
"We recommend updating your {1} to specify the {3} version, instead."
"".format(
click.style("Warning", fg="red", bold=True),
click.style("Pipfile", bold=True),
click.style("requirements.txt", bold=True),
click.style('"*"', bold=True),
)
console.print(
"[bold red]Warning[/bold red]: Your [bold]Pipfile[/bold] now contains pinned versions, "
"if your [bold]requirements.txt[/bold] did. \n"
'We recommend updating your [bold]Pipfile[/bold] to specify the [bold]"*"'
"[/bold] version, instead."
)
else:
click.secho("Creating a Pipfile for this project...", bold=True, err=True)
err.print("Creating a Pipfile for this project...", style="bold")
# Create the pipfile if it doesn't exist.
project.create_pipfile(python=python)
# Validate the Pipfile's contents.
Expand All @@ -117,7 +106,5 @@ def ensure_pipfile(project, validate=True, skip_requirements=False, system=False
changed = project.ensure_proper_casing()
# Write changes out to disk.
if changed:
click.echo(
click.style("Fixing package names in Pipfile...", bold=True), err=True
)
err.print("Fixing package names in Pipfile...", style="bold")
project.write_toml(p)

0 comments on commit 8b118c1

Please sign in to comment.