Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow enabling/disabling REPL code execution in the Replite directive #245

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

agriyakhetarpal
Copy link
Member

@agriyakhetarpal agriyakhetarpal commented Jan 1, 2025

Description

This pull request exposes functionality added upstream via jupyterlite/jupyterlite#1547 and released in jupyterlite-core version 0.5.0.

In particular, this enables the act of enabling/disabling the code execution for the Replite directive, so it is now possible for the REPL not to load the Pyodide kernel automatically and instead wait for the user's input. It can be controlled via the replite_auto_execute option globally or via the :execute: [True/False] option on a per-directive basis as an override. This appends &execute=0 to the REPL URL if False.

It is to be noted that while we support jupyterlite-core >=0.2,<0.6 via #238, this option requires jupyterlite >= 0.5 to work, and there is no effect for versions prior to jupyterlite-core 0.5.

Closes #244

Changes made

  • The addition of a replite_auto_execute global configuration option, an :execute: option for the Replite directive, and corresponding URL handling
  • Both options documented for readers

Additional context

This will help us make progress on matplotlib/matplotlib#22634

@agriyakhetarpal agriyakhetarpal added the enhancement New feature or request label Jan 1, 2025
@agriyakhetarpal agriyakhetarpal changed the title Allow enabling/disabling REPL code execution in Replite Allow enabling/disabling REPL code execution in the Replite directive Jan 1, 2025
@agriyakhetarpal agriyakhetarpal added this to the 0.18.0 milestone Jan 2, 2025
docs/configuration.md Outdated Show resolved Hide resolved
docs/directives/replite.md Show resolved Hide resolved

if execute == "false":
self.options["execute"] = "0"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we raise if execute is an invalid value ?

And also I'm likely to misunderstand something, (sorry need to restart brain in 2025) but you pop'ed execute from self.options inconditionally, but put it back only if false, should you maybe:

elif execute in ('true', '1'): # i'm assuming 1 is a possible value
    self.options['execute'] = '1'

plus, if self.options['execute'] is '0' originally, you also don't put '0' back in.

And finally, maybe move the new_tab = self.options.pop("new_tab", False), below the new code (even lower to like 447 before if new_tab, or even change to

if self.options.pop("new_tab", False):

to avoid intermediary variables used only once.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I messed something up here – it would be better that our behaviour is similar to :new_tab:, such that we keep only True or False as acceptable options, and we handle the 1/0 conversion internally (without lower()ing anything).

Is this better with 00481a4?

pyproject.toml Outdated Show resolved Hide resolved
@agriyakhetarpal
Copy link
Member Author

Thanks for the reviews – rebasing and applying the suggested changes in a moment

@agriyakhetarpal agriyakhetarpal marked this pull request as ready for review January 9, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port no_execute option for the Replite directive
3 participants