@@ -56,6 +56,7 @@ class ComponentInfo():
56
56
base_image : str = _DEFAULT_BASE_IMAGE
57
57
packages_to_install : Optional [List [str ]] = None
58
58
pip_index_urls : Optional [List [str ]] = None
59
+ pip_trusted_hosts : Optional [List [str ]] = None
59
60
60
61
61
62
# A map from function_name to components. This is always populated when a
@@ -69,22 +70,33 @@ def _python_function_name_to_component_name(name):
69
70
return name_with_spaces [0 ].upper () + name_with_spaces [1 :]
70
71
71
72
72
- def make_index_url_options (pip_index_urls : Optional [List [str ]]) -> str :
73
+ def make_index_url_options (pip_index_urls : Optional [List [str ]], pip_trusted_hosts : Optional [ List [ str ]] ) -> str :
73
74
"""Generates index url options for pip install command based on provided
74
75
pip_index_urls.
75
76
76
77
Args:
77
78
pip_index_urls: Optional list of pip index urls
79
+ pip_trusted_hosts: Optional list of pip trust hosts
78
80
79
81
Returns:
80
82
- Empty string if pip_index_urls is empty/None.
81
- - '--index-url url --trusted-host url ' if pip_index_urls contains 1
83
+ - '--index-url url ' if pip_index_urls contains 1
82
84
url
83
- - the above followed by '--extra-index-url url --trusted-host url '
85
+ - the above followed by '--extra-index-url url '
84
86
for
85
87
each next url in pip_index_urls if pip_index_urls contains more than 1
86
88
url
87
89
90
+ - pip_trusted_hosts was added later. In this case, if pip_trusted_hosts is None or empty
91
+ - the above followed by '--trusted-host url '
92
+ for
93
+ each url in pip_index_urls
94
+
95
+ - if pip_trusted_hosts is greater than 0
96
+ - the above followed by '--trusted-host url '
97
+ for
98
+ each url in pip_trusted_hosts
99
+
88
100
Note: In case pip_index_urls is not empty, the returned string will
89
101
contain space at the end.
90
102
"""
@@ -94,11 +106,21 @@ def make_index_url_options(pip_index_urls: Optional[List[str]]) -> str:
94
106
index_url = pip_index_urls [0 ]
95
107
extra_index_urls = pip_index_urls [1 :]
96
108
97
- options = [f'--index-url { index_url } --trusted-host { index_url } ' ]
109
+ options = [f'--index-url { index_url } ' ]
98
110
options .extend (
99
- f'--extra-index-url { extra_index_url } --trusted-host { extra_index_url } '
111
+ f'--extra-index-url { extra_index_url } '
100
112
for extra_index_url in extra_index_urls )
101
113
114
+ if pip_trusted_hosts is None or len (pip_trusted_hosts ) == 0 :
115
+ options = [f'--trusted-host { index_url } ' ]
116
+ options .extend (
117
+ f'--trusted-host { extra_index_url } '
118
+ for extra_index_url in extra_index_urls )
119
+ else :
120
+ options .extend (
121
+ f'--trusted-host { trusted_host } '
122
+ for trusted_host in pip_trusted_hosts )
123
+
102
124
return ' ' .join (options ) + ' '
103
125
104
126
@@ -126,6 +148,7 @@ def _get_packages_to_install_command(
126
148
packages_to_install : Optional [List [str ]] = None ,
127
149
install_kfp_package : bool = True ,
128
150
target_image : Optional [str ] = None ,
151
+ pip_trusted_hosts : Optional [List [str ]] = None ,
129
152
) -> List [str ]:
130
153
packages_to_install = packages_to_install or []
131
154
kfp_in_user_pkgs = any (pkg .startswith ('kfp' ) for pkg in packages_to_install )
@@ -136,7 +159,7 @@ def _get_packages_to_install_command(
136
159
if not inject_kfp_install and not packages_to_install :
137
160
return []
138
161
pip_install_strings = []
139
- index_url_options = make_index_url_options (pip_index_urls )
162
+ index_url_options = make_index_url_options (pip_index_urls , pip_trusted_hosts )
140
163
141
164
if inject_kfp_install :
142
165
if kfp_package_path :
@@ -517,6 +540,7 @@ def create_component_from_func(
517
540
output_component_file : Optional [str ] = None ,
518
541
install_kfp_package : bool = True ,
519
542
kfp_package_path : Optional [str ] = None ,
543
+ pip_trusted_hosts : Optional [List [str ]] = None ,
520
544
) -> python_component .PythonComponent :
521
545
"""Implementation for the @component decorator.
522
546
@@ -530,6 +554,7 @@ def create_component_from_func(
530
554
kfp_package_path = kfp_package_path ,
531
555
packages_to_install = packages_to_install ,
532
556
pip_index_urls = pip_index_urls ,
557
+ pip_trusted_hosts = pip_trusted_hosts ,
533
558
)
534
559
535
560
command = []
@@ -575,7 +600,8 @@ def create_component_from_func(
575
600
output_component_file = output_component_file ,
576
601
base_image = base_image ,
577
602
packages_to_install = packages_to_install ,
578
- pip_index_urls = pip_index_urls )
603
+ pip_index_urls = pip_index_urls ,
604
+ pip_trusted_hosts = pip_trusted_hosts )
579
605
580
606
if REGISTERED_MODULES is not None :
581
607
REGISTERED_MODULES [component_name ] = component_info
0 commit comments