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 Feb 26, 2019
1 parent c2661ef commit 8e81664
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 @@ -167,8 +167,14 @@ def user_agent():
# value to make it easier to know that the check has been run.
data["ci"] = True if looks_like_ci() else None

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 @@ -88,6 +88,11 @@ def test_user_agent__ci(monkeypatch, name, expected_like_ci):
assert ('"ci":null' in user_agent) == (not expected_like_ci)


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 8e81664

Please sign in to comment.