diff --git a/news/6182.vendor.rst b/news/6182.vendor.rst new file mode 100644 index 0000000000..245d8fcb30 --- /dev/null +++ b/news/6182.vendor.rst @@ -0,0 +1 @@ +Remove click.echo from pipenv/cli diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py index 8874a6f321..35ad1f4b17 100644 --- a/pipenv/cli/command.py +++ b/pipenv/cli/command.py @@ -186,10 +186,8 @@ def cli( pypi_mirror=state.pypi_mirror, clear=state.clear, ) - # Check this again before exiting for empty ``pipenv`` command. elif ctx.invoked_subcommand is None: - # Display help to user, if no commands were passed. - print(format_help(ctx.get_help())) + console.print(format_help(ctx.get_help())) @cli.command( diff --git a/pipenv/cli/options.py b/pipenv/cli/options.py index e82e02c61f..3d13b131fb 100644 --- a/pipenv/cli/options.py +++ b/pipenv/cli/options.py @@ -2,7 +2,7 @@ import re from pipenv.project import Project -from pipenv.utils import err +from pipenv.utils import console, err from pipenv.utils.internet import is_valid_url from pipenv.vendor.click import ( BadArgumentUsage, @@ -10,7 +10,6 @@ Group, Option, argument, - echo, make_pass_decorator, option, ) @@ -33,12 +32,7 @@ def get_help_option(self, ctx): def show_help(ctx, param, value): if value and not ctx.resilient_parsing: - if not ctx.invoked_subcommand: - # legit main help - echo(format_help(ctx.get_help())) - else: - # legit sub-command help - echo(ctx.get_help(), color=ctx.color) + console.print(format_help(ctx.get_help())) ctx.exit() return Option( diff --git a/pipenv/utils/__init__.py b/pipenv/utils/__init__.py index 3359402c07..13e4f793af 100644 --- a/pipenv/utils/__init__.py +++ b/pipenv/utils/__init__.py @@ -3,6 +3,5 @@ from pipenv.patched.pip._vendor.rich.console import Console logging.basicConfig(level=logging.INFO) - -console = Console() +console = Console(highlight=False) err = Console(stderr=True) diff --git a/pipenv/utils/display.py b/pipenv/utils/display.py index a93a718be8..8f5748a414 100644 --- a/pipenv/utils/display.py +++ b/pipenv/utils/display.py @@ -1,30 +1,19 @@ -from pipenv.vendor import click - - def format_help(help): """Formats the help string.""" - help = help.replace("Options:", str(click.style("Options:", bold=True))) - help = help.replace( - "Usage: pipenv", str("Usage: {}".format(click.style("pipenv", bold=True))) - ) - help = help.replace(" check", str(click.style(" check", fg="red", bold=True))) - help = help.replace(" clean", str(click.style(" clean", fg="red", bold=True))) - help = help.replace(" graph", str(click.style(" graph", fg="red", bold=True))) - help = help.replace( - " install", str(click.style(" install", fg="magenta", bold=True)) - ) - help = help.replace(" lock", str(click.style(" lock", fg="green", bold=True))) - help = help.replace(" open", str(click.style(" open", fg="red", bold=True))) - help = help.replace(" run", str(click.style(" run", fg="yellow", bold=True))) - help = help.replace(" shell", str(click.style(" shell", fg="yellow", bold=True))) - help = help.replace( - " scripts", str(click.style(" scripts", fg="yellow", bold=True)) - ) - help = help.replace(" sync", str(click.style(" sync", fg="green", bold=True))) - help = help.replace( - " uninstall", str(click.style(" uninstall", fg="magenta", bold=True)) - ) - help = help.replace(" update", str(click.style(" update", fg="green", bold=True))) + help = help.replace("Options:", "[bold]Options:[/bold]") + help = help.replace("Usage: pipenv", "Usage: [bold]pipenv[/bold]") + help = help.replace(" check", "[bold red] check[/red bold]") + help = help.replace(" clean", "[bold red] clean[/red bold]") + help = help.replace(" graph", "[bold red] graph[/red bold]") + help = help.replace(" install", "[bold magenta] install[/magenta bold]") + help = help.replace(" lock", "[bold green] lock[/green bold]") + help = help.replace(" open", "[bold red] open[/red bold]") + help = help.replace(" run", "[bold yellow] run[/yellow bold]") + help = help.replace(" shell", "[bold yellow] shell[/yellow bold]") + help = help.replace(" scripts", "[bold yellow] scripts[/yellow bold]") + help = help.replace(" sync", "[bold green] sync[/green bold]") + help = help.replace(" uninstall", "[bold magenta] uninstall[/magenta bold]") + help = help.replace(" update", "[bold green] update[/green bold]") additional_help = """ Usage Examples: Create a new project using Python 3.7, specifically: @@ -52,14 +41,14 @@ def format_help(help): $ {} Commands:""".format( - click.style("pipenv --python 3.7", fg="yellow"), - click.style("pipenv --rm", fg="yellow"), - click.style("pipenv install --dev", fg="yellow"), - click.style("pipenv lock --pre", fg="yellow"), - click.style("pipenv graph", fg="yellow"), - click.style("pipenv check", fg="yellow"), - click.style("pipenv install -e .", fg="yellow"), - click.style("pipenv run pip freeze", fg="yellow"), + "[yellow]pipenv --python 3.7[/yellow]", + "[yellow]pipenv --rm[/yellow]", + "[yellow]pipenv install --dev[/yellow]", + "[yellow]pipenv lock --pre[/yellow]", + "[yellow]pipenv graph[/yellow]", + "[yellow]pipenv check[/yellow]", + "[yellow]pipenv install -e .[/yellow]", + "[yellow]pipenv run pip freeze[/yellow]", ) help = help.replace("Commands:", additional_help) return help