Skip to content

Comments

fix: initialize constraints list for install action#262

Open
JCapul wants to merge 1 commit intojupyterlite:mainfrom
JCapul:JCapul-patch-1
Open

fix: initialize constraints list for install action#262
JCapul wants to merge 1 commit intojupyterlite:mainfrom
JCapul:JCapul-patch-1

Conversation

@JCapul
Copy link

@JCapul JCapul commented Feb 18, 2026

Hi,
I hit a bug in the currently deployed version of JupyterLite (the try out version) when trying to use piplite install with a constraint file. I had a look at the code and realized the install action kwargs was not initialized for the "constraints" entry.
So here is a very quick fix.

I didn't find any related tests to update as well, so I thought I'd just issue this PR.

Let me know if I should update any other part to make it a proper fix.

To reproduce: %pip install -c pip_list.txt pep8

Then I got this error:

Traceback (most recent call last):
  File "/lib/python3.13/site-packages/pyodide_kernel/kernel.py", line 104, in run
    code = await self.lite_transform_manager.transform_cell(code)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.13/site-packages/pyodide_kernel/litetransform.py", line 32, in transform_cell
    lines = await transform(lines)
            ^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.13/site-packages/pyodide_kernel/litetransform.py", line 89, in pip_magic
    transformed_code = await piplite.cli.get_transformed_code(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        shlex.split(pip_match[2])
        ^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/lib/python3.13/site-packages/piplite/cli.py", line 116, in get_transformed_code
    action, kwargs = await get_action_kwargs(argv)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.13/site-packages/piplite/cli.py", line 166, in get_action_kwargs
    kwargs["constraints"] += [spec]
    ~~~~~~^^^^^^^^^^^^^^^
KeyError: 'constraints'

The "constraints" entry in install action kwargs was not initialized leading to an exception when using the --constraints option.
@github-actions
Copy link
Contributor

lite-badge 👈 Try it on ReadTheDocs

@jtpio jtpio added the bug Something isn't working label Feb 19, 2026
Copy link
Contributor

@bollwyvl bollwyvl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


if action == "install":
kwargs["requirements"] = args.packages
kwargs["constraints"] = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine, or could be a kwargs.setdefault("constraints", []).append() below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for the review, I find it simpler and more explicit as it is, but let me know if you prefer it the other way, no pb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants