19
19
from pipenv .environment import Environment
20
20
from pipenv .environments import Setting , is_in_virtualenv , normalize_pipfile_path
21
21
from pipenv .patched .pip ._internal .commands .install import InstallCommand
22
+ from pipenv .patched .pip ._internal .configuration import Configuration
23
+ from pipenv .patched .pip ._internal .exceptions import ConfigurationError
22
24
from pipenv .patched .pip ._vendor import pkg_resources
23
25
from pipenv .utils .constants import is_type_checking
24
26
from pipenv .utils .dependencies import (
28
30
pep423_name ,
29
31
python_version ,
30
32
)
31
- from pipenv .utils .internet import get_url_name , is_valid_url , proper_case
33
+ from pipenv .utils .internet import get_url_name , is_pypi_url , is_valid_url , proper_case
32
34
from pipenv .utils .shell import (
33
35
find_requirements ,
34
36
find_windows_executable ,
@@ -131,7 +133,39 @@ def __init__(self, python_version=None, chdir=True):
131
133
self ._build_system = {"requires" : ["setuptools" , "wheel" ]}
132
134
self .python_version = python_version
133
135
self .s = Setting ()
134
- if self .s .PIPENV_TEST_INDEX :
136
+ # Load Pip configuration and get items
137
+ self .configuration = Configuration (isolated = False , load_only = None )
138
+ self .configuration .load ()
139
+ pip_conf_indexes = []
140
+ for section_key , value in self .configuration .items ():
141
+ key_parts = section_key .split ("." , 1 )
142
+ if key_parts [1 ] == "index-url" :
143
+ try :
144
+ trusted_hosts = self .configuration .get_value (
145
+ f"{ key_parts [0 ]} .trusted-host"
146
+ )
147
+ except ConfigurationError :
148
+ trusted_hosts = []
149
+ pip_conf_indexes .append (
150
+ {
151
+ "url" : value ,
152
+ "verify_ssl" : not any (
153
+ trusted_host in value for trusted_host in trusted_hosts
154
+ )
155
+ and "https://" in value ,
156
+ "name" : f"pip_conf_index_{ key_parts [0 ]} " ,
157
+ }
158
+ )
159
+
160
+ if pip_conf_indexes :
161
+ self .default_source = None
162
+ for pip_conf_index in pip_conf_indexes :
163
+ if self .default_source is None :
164
+ self .default_source = pip_conf_index
165
+ if is_pypi_url (pip_conf_index ["url" ]):
166
+ self .default_source = pip_conf_index
167
+ pip_conf_indexes .remove (self .default_source )
168
+ elif self .s .PIPENV_TEST_INDEX :
135
169
self .default_source = {
136
170
"url" : self .s .PIPENV_TEST_INDEX ,
137
171
"verify_ssl" : True ,
@@ -144,9 +178,10 @@ def __init__(self, python_version=None, chdir=True):
144
178
"name" : "pypi" ,
145
179
}
146
180
147
- plette .pipfiles .DEFAULT_SOURCE_TOML = (
148
- f"[[source]]\n { toml .dumps (self .default_source )} "
149
- )
181
+ default_sources_toml = f"[[source]]\n { toml .dumps (self .default_source )} "
182
+ for pip_conf_index in pip_conf_indexes :
183
+ default_sources_toml += f"\n \n [[source]]\n { toml .dumps (pip_conf_index )} "
184
+ plette .pipfiles .DEFAULT_SOURCE_TOML = default_sources_toml
150
185
151
186
# Hack to skip this during pipenv run, or -r.
152
187
if ("run" not in sys .argv ) and chdir :
0 commit comments