25
25
from pip ._internal .cli import cmdoptions
26
26
from pip ._internal .exceptions import InstallationError , RequirementsFileParseError
27
27
from pip ._internal .models .search_scope import SearchScope
28
- from pip ._internal .network .session import PipSession
29
- from pip ._internal .network .utils import raise_for_status
30
28
from pip ._internal .utils .encoding import auto_decode
31
29
from pip ._internal .utils .urls import get_url_scheme
32
30
33
31
if TYPE_CHECKING :
34
32
from pip ._internal .index .package_finder import PackageFinder
33
+ from pip ._internal .network .session import PipSession
35
34
36
35
__all__ = ["parse_requirements" ]
37
36
@@ -133,7 +132,7 @@ def __init__(
133
132
134
133
def parse_requirements (
135
134
filename : str ,
136
- session : PipSession ,
135
+ session : " PipSession" ,
137
136
finder : Optional ["PackageFinder" ] = None ,
138
137
options : Optional [optparse .Values ] = None ,
139
138
constraint : bool = False ,
@@ -210,7 +209,7 @@ def handle_option_line(
210
209
lineno : int ,
211
210
finder : Optional ["PackageFinder" ] = None ,
212
211
options : Optional [optparse .Values ] = None ,
213
- session : Optional [PipSession ] = None ,
212
+ session : Optional [" PipSession" ] = None ,
214
213
) -> None :
215
214
if opts .hashes :
216
215
logger .warning (
@@ -278,7 +277,7 @@ def handle_line(
278
277
line : ParsedLine ,
279
278
options : Optional [optparse .Values ] = None ,
280
279
finder : Optional ["PackageFinder" ] = None ,
281
- session : Optional [PipSession ] = None ,
280
+ session : Optional [" PipSession" ] = None ,
282
281
) -> Optional [ParsedRequirement ]:
283
282
"""Handle a single parsed requirements line; This can result in
284
283
creating/yielding requirements, or updating the finder.
@@ -321,7 +320,7 @@ def handle_line(
321
320
class RequirementsFileParser :
322
321
def __init__ (
323
322
self ,
324
- session : PipSession ,
323
+ session : " PipSession" ,
325
324
line_parser : LineParser ,
326
325
) -> None :
327
326
self ._session = session
@@ -526,7 +525,7 @@ def expand_env_variables(lines_enum: ReqFileLines) -> ReqFileLines:
526
525
yield line_number , line
527
526
528
527
529
- def get_file_content (url : str , session : PipSession ) -> Tuple [str , str ]:
528
+ def get_file_content (url : str , session : " PipSession" ) -> Tuple [str , str ]:
530
529
"""Gets the content of a file; it may be a filename, file: URL, or
531
530
http: URL. Returns (location, content). Content is unicode.
532
531
Respects # -*- coding: declarations on the retrieved files.
@@ -538,6 +537,9 @@ def get_file_content(url: str, session: PipSession) -> Tuple[str, str]:
538
537
539
538
# Pip has special support for file:// URLs (LocalFSAdapter).
540
539
if scheme in ["http" , "https" , "file" ]:
540
+ # Delay importing heavy network modules until absolutely necessary.
541
+ from pip ._internal .network .utils import raise_for_status
542
+
541
543
resp = session .get (url )
542
544
raise_for_status (resp )
543
545
return resp .url , resp .text
0 commit comments