Skip to content

Commit a5e9565

Browse files
Handle tuple unpacking better
1 parent e7d3818 commit a5e9565

File tree

1 file changed

+36
-23
lines changed
  • packages/pyodide-kernel/py/piplite/piplite

1 file changed

+36
-23
lines changed

packages/pyodide-kernel/py/piplite/piplite/cli.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,38 +142,51 @@ async def get_action_kwargs(argv: list[str]) -> tuple[typing.Optional[str], dict
142142
action = args.action
143143

144144
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 = []
156146

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)
159149

150+
# Process requirements files
160151
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
166172
by_index = {}
167-
for req, idx in kwargs["requirements"]:
173+
for req, idx in all_requirements:
168174
by_index.setdefault(idx, []).append(req)
169175

170-
# Install each group with its index URL
171-
all_requirements = []
176+
kwargs["requirements"] = []
172177
for idx, reqs in by_index.items():
173178
if idx:
174179
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
177190

178191
return action, kwargs
179192

0 commit comments

Comments
 (0)