Skip to content

Commit

Permalink
Add ability to override pip's user agent with PIP_USER_AGENT_INSTALLE…
Browse files Browse the repository at this point in the history
…R_OVERRIDE
  • Loading branch information
theacodes committed May 18, 2018
1 parent 6020855 commit 0012ddd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Empty file.
10 changes: 8 additions & 2 deletions src/pip/_internal/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,14 @@ def user_agent():
if setuptools_version is not None:
data["setuptools_version"] = setuptools_version

return "{data[installer][name]}/{data[installer][version]} {json}".format(
data=data,
installer = os.environ.get("PIP_USER_AGENT_INSTALLER_OVERRIDE")
if not installer:
installer = (
"{data[installer][name]}/{data[installer][version]}".format(
data=data))

return "{installer} {json}".format(
installer=installer,
json=json.dumps(data, separators=(",", ":"), sort_keys=True),
)

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def test_user_agent():
PipSession().headers["User-Agent"].startswith("pip/%s" % pip.__version__)


def test_user_agent_override(monkeypatch):
monkeypatch.setenv("PIP_USER_AGENT_INSTALLER_OVERRIDE", "pipenv/1.0.0")
PipSession().headers["User-Agent"].startswith("pipenv/1.0.0")


class FakeStream(object):

def __init__(self, contents):
Expand Down

0 comments on commit 0012ddd

Please sign in to comment.