@@ -142,38 +142,51 @@ async def get_action_kwargs(argv: list[str]) -> tuple[typing.Optional[str], dict
142
142
action = args .action
143
143
144
144
if action == "install" :
145
- if args .index_url :
146
- # If there's a CLI index URL, use it for command-line packages
147
- kwargs ["requirements" ] = [(pkg , args .index_url ) for pkg in args .packages ]
148
- else :
149
- kwargs ["requirements" ] = [(pkg , None ) for pkg in args .packages ]
150
-
151
- if args .pre :
152
- kwargs ["pre" ] = True
153
-
154
- if args .no_deps :
155
- kwargs ["deps" ] = False
145
+ all_requirements = []
156
146
157
- if args .verbose :
158
- kwargs [ "keep_going" ] = True
147
+ if args .packages :
148
+ all_requirements . extend (( pkg , args . index_url ) for pkg in args . packages )
159
149
150
+ # Process requirements files
160
151
for req_file in args .requirements or []:
161
- reqs_with_indices = await _packages_from_requirements_file (Path (req_file ))
162
- kwargs ["requirements" ].extend (reqs_with_indices )
163
-
164
- # Convert requirements to proper format for piplite.install
165
- if kwargs .get ("requirements" ):
152
+ context = RequirementsContext ()
153
+ # If we have a CLI index URL, set it as the initial context
154
+ if args .index_url :
155
+ context .index_url = args .index_url
156
+
157
+ if not Path (req_file ).exists ():
158
+ warn (f"piplite could not find requirements file { req_file } " )
159
+ continue
160
+
161
+ for line_no , line in enumerate (
162
+ Path (req_file ).read_text (encoding = "utf-8" ).splitlines ()
163
+ ):
164
+ await _packages_from_requirements_line (
165
+ Path (req_file ), line_no + 1 , line , context
166
+ )
167
+
168
+ all_requirements .extend (context .requirements )
169
+
170
+ if all_requirements :
171
+ # Group requirements by index URL
166
172
by_index = {}
167
- for req , idx in kwargs [ "requirements" ] :
173
+ for req , idx in all_requirements :
168
174
by_index .setdefault (idx , []).append (req )
169
175
170
- # Install each group with its index URL
171
- all_requirements = []
176
+ kwargs ["requirements" ] = []
172
177
for idx , reqs in by_index .items ():
173
178
if idx :
174
179
kwargs ["index_urls" ] = idx
175
- all_requirements .extend (reqs )
176
- kwargs ["requirements" ] = all_requirements
180
+ kwargs ["requirements" ].extend (reqs )
181
+
182
+ if args .pre :
183
+ kwargs ["pre" ] = True
184
+
185
+ if args .no_deps :
186
+ kwargs ["deps" ] = False
187
+
188
+ if args .verbose :
189
+ kwargs ["keep_going" ] = True
177
190
178
191
return action , kwargs
179
192
0 commit comments