Repository: pypa/pipenv

Issue:
Improve experience of debugging failed installs with pipenv
I was trying to debug why pipenv was failing on an IPython install in OSX.  I was getting errors like this:

```
›› pipenv install --verbose
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    load_entry_point('pipenv', 'console_scripts', 'pipenv')()
<long traceback>
  File "/Users/jtratner/pipenv/pipenv/patched/pip/utils/__init__.py", line 707, in call_subprocess
    % (command_desc, proc.returncode, cwd))
pip.exceptions.InstallationError: Command "python setup.py egg_info" failed with error code 1 in /var/folders/fm/sjgpzb856kld04jvq82bxrcw0000gp/T/tmp4cQKivbuild/ipython/
```
but with no ability to actually look at what the error was because temp file got removed.

By adding 

```
logger.setLevel(std_logging.INFO)
```

to pipenv/pipenv/patched/pip/utils/__init__.py, I was able to get to underlying error message.  But just using `--verbose` flag didn't really get anywhere.

It'd be nice to either be able to specify a loglevel to pip/pipenv so you can see build failures or have the `--verbose` flag pass through to pip itself. (and if there's a way to do this or a way you'd *like* to do this, perhaps we could add it to the documentation).

(It turned out it was the good old error like this:

```
INFO:pip.utils:Complete output from command python setup.py egg_info:
INFO:pip.utils:
IPython 6.0+ does not support Python 2.6, 2.7, 3.0, 3.1, or 3.2.
When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
Beginning with IPython 6.0, Python 3.3 and above is required.

See IPython `README.rst` file for more information:

    https://github.com/ipython/ipython/blob/master/README.rst

Python sys.version_info(major=2, minor=7, micro=14, releaselevel='final', serial=0) detected.
```
)

##### Describe your environment

1. OS Type OS X
1. Python version: `2.7.14`
1. Pipenv version: (latest master)


Discussion:
I'm definitely open to having `--verbose` set the log level. 
How do you feel about something like this?

1. Can specify it multiple times (and “-v” is synonym for “—verbose”)
2.Single “-v” dumps more output, like “—verbose” now
3. “-vv” sets INFO loglevel for pip (and maybe pipenv)
4. “-vvv” sets DEBUG loglevel for pip and pipenv


On Sat, Feb 17, 2018 at 4:46 AM Kenneth Reitz <notifications@github.com>
wrote:

> I'm definately open to having --verbose set the log level.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pypa/pipenv/issues/1434#issuecomment-366439246>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/ABhjqyfomV_mFRdjLGIH-f_MVsrTZ7p6ks5tVso1gaJpZM4SJM7b>
> .
>

no need for that, let's just add the logging info to standard verbose mode. 

Resolving patch:
diff --git a/pipenv/cli.py b/pipenv/cli.py
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 
+import logging
 import os
 import sys
 
@@ -34,6 +35,11 @@
 
 CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
 
+def setup_verbose(ctx, param, value):
+    if value:
+        logging.getLogger('pip').setLevel(logging.INFO)
+    return value
+
 
 @click.group(invoke_without_command=True, context_settings=CONTEXT_SETTINGS)
 @click.option('--update', is_flag=True, default=False, help="Update Pipenv & pip to latest.")
@@ -186,7 +192,7 @@ def cli(
 @click.option('--system', is_flag=True, default=False, help="System pip management.")
 @click.option('--requirements', '-r', nargs=1, default=False, help="Import a requirements.txt file.")
 @click.option('--code', '-c', nargs=1, default=False, help="Import from codebase.")
-@click.option('--verbose', is_flag=True, default=False, help="Verbose mode.")
+@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.", callback=setup_verbose)
 @click.option('--ignore-pipfile', is_flag=True, default=False, help="Ignore Pipfile when installing, using the Pipfile.lock.")
 @click.option('--sequential', is_flag=True, default=False, help="Install dependencies one-at-a-time, instead of concurrently.")
 @click.option('--skip-lock', is_flag=True, default=False, help=u"Ignore locking mechanisms when installing—use the Pipfile, instead.")
@@ -214,7 +220,7 @@ def install(
 @click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.")
 @click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.")
 @click.option('--system', is_flag=True, default=False, help="System pip management.")
-@click.option('--verbose', is_flag=True, default=False, help="Verbose mode.")
+@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.", callback=setup_verbose)
 @click.option('--lock', is_flag=True, default=True, help="Lock afterwards.")
 @click.option('--all-dev', is_flag=True, default=False, help="Un-install all package from [dev-packages].")
 @click.option('--all', is_flag=True, default=False, help="Purge all package(s) from virtualenv. Does not edit Pipfile.")
@@ -234,7 +240,7 @@ def uninstall(
 @click.command(short_help="Generates Pipfile.lock.")
 @click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.")
 @click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.")
-@click.option('--verbose', is_flag=True, default=False, help="Verbose mode.")
+@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.", callback=setup_verbose)
 @click.option('--requirements', '-r', is_flag=True, default=False, help="Generate output compatible with requirements.txt.")
 @click.option('--dev', '-d', is_flag=True, default=False, help="Generate output compatible with requirements.txt for the development dependencies.")
 @click.option('--clear', is_flag=True, default=False, help="Clear the dependency cache.")
@@ -361,7 +367,7 @@ def run_open(module, three=None, python=None):
 
 @click.command(short_help="Uninstalls all packages, and re-installs package(s) in [packages] to latest compatible versions.")
 @click.argument('package_name', default=False)
-@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.")
+@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.", callback=setup_verbose)
 @click.option('--dev', '-d', is_flag=True, default=False, help="Additionally install package(s) in [dev-packages].")
 @click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.")
 @click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.")
diff --git a/pipenv/core.py b/pipenv/core.py
--- a/pipenv/core.py
+++ b/pipenv/core.py
@@ -2,6 +2,7 @@
 
 import contextlib
 import codecs
+import logging
 import os
 import sys
 import shutil
@@ -1334,6 +1335,7 @@ def pip_install(
 
     if verbose:
         click.echo(crayons.normal('Installing {0!r}'.format(package_name), bold=True), err=True)
+        pip.logger.setLevel(logging.INFO)
 
     # Create files for hash mode.
     if (not ignore_hashes) and (r is None):


Test patch: