本文整理匯總了Python中pip._internal.network.session.PipSession方法的典型用法代碼示例。如果您正苦於以下問題:Python session.PipSession方法的具體用法?Python session.PipSession怎麽用?Python session.PipSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pip._internal.network.session
的用法示例。
在下文中一共展示了session.PipSession方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: find_required_modules
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def find_required_modules(options, requirements_filename: str):
explicit = set()
for requirement in parse_requirements(requirements_filename,
session=PipSession()):
try:
requirement_name = requirement.name
# The type of "requirement" changed between pip versions.
# We exclude the "except" from coverage so that on any pip version we
# can report 100% coverage.
except AttributeError: # pragma: no cover
from pip._internal.req.constructors import install_req_from_line
requirement_name = install_req_from_line(
requirement.requirement,
).name
if options.ignore_reqs(requirement):
log.debug('ignoring requirement: %s', requirement_name)
else:
log.debug('found requirement: %s', requirement_name)
explicit.add(canonicalize_name(requirement_name))
return explicit
示例2: _get_finder
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def _get_finder() -> PackageFinder:
try:
return PackageFinder(find_links=[], index_urls=[], session=PipSession())
except TypeError:
pass
# pip 19.3
from pip._internal.models.search_scope import SearchScope
from pip._internal.models.selection_prefs import SelectionPreferences
try:
return PackageFinder.create(
search_scope=SearchScope(find_links=[], index_urls=[]),
selection_prefs=SelectionPreferences(allow_yanked=False),
session=PipSession(),
)
except TypeError:
pass
from pip._internal.models.target_python import TargetPython
try:
# pip 19.3.1
from pip._internal.collector import LinkCollector
except ImportError:
from pip._internal.index.collector import LinkCollector
return PackageFinder.create(
link_collector=LinkCollector(
search_scope=SearchScope(find_links=[], index_urls=[]),
session=PipSession(),
),
selection_prefs=SelectionPreferences(allow_yanked=False),
target_python=TargetPython(),
)
# https://github.com/pypa/packaging/blob/master/packaging/requirements.py
# https://github.com/jazzband/pip-tools/blob/master/piptools/utils.py
示例3: _http_get_download
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def _http_get_download(session, link):
# type: (PipSession, Link) -> Response
target_url = link.url.split('#', 1)[0]
resp = session.get(
target_url,
# We use Accept-Encoding: identity here because requests
# defaults to accepting compressed responses. This breaks in
# a variety of ways depending on how the server is configured.
# - Some servers will notice that the file isn't a compressible
# file and will leave the file alone and with an empty
# Content-Encoding
# - Some servers will notice that the file is already
# compressed and will leave the file alone and will add a
# Content-Encoding: gzip header
# - Some servers won't notice anything at all and will take
# a file that's already been compressed and compress it again
# and set the Content-Encoding: gzip header
# By setting this to request only the identity encoding We're
# hoping to eliminate the third case. Hopefully there does not
# exist a server which when given a file will notice it is
# already compressed and that you're not asking for a
# compressed file and will then decompress it before sending
# because if that's the case I don't think it'll ever be
# possible to make this work.
headers={"Accept-Encoding": "identity"},
stream=True,
)
resp.raise_for_status()
return resp
示例4: __init__
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def __init__(
self,
session, # type: PipSession
progress_bar, # type: str
):
# type: (...) -> None
self._session = session
self._progress_bar = progress_bar
示例5: parse_requirements
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def parse_requirements(
filename, # type: str
session, # type: PipSession
finder=None, # type: Optional[PackageFinder]
comes_from=None, # type: Optional[str]
options=None, # type: Optional[optparse.Values]
constraint=False, # type: bool
wheel_cache=None, # type: Optional[WheelCache]
use_pep517=None # type: Optional[bool]
):
# type: (...) -> Iterator[InstallRequirement]
"""Parse a requirements file and yield InstallRequirement instances.
:param filename: Path or url of requirements file.
:param session: PipSession instance.
:param finder: Instance of pip.index.PackageFinder.
:param comes_from: Origin description of requirements.
:param options: cli options.
:param constraint: If true, parsing a constraint file rather than
requirements file.
:param wheel_cache: Instance of pip.wheel.WheelCache
:param use_pep517: Value of the --use-pep517 option.
"""
skip_requirements_regex = (
options.skip_requirements_regex if options else None
)
line_parser = get_line_parser(finder)
parser = RequirementsFileParser(
session, line_parser, comes_from, skip_requirements_regex
)
for parsed_line in parser.parse(filename, constraint):
req = handle_line(
parsed_line, finder, options, session, wheel_cache, use_pep517
)
if req is not None:
yield req
示例6: __init__
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def __init__(
self,
session, # type: PipSession
line_parser, # type: LineParser
comes_from, # type: str
skip_requirements_regex, # type: Optional[str]
):
# type: (...) -> None
self._session = session
self._line_parser = line_parser
self._comes_from = comes_from
self._skip_requirements_regex = skip_requirements_regex
示例7: _ensure_html_response
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def _ensure_html_response(url, session):
# type: (str, PipSession) -> None
"""Send a HEAD request to the URL, and ensure the response contains HTML.
Raises `_NotHTTP` if the URL is not available for a HEAD request, or
`_NotHTML` if the content type is not text/html.
"""
scheme, netloc, path, query, fragment = urllib_parse.urlsplit(url)
if scheme not in {'http', 'https'}:
raise _NotHTTP()
resp = session.head(url, allow_redirects=True)
resp.raise_for_status()
_ensure_html_header(resp)
示例8: with_cached_link_fetch
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def with_cached_link_fetch(fn):
# type: (Any) -> Any
@lru_cache(maxsize=None)
def wrapper(link, session=None):
# type: (Link, Optional[PipSession]) -> Optional[HTMLPage]
return fn(link, session=session)
return wrapper
示例9: __init__
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def __init__(
self,
session, # type: PipSession
search_scope, # type: SearchScope
):
# type: (...) -> None
self.search_scope = search_scope
self.session = session
示例10: get_default_session
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def get_default_session(self, options):
# type: (Values) -> PipSession
"""Get a default-managed session."""
if self._session is None:
self._session = self.enter_context(self._build_session(options))
# there's no type annotation on requests.Session, so it's
# automatically ContextManager[Any] and self._session becomes Any,
# then https://github.com/python/mypy/issues/7696 kicks in
assert self._session is not None
return self._session
示例11: _build_session
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def _build_session(self, options, retries=None, timeout=None):
# type: (Values, Optional[int], Optional[int]) -> PipSession
session = PipSession(
cache=(
normalize_path(os.path.join(options.cache_dir, "http"))
if options.cache_dir else None
),
retries=retries if retries is not None else options.retries,
trusted_hosts=options.trusted_hosts,
index_urls=self._get_index_urls(options),
headers=self._get_headers(options),
)
# Handle custom ca-bundles from the user
if options.cert:
session.verify = options.cert
# Handle SSL client certificate
if options.client_cert:
session.cert = options.client_cert
# Handle timeouts
if options.timeout or timeout:
session.timeout = (
timeout if timeout is not None else options.timeout
)
# Handle configured proxies
if options.proxy:
session.proxies = {
"http": options.proxy,
"https": options.proxy,
}
# Determine if we can prompt the user for authentication or not
session.auth.prompting = not options.no_input
return session
示例12: make_requirement_preparer
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def make_requirement_preparer(
temp_build_dir, # type: TempDirectory
options, # type: Values
req_tracker, # type: RequirementTracker
session, # type: PipSession
finder, # type: PackageFinder
use_user_site, # type: bool
download_dir=None, # type: str
wheel_download_dir=None, # type: str
):
# type: (...) -> RequirementPreparer
"""
Create a RequirementPreparer instance for the given parameters.
"""
downloader = Downloader(session, progress_bar=options.progress_bar)
temp_build_dir_path = temp_build_dir.path
assert temp_build_dir_path is not None
return RequirementPreparer(
build_dir=temp_build_dir_path,
src_dir=options.src_dir,
download_dir=download_dir,
wheel_download_dir=wheel_download_dir,
build_isolation=options.build_isolation,
req_tracker=req_tracker,
downloader=downloader,
finder=finder,
require_hashes=options.require_hashes,
use_user_site=use_user_site,
)
示例13: _build_package_finder
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def _build_package_finder(
self,
options, # type: Values
session, # type: PipSession
target_python=None, # type: Optional[TargetPython]
ignore_requires_python=None, # type: Optional[bool]
):
# type: (...) -> PackageFinder
"""
Create a package finder appropriate to this requirement command.
:param ignore_requires_python: Whether to ignore incompatible
"Requires-Python" values in links. Defaults to False.
"""
link_collector = make_link_collector(session, options=options)
selection_prefs = SelectionPreferences(
allow_yanked=True,
format_control=options.format_control,
allow_all_prereleases=options.pre,
prefer_binary=options.prefer_binary,
ignore_requires_python=ignore_requires_python,
)
return PackageFinder.create(
link_collector=link_collector,
selection_prefs=selection_prefs,
target_python=target_python,
)
示例14: get_requirements
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def get_requirements(requirement):
"""Parse a requirement file
:param requirement: path to requirement file
:returns: list of InstallRequirement
:rtype: list[InstallRequirements]
"""
session = PipSession()
return parse_requirements(requirement, session=session)
示例15: parse_requirements
# 需要導入模塊: from pip._internal.network import session [as 別名]
# 或者: from pip._internal.network.session import PipSession [as 別名]
def parse_requirements(
filename, # type: str
session, # type: PipSession
finder=None, # type: Optional[PackageFinder]
comes_from=None, # type: Optional[str]
options=None, # type: Optional[optparse.Values]
constraint=False, # type: bool
):
# type: (...) -> Iterator[ParsedRequirement]
"""Parse a requirements file and yield InstallRequirement instances.
:param filename: Path or url of requirements file.
:param session: PipSession instance.
:param finder: Instance of pip.index.PackageFinder.
:param comes_from: Origin description of requirements.
:param options: cli options.
:param constraint: If true, parsing a constraint file rather than
requirements file.
"""
line_parser = get_line_parser(finder)
parser = RequirementsFileParser(session, line_parser, comes_from)
for parsed_line in parser.parse(filename, constraint):
parsed_req = handle_line(
parsed_line,
options=options,
finder=finder,
session=session
)
if parsed_req is not None:
yield parsed_req