@@ -151,6 +151,11 @@ async def get_action_kwargs(argv: list[str]) -> tuple[typing.Optional[str], dict
151
151
for req_file in args .requirements or []:
152
152
context = RequirementsContext ()
153
153
154
+ # If CLI index URL is provided, it should override within-file-level
155
+ # index URL for all requirements.
156
+ if args .index_url :
157
+ context .index_url = args .index_url
158
+
154
159
if not Path (req_file ).exists ():
155
160
warn (f"piplite could not find requirements file { req_file } " )
156
161
continue
@@ -165,18 +170,21 @@ async def get_action_kwargs(argv: list[str]) -> tuple[typing.Optional[str], dict
165
170
all_requirements .extend (context .requirements )
166
171
167
172
if all_requirements :
168
- kwargs [ "requirements" ] = []
169
- used_index = None
173
+ by_index = {}
174
+ file_index_url = None
170
175
171
176
for req , idx in all_requirements :
172
177
if idx :
173
- used_index = idx
174
- kwargs [ "requirements" ] .append (req )
178
+ file_index_url = idx
179
+ by_index . setdefault ( file_index_url , []) .append (req )
175
180
176
- # Set the index URL if one was found (either passed to the CLI or
177
- # passed within the requirements file)
178
- if used_index :
179
- kwargs ["index_urls" ] = used_index
181
+ # Build final kwargs. We set the index URL if one was found
182
+ # (either passed to the CLI or passed within the requirements file)
183
+ kwargs ["requirements" ] = []
184
+ for idx , reqs in by_index .items ():
185
+ if idx :
186
+ kwargs ["index_urls" ] = idx
187
+ kwargs ["requirements" ].extend (reqs )
180
188
181
189
if args .pre :
182
190
kwargs ["pre" ] = True
0 commit comments