From ebead2376ab2549a4db08bdfe9a3493335d0d1a3 Mon Sep 17 00:00:00 2001 From: "Pradyun S. Gedam" Date: Fri, 12 May 2017 12:25:27 +0530 Subject: [PATCH] Handle PIP_CONFIG_FILE correctly --- pip/configuration.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pip/configuration.py b/pip/configuration.py index d0df73514..a7b5e3bc4 100644 --- a/pip/configuration.py +++ b/pip/configuration.py @@ -190,15 +190,15 @@ class Configuration(object): def _load_config_files(self): """Loads configuration from configuration files """ - for variant, files in self._get_config_files(): - if variant == "environment": - if files == [os.devnull]: - # If the user sets the environment var as devnull, - # we don't load configuration. - break - elif files == [None]: - continue + config_files = dict(self._get_config_files()) + if config_files["environment"][0:1] == [os.devnull]: + logger.debug( + "Skipping loading configuration files due to " + "environment's PIP_CONFIG_FILE being os.devnull" + ) + return + for variant, files in config_files.items(): for file in files: # If there's specific variant set in `load_only`, load only # that variant, not the others. @@ -261,16 +261,19 @@ class Configuration(object): This should be treated like items of a dictionary. """ + # SMELL: Move the conditions out of this function # environment variables have the lowest priority config_file = os.environ.get('PIP_CONFIG_FILE', None) - yield "environment", [config_file] + if config_file is not None: + yield "environment", [config_file] + else: + yield "environment", [] # at the base we have any site-wide configuration yield "site-wide", list(site_config_files) # per-user configuration next - # SMELL: Move this condition out of this function should_load_user_config = not self.isolated and not ( config_file and os.path.exists(config_file) )