File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
src/pip/_internal/network Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 3
3
"""
4
4
5
5
import email .utils
6
+ import functools
6
7
import io
7
8
import ipaddress
8
9
import json
@@ -106,6 +107,7 @@ def looks_like_ci() -> bool:
106
107
return any (name in os .environ for name in CI_ENVIRONMENT_VARIABLES )
107
108
108
109
110
+ @functools .lru_cache (maxsize = 1 )
109
111
def user_agent () -> str :
110
112
"""
111
113
Return a string representing the user agent.
Original file line number Diff line number Diff line change 10
10
11
11
from pip import __version__
12
12
from pip ._internal .models .link import Link
13
- from pip ._internal .network .session import CI_ENVIRONMENT_VARIABLES , PipSession
13
+ from pip ._internal .network .session import (
14
+ CI_ENVIRONMENT_VARIABLES ,
15
+ PipSession ,
16
+ user_agent ,
17
+ )
14
18
15
19
16
20
def get_user_agent () -> str :
21
+ # These tests are testing the computation of the user agent, so we want to
22
+ # avoid reusing cached values.
23
+ user_agent .cache_clear ()
17
24
return PipSession ().headers ["User-Agent" ]
18
25
19
26
@@ -58,7 +65,7 @@ def test_user_agent__ci(
58
65
59
66
def test_user_agent_user_data (monkeypatch : pytest .MonkeyPatch ) -> None :
60
67
monkeypatch .setenv ("PIP_USER_AGENT_USER_DATA" , "some_string" )
61
- assert "some_string" in PipSession (). headers [ "User-Agent" ]
68
+ assert "some_string" in get_user_agent ()
62
69
63
70
64
71
class TestPipSession :
You can’t perform that action at this time.
0 commit comments