27
27
#: a cache of available packages
28
28
_PIPLITE_INDICES = {}
29
29
30
- #: don't fall back to pypi.org if a package is not found in _PIPLITE_URLS
31
- _PIPLITE_DISABLE_PYPI = False
32
-
33
30
#: a well-known file name respected by the rest of the build chain
34
31
ALL_JSON = "/all.json"
35
32
36
- #: default index URLs to use when no specific index URLs are provided
37
- _PIPLITE_DEFAULT_INDEX_URLS = None
33
+ #: default arguments for piplite.install
34
+ _PIPLITE_DEFAULT_INSTALL_ARGS = {
35
+ "requirements" : None ,
36
+ "keep_going" : False ,
37
+ "deps" : True ,
38
+ "credentials" : None ,
39
+ "pre" : False ,
40
+ "index_urls" : None ,
41
+ "verbose" : False ,
42
+ }
43
+
44
+ # Internal flags that affect package lookup behavior
45
+ _PIPLITE_INTERNAL_FLAGS = {
46
+ "disable_pypi" : False , # don't fall back to pypi.org if package not found in _PIPLITE_URLS
47
+ }
38
48
39
49
40
50
class PiplitePyPIDisabled (ValueError ):
@@ -97,7 +107,7 @@ async def _query_package(
97
107
if pypi_json_from_index :
98
108
return pypi_json_from_index
99
109
100
- if _PIPLITE_DISABLE_PYPI :
110
+ if _PIPLITE_INTERNAL_FLAGS [ "disable_pypi" ] :
101
111
raise PiplitePyPIDisabled (
102
112
f"{ name } could not be installed: PyPI fallback is disabled"
103
113
)
@@ -122,28 +132,30 @@ async def _install(
122
132
"""Invoke micropip.install with a patch to get data from local indexes"""
123
133
124
134
try :
125
- # Use default index URLs if none provided and defaults exist
126
- effective_index_urls = (
127
- index_urls if index_urls is not None else _PIPLITE_DEFAULT_INDEX_URLS
128
- )
135
+ install_args = _PIPLITE_DEFAULT_INSTALL_ARGS .copy ()
136
+
137
+ provided_args = {
138
+ "requirements" : requirements ,
139
+ "keep_going" : keep_going ,
140
+ "deps" : deps ,
141
+ "credentials" : credentials ,
142
+ "pre" : pre ,
143
+ "index_urls" : index_urls ,
144
+ "verbose" : verbose ,
145
+ }
146
+ install_args .update ({k : v for k , v in provided_args .items () if v is not None })
147
+
129
148
130
149
if verbose :
131
- logger .info (f"Installing with index URLs : { effective_index_urls } " )
150
+ logger .info (f"Installing with arguments : { install_args } " )
132
151
133
152
with patch ("micropip.package_index.query_package" , _query_package ):
134
- return await micropip .install (
135
- requirements = requirements ,
136
- keep_going = keep_going ,
137
- deps = deps ,
138
- credentials = credentials ,
139
- pre = pre ,
140
- index_urls = effective_index_urls ,
141
- verbose = verbose ,
142
- )
153
+ return await micropip .install (** install_args )
154
+
143
155
except Exception as e :
144
- if effective_index_urls :
156
+ if install_args . get ( "index_urls" ) :
145
157
logger .error (
146
- f"Failed to install using index URLs { effective_index_urls } : { e } "
158
+ f"Failed to install using index URLs { install_args [ 'index_urls' ] } : { e } "
147
159
)
148
160
raise
149
161
0 commit comments