Repository: pypa/pip

Issue:
pip --no-cache-dir still warns about a cache folder
If I use the `--no-cache-dir` option, I expect it to not even try to figure out any cache, but you can see that it still does, and suggest to use `sudo -H`

```
$ sudo pip --no-cache-dir --disable-pip-version-check search glop
The directory '/home/ubuntu/.cache/pip/log' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
glopen     - Open-like interface to globus remotes
glopy      - Python library wrapping Globus Toolkit credential library
```

Verbose:

```
$ sudo pip --verbose --no-cache-dir --disable-pip-version-check search glop
The directory '/home/ubuntu/.cache/pip/log' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Starting new HTTPS connection (1): pypi.python.org
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
"POST /pypi HTTP/1.1" 200 None
glopen     - Open-like interface to globus remotes
glopy      - Python library wrapping Globus Toolkit credential library
```

Version:

```
$ pip --version
pip 6.1.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
```



Discussion:
That's because on some operating systems the log directory is a sub-directory of the cache directory (but not on others). I'm not sure what the right answer is- on one hand on systems where the log dir is a subdir of the cache dir it can often make sense to turn off logging when `--no-cache-dir` is used (though maybe not always? Someone might just be trying to disable caching), on the other hand doing that is a little confusing on platforms where the log dir isn't in the cache dir.

In attempting to find a workaround for this warning, I noticed that it appears even if the log directory is explicitly set to something else using the `--log` argument:

``` bash
# search for a package, with cache disabled and log sent to /dev/null
vagrant@hotlanta:/percolate/hotlanta$ sudo pip --no-cache-dir --log /dev/null search ianw
The directory '/home/vagrant/.cache/pip/log' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
js.unicode_eastasianwidth     - Fanstatic packaging of Counting the unicode characters based Unicode East Asian Width database for JavaScript. It includes some tools for dealing with characters.

# version
vagrant@hotlanta:/percolate/hotlanta$ pip --version
pip 6.1.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
```

While it may not be desirable to infer logging behavior based on the usage of the `--no-cache-dir` flag, it should at least be possible to redirect logging (or perhaps disable it with a `--no-log-dir` flag) to get around this problem. 


Resolving patch:
diff --git a/pip/basecommand.py b/pip/basecommand.py
--- a/pip/basecommand.py
+++ b/pip/basecommand.py
@@ -22,9 +22,8 @@
     SUCCESS, ERROR, UNKNOWN_ERROR, VIRTUALENV_NOT_FOUND,
     PREVIOUS_BUILD_DIR_ERROR,
 )
-from pip.utils import appdirs, get_prog, normalize_path
+from pip.utils import get_prog, normalize_path
 from pip.utils.deprecation import RemovedInPip8Warning
-from pip.utils.filesystem import check_path_owner
 from pip.utils.logging import IndentingFormatter
 from pip.utils.outdated import pip_version_check
 
@@ -120,13 +119,6 @@ def main(self, args):
         else:
             level = "INFO"
 
-        # Compute the path for our debug log.
-        debug_log_path = os.path.join(appdirs.user_log_dir("pip"), "debug.log")
-
-        # Ensure that the path for our debug log is owned by the current user
-        # and if it is not, disable the debug log.
-        write_debug_log = check_path_owner(debug_log_path)
-
         logging_dictConfig({
             "version": 1,
             "disable_existing_loggers": False,
@@ -160,15 +152,6 @@ def main(self, args):
                     "stream": self.log_streams[1],
                     "formatter": "indent",
                 },
-                "debug_log": {
-                    "level": "DEBUG",
-                    "class": "pip.utils.logging.BetterRotatingFileHandler",
-                    "filename": debug_log_path,
-                    "maxBytes": 10 * 1000 * 1000,  # 10 MB
-                    "backupCount": 1,
-                    "delay": True,
-                    "formatter": "indent",
-                },
                 "user_log": {
                     "level": "DEBUG",
                     "class": "pip.utils.logging.BetterRotatingFileHandler",
@@ -182,7 +165,6 @@ def main(self, args):
                 "handlers": list(filter(None, [
                     "console",
                     "console_errors",
-                    "debug_log" if write_debug_log else None,
                     "user_log" if options.log else None,
                 ])),
             },
@@ -204,17 +186,6 @@ def main(self, args):
             ),
         })
 
-        # We add this warning here instead of up above, because the logger
-        # hasn't been configured until just now.
-        if not write_debug_log:
-            logger.warning(
-                "The directory '%s' or its parent directory is not owned by "
-                "the current user and the debug log has been disabled. Please "
-                "check the permissions and owner of that directory. If "
-                "executing pip with sudo, you may want sudo's -H flag.",
-                os.path.dirname(debug_log_path),
-            )
-
         if options.log_explicit_levels:
             warnings.warn(
                 "--log-explicit-levels has been deprecated and will be removed"


Test patch: