Skip to content

Commit

Permalink
Configuration - Documentation updates (#4556)
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg authored and dstufft committed Jun 24, 2017
1 parent a24c59f commit 49abd55
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/configuration.rst
Expand Up @@ -3,4 +3,4 @@
Configuration
=============

This content is now covered in the :doc:`User Guide <user_guide>`
This content is now covered in the :ref:`Configuration` section of the :doc:`User Guide <user_guide>`.
1 change: 1 addition & 0 deletions docs/reference/index.rst
Expand Up @@ -14,5 +14,6 @@ Reference Guide
pip_show
pip_search
pip_check
pip_config
pip_wheel
pip_hash
22 changes: 22 additions & 0 deletions docs/reference/pip_config.rst
@@ -0,0 +1,22 @@

.. _`pip config`:

pip config
------------

.. contents::

Usage
*****

.. pip-command-usage:: config

Description
***********

.. pip-command-description:: config

Options
*******

.. pip-command-options:: config
2 changes: 1 addition & 1 deletion docs/user_guide.rst
Expand Up @@ -424,7 +424,7 @@ Examples:


Command Completion
------------------
******************

pip comes with support for command line completion in bash, zsh and fish.

Expand Down
1 change: 1 addition & 0 deletions news/4556.trivial
@@ -0,0 +1 @@
Misc changes related to configuration
4 changes: 2 additions & 2 deletions pip/commands/configuration.py
Expand Up @@ -52,8 +52,8 @@ def __init__(self, *args, **kwargs):
action='store',
default=None,
help=(
'Editor to use to edit the file. Uses '
'$EDITOR if not passed.'
'Editor to use to edit the file. Uses VISUAL or EDITOR '
'environment variables if not provided.'
)
)

Expand Down
8 changes: 7 additions & 1 deletion pip/configuration.py
Expand Up @@ -83,6 +83,8 @@ def __init__(self, isolated, load_only=None):
kinds.GLOBAL, kinds.USER, kinds.VENV, kinds.ENV, kinds.ENV_VAR
]

self._ignore_env_names = ["version", "help"]

# Because we keep track of where we got the data from
self._parsers = {variant: [] for variant in self._override_order}
self._config = {variant: {} for variant in self._override_order}
Expand Down Expand Up @@ -275,7 +277,11 @@ def _normalized_keys(self, section, items):
def _get_environ_vars(self):
"""Returns a generator with all environmental vars with prefix PIP_"""
for key, val in os.environ.items():
if key.startswith("PIP_"):
should_be_yielded = (
key.startswith("PIP_") and
key[4:].lower() not in self._ignore_env_names
)
if should_be_yielded:
yield key[4:].lower(), val

# XXX: This is patched in the tests.
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_configuration.py
Expand Up @@ -3,6 +3,7 @@

import os

import pytest
from mock import MagicMock

from pip.exceptions import ConfigurationError
Expand Down Expand Up @@ -49,6 +50,22 @@ def test_environment_var_loading(self):
self.configuration.load()
assert self.configuration.get_value(":env:.hello") == "5"

@pytest.mark.skipif("sys.platform == 'win32'")
def test_environment_var_does_not_load_lowercase(self):
os.environ["pip_hello"] = "5"

self.configuration.load()
with pytest.raises(ConfigurationError):
self.configuration.get_value(":env:.hello")

def test_environment_var_does_not_load_version(self):
os.environ["PIP_VERSION"] = "True"

self.configuration.load()

with pytest.raises(ConfigurationError):
self.configuration.get_value(":env:.version")


class TestConfigurationPrecedence(ConfigurationMixin):
# Tests for methods to that determine the order of precedence of
Expand Down

0 comments on commit 49abd55

Please sign in to comment.