@@ -513,6 +513,39 @@ class PackageFinder(object):
513
513
514
514
def __init__ (
515
515
self ,
516
+ candidate_evaluator , # type: CandidateEvaluator
517
+ find_links , # type: List[str]
518
+ index_urls , # type: List[str]
519
+ secure_origins , # type: List[SecureOrigin]
520
+ session , # type: PipSession
521
+ allow_all_prereleases = False , # type: bool
522
+ format_control = None , # type: Optional[FormatControl]
523
+ ):
524
+ # type: (...) -> None
525
+ """
526
+ This constructor is primarily meant to be used by the create() class
527
+ method and from tests.
528
+
529
+ :param candidate_evaluator: A CandidateEvaluator object.
530
+ :param session: The Session to use to make requests.
531
+ :param allow_all_prereleases: Whether to allow all pre-releases.
532
+ :param format_control: A FormatControl object, used to control
533
+ the selection of source packages / binary packages when consulting
534
+ the index and links.
535
+ """
536
+ format_control = format_control or FormatControl (set (), set ())
537
+
538
+ self .candidate_evaluator = candidate_evaluator
539
+ self .find_links = find_links
540
+ self .index_urls = index_urls
541
+ self .secure_origins = secure_origins
542
+ self .session = session
543
+ self .allow_all_prereleases = allow_all_prereleases
544
+ self .format_control = format_control
545
+
546
+ @classmethod
547
+ def create (
548
+ cls ,
516
549
find_links , # type: List[str]
517
550
index_urls , # type: List[str]
518
551
allow_all_prereleases = False , # type: bool
@@ -525,9 +558,12 @@ def __init__(
525
558
implementation = None , # type: Optional[str]
526
559
prefer_binary = False # type: bool
527
560
):
528
- # type: (...) -> None
561
+ # type: (...) -> PackageFinder
529
562
"""Create a PackageFinder.
530
563
564
+ :param trusted_hosts: Domains that we won't emit warnings for when
565
+ not using HTTPS.
566
+ :param session: The Session to use to make requests.
531
567
:param format_control: A FormatControl object or None. Used to control
532
568
the selection of source packages / binary packages when consulting
533
569
the index and links.
@@ -547,7 +583,7 @@ def __init__(
547
583
"""
548
584
if session is None :
549
585
raise TypeError (
550
- "PackageFinder() missing 1 required keyword argument: "
586
+ "PackageFinder.create () missing 1 required keyword argument: "
551
587
"'session'"
552
588
)
553
589
@@ -556,45 +592,34 @@ def __init__(
556
592
# it and if it exists, use the normalized version.
557
593
# This is deliberately conservative - it might be fine just to
558
594
# blindly normalize anything starting with a ~...
559
- self . find_links = [] # type: List[str]
595
+ built_find_links = [] # type: List[str]
560
596
for link in find_links :
561
597
if link .startswith ('~' ):
562
598
new_link = normalize_path (link )
563
599
if os .path .exists (new_link ):
564
600
link = new_link
565
- self .find_links .append (link )
566
-
567
- self .index_urls = index_urls
601
+ built_find_links .append (link )
568
602
569
- self .format_control = format_control or FormatControl (set (), set ())
570
-
571
- # Domains that we won't emit warnings for when not using HTTPS
572
- self .secure_origins = [
603
+ secure_origins = [
573
604
("*" , host , "*" )
574
605
for host in (trusted_hosts if trusted_hosts else [])
575
606
] # type: List[SecureOrigin]
576
607
577
- # Do we want to allow _all_ pre-releases?
578
- self .allow_all_prereleases = allow_all_prereleases
579
-
580
- # The Session we'll use to make requests
581
- self .session = session
582
-
583
608
# The valid tags to check potential found wheel candidates against
584
609
valid_tags = get_supported (
585
610
versions = versions ,
586
611
platform = platform ,
587
612
abi = abi ,
588
613
impl = implementation ,
589
614
)
590
- self . candidate_evaluator = CandidateEvaluator (
615
+ candidate_evaluator = CandidateEvaluator (
591
616
valid_tags = valid_tags , prefer_binary = prefer_binary ,
592
617
)
593
618
594
619
# If we don't have TLS enabled, then WARN if anyplace we're looking
595
620
# relies on TLS.
596
621
if not HAS_TLS :
597
- for link in itertools .chain (self . index_urls , self . find_links ):
622
+ for link in itertools .chain (index_urls , built_find_links ):
598
623
parsed = urllib_parse .urlparse (link )
599
624
if parsed .scheme == "https" :
600
625
logger .warning (
@@ -604,6 +629,16 @@ def __init__(
604
629
)
605
630
break
606
631
632
+ return cls (
633
+ candidate_evaluator = candidate_evaluator ,
634
+ find_links = built_find_links ,
635
+ index_urls = index_urls ,
636
+ secure_origins = secure_origins ,
637
+ session = session ,
638
+ allow_all_prereleases = allow_all_prereleases ,
639
+ format_control = format_control ,
640
+ )
641
+
607
642
def get_formatted_locations (self ):
608
643
# type: () -> str
609
644
lines = []
0 commit comments