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
+
30
33
#: a well-known file name respected by the rest of the build chain
31
34
ALL_JSON = "/all.json"
32
35
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
- }
36
+ #: default index URLs to use when no specific index URLs are provided
37
+ _PIPLITE_DEFAULT_INDEX_URLS = None
48
38
49
39
50
40
class PiplitePyPIDisabled (ValueError ):
@@ -107,7 +97,7 @@ async def _query_package(
107
97
if pypi_json_from_index :
108
98
return pypi_json_from_index
109
99
110
- if _PIPLITE_INTERNAL_FLAGS [ "disable_pypi" ] :
100
+ if _PIPLITE_DISABLE_PYPI :
111
101
raise PiplitePyPIDisabled (
112
102
f"{ name } could not be installed: PyPI fallback is disabled"
113
103
)
@@ -132,30 +122,28 @@ async def _install(
132
122
"""Invoke micropip.install with a patch to get data from local indexes"""
133
123
134
124
try :
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
-
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
+ )
148
129
149
130
if verbose :
150
- logger .info (f"Installing with arguments : { install_args } " )
131
+ logger .info (f"Installing with index URLs : { effective_index_urls } " )
151
132
152
133
with patch ("micropip.package_index.query_package" , _query_package ):
153
- return await micropip .install (** install_args )
154
-
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
+ )
155
143
except Exception as e :
156
- if install_args . get ( "index_urls" ) :
144
+ if effective_index_urls :
157
145
logger .error (
158
- f"Failed to install using index URLs { install_args [ 'index_urls' ] } : { e } "
146
+ f"Failed to install using index URLs { effective_index_urls } : { e } "
159
147
)
160
148
raise
161
149
0 commit comments