def make_link_collector( session, # type: PipSession options, # type: Values suppress_no_index=False, # type: bool ): # type: (...) -> LinkCollector """ :param session: The Session to use to make requests. :param suppress_no_index: Whether to ignore the --no-index option when constructing the SearchScope object. """ index_urls = [options.index_url] + options.extra_index_urls if options.no_index and not suppress_no_index: logger.debug( 'Ignoring indexes: %s', ','.join(redact_auth_from_url(url) for url in index_urls), ) index_urls = [] # Make sure find_links is a list before passing to create(). find_links = options.find_links or [] search_scope = SearchScope.create( find_links=find_links, index_urls=index_urls, ) link_collector = LinkCollector(session=session, search_scope=search_scope) return link_collector
def make_test_finder( find_links=None, # type: Optional[List[str]] index_urls=None, # type: Optional[List[str]] allow_all_prereleases=False, # type: bool trusted_hosts=None, # type: Optional[Iterable[str]] session=None, # type: Optional[PipSession] target_python=None, # type: Optional[TargetPython] ): # type: (...) -> PackageFinder """ Create a PackageFinder for testing purposes. """ if find_links is None: find_links = [] if index_urls is None: index_urls = [] if session is None: session = PipSession() search_scope = SearchScope.create( find_links=find_links, index_urls=index_urls, ) return PackageFinder.create( search_scope=search_scope, allow_yanked=True, allow_all_prereleases=allow_all_prereleases, trusted_hosts=trusted_hosts, session=session, target_python=target_python, )
def patch_link_collection( computation_backend: ComputationBackend, nightly: bool ) -> Iterator[None]: base = "https://download.pytorch.org/whl/" url = ( f"nightly/{computation_backend}/torch_nightly.html" if nightly else "torch_stable.html" ) search_scope = SearchScope.create([urljoin(base, url)], []) @contextlib.contextmanager def context(args: Tuple[LinkCollector, str], kwargs: Any) -> Iterator[None]: self, project_name, *_ = args if project_name not in PYTORCH_DISTRIBUTIONS: yield return with mock.patch.object(self, "search_scope", search_scope): yield with apply_patch( "pip._internal.index.collector.LinkCollector.collect_links", context=context, # type: ignore[arg-type] ): yield
def make_test_search_scope( find_links=None, # type: Optional[List[str]] index_urls=None, # type: Optional[List[str]] ): if find_links is None: find_links = [] if index_urls is None: index_urls = [] return SearchScope.create(find_links=find_links, index_urls=index_urls)
def make_search_scope(options, suppress_no_index=False): # type: (Values, bool) -> SearchScope """ :param suppress_no_index: Whether to ignore the --no-index option when constructing the SearchScope object. """ index_urls = [options.index_url] + options.extra_index_urls if options.no_index and not suppress_no_index: logger.debug( 'Ignoring indexes: %s', ','.join(redact_password_from_url(url) for url in index_urls), ) index_urls = [] # Make sure find_links is a list before passing to create(). find_links = options.find_links or [] search_scope = SearchScope.create( find_links=find_links, index_urls=index_urls, ) return search_scope
def make_pytorch_link_collector( session: PipSession, url: str = "https://download.pytorch.org/whl/torch_stable.html" ) -> LinkCollector: search_scope = SearchScope.create(find_links=[url], index_urls=[]) return LinkCollector(session=session, search_scope=search_scope)