Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit pipenv and other tools to report itself as the downloader in pip's user agent #5424

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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