@@ -129,8 +129,17 @@ async def get_transformed_code(argv: list[str]) -> typing.Optional[str]:
129
129
130
130
131
131
async def get_action_kwargs (argv : list [str ]) -> tuple [typing .Optional [str ], dict ]:
132
- """Get the arguments to `piplite` subcommands from CLI-like tokens."""
132
+ """Get the arguments to `piplite` subcommands from CLI-like tokens.
133
133
134
+ This function handles both command-line arguments and requirements files,
135
+ ensuring that index URLs from either source are properly captured and used.
136
+
137
+ The precedence order is:
138
+ 1. Command line --index-url flag
139
+ 2. Index URL specified in requirements file
140
+ 3. Default system index
141
+
142
+ """
134
143
parser = _get_parser ()
135
144
136
145
try :
@@ -152,7 +161,7 @@ async def get_action_kwargs(argv: list[str]) -> tuple[typing.Optional[str], dict
152
161
context = RequirementsContext ()
153
162
154
163
# If CLI index URL is provided, it should override within-file-level
155
- # index URL for all requirements.
164
+ # index URL for all requirements and take precedence .
156
165
if args .index_url :
157
166
context .index_url = args .index_url
158
167
@@ -170,21 +179,17 @@ async def get_action_kwargs(argv: list[str]) -> tuple[typing.Optional[str], dict
170
179
all_requirements .extend (context .requirements )
171
180
172
181
if all_requirements :
173
- by_index = {}
174
- file_index_url = None
182
+ kwargs [ "requirements" ] = []
183
+ active_index_url = None
175
184
176
185
for req , idx in all_requirements :
177
- if idx :
178
- file_index_url = idx
179
- by_index . setdefault ( file_index_url , []) .append (req )
186
+ if idx is not None :
187
+ active_index_url = idx
188
+ kwargs [ "requirements" ] .append (req )
180
189
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 )
190
+ # Set the final index URL, if we found one
191
+ if active_index_url is not None :
192
+ kwargs ["index_urls" ] = active_index_url
188
193
189
194
if args .pre :
190
195
kwargs ["pre" ] = True
0 commit comments