當前位置: 首頁>>代碼示例>>Python>>正文


Python session.PipSession方法代碼示例

本文整理匯總了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 
開發者ID:r1chardj0n3s,項目名稱:pip-check-reqs,代碼行數:23,代碼來源:common.py

示例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 
開發者ID:dephell,項目名稱:dephell,代碼行數:37,代碼來源:pip.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 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:31,代碼來源:download.py

示例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 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:10,代碼來源:download.py

示例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 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:39,代碼來源:req_file.py

示例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 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:14,代碼來源:req_file.py

示例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) 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:17,代碼來源:collector.py

示例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 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:11,代碼來源:collector.py

示例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 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:10,代碼來源:collector.py

示例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 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:12,代碼來源:req_command.py

示例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 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:40,代碼來源:req_command.py

示例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,
        ) 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:33,代碼來源:req_command.py

示例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,
        ) 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:30,代碼來源:req_command.py

示例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) 
開發者ID:ali5h,項目名稱:rules_pip,代碼行數:12,代碼來源:piptool.py

示例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 
開發者ID:ali5h,項目名稱:rules_pip,代碼行數:33,代碼來源:req_file.py


注:本文中的pip._internal.network.session.PipSession方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。