本文整理汇总了Python中pip._internal.download.PipSession方法的典型用法代码示例。如果您正苦于以下问题:Python download.PipSession方法的具体用法?Python download.PipSession怎么用?Python download.PipSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip._internal.download
的用法示例。
在下文中一共展示了download.PipSession方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_required_modules
# 需要导入模块: from pip._internal import download [as 别名]
# 或者: from pip._internal.download 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 import download [as 别名]
# 或者: from pip._internal.download 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: _build_session
# 需要导入模块: from pip._internal import download [as 别名]
# 或者: from pip._internal.download import PipSession [as 别名]
def _build_session(self, options, retries=None, timeout=None):
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,
insecure_hosts=options.trusted_hosts,
)
# 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
示例4: _ensure_html_response
# 需要导入模块: from pip._internal import download [as 别名]
# 或者: from pip._internal.download 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)
示例5: parse_requirements
# 需要导入模块: from pip._internal import download [as 别名]
# 或者: from pip._internal.download import PipSession [as 别名]
def parse_requirements(
filename, # type: str
finder=None, # type: Optional[PackageFinder]
comes_from=None, # type: Optional[str]
options=None, # type: Optional[optparse.Values]
session=None, # type: Optional[PipSession]
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 finder: Instance of pip.index.PackageFinder.
:param comes_from: Origin description of requirements.
:param options: cli options.
:param session: Instance of pip.download.PipSession.
: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.
"""
if session is None:
raise TypeError(
"parse_requirements() missing 1 required keyword argument: "
"'session'"
)
_, content = get_file_content(
filename, comes_from=comes_from, session=session
)
lines_enum = preprocess(content, options)
for line_number, line in lines_enum:
req_iter = process_line(line, filename, line_number, finder,
comes_from, options, session, wheel_cache,
use_pep517=use_pep517, constraint=constraint)
for req in req_iter:
yield req
示例6: _build_session
# 需要导入模块: from pip._internal import download [as 别名]
# 或者: from pip._internal.download 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,
insecure_hosts=options.trusted_hosts,
)
# 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
示例7: _build_package_finder
# 需要导入模块: from pip._internal import download [as 别名]
# 或者: from pip._internal.download import PipSession [as 别名]
def _build_package_finder(
self,
options, # type: Values
session, # type: PipSession
platform=None, # type: Optional[str]
python_versions=None, # type: Optional[List[str]]
abi=None, # type: Optional[str]
implementation=None # type: Optional[str]
):
# type: (...) -> PackageFinder
"""
Create a package finder appropriate to this requirement command.
"""
index_urls = [options.index_url] + options.extra_index_urls
if options.no_index:
logger.debug(
'Ignoring indexes: %s',
','.join(redact_password_from_url(url) for url in index_urls),
)
index_urls = []
return PackageFinder(
find_links=options.find_links,
format_control=options.format_control,
index_urls=index_urls,
trusted_hosts=options.trusted_hosts,
allow_all_prereleases=options.pre,
session=session,
platform=platform,
versions=python_versions,
abi=abi,
implementation=implementation,
prefer_binary=options.prefer_binary,
)