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

PyEditor - process(code) ability #2053

Merged
merged 4 commits into from May 8, 2024

Conversation

WebReflection
Copy link
Contributor

Description

After yesterday meeting with Tufts, we've realized the PyEditor has no way to process code same way the PyTerminal does.

This MR would like to expose the same API we have with the terminal, when the script with the type py-editor or mpy-editor actually gets attached a process field, among a target one when is not setup, where such process(code) will return a promise that resolves (or rejects) after the provided code has been evaluated.

Please note the evaluation won't automatically print results in the editor output as I think that might be undesired (but we could change that if needed / requested).

/cc @ntoll @JeffersGlass

Changes

  • attach a method to the script that can pass along the code to evaluate to the interpreter
  • notify bubbling up to the window (global) whenever a py-editor or an mpy-editor has been bootstrapped
  • test that everything actually works as expected

Documentation / Example

<script>
addEventListener('mpy-editor', async event => {
  // the script is the target of this event
  const { target: script } = event;
  // it can process any Python code
  await script.process('globalValue = 123');
});
</script>
<script type="mpy-editor">
# run will show the previously setup value
print(globalValue) # 123
</script>

Once the mpy-editor event is triggered, if the script was a setup one, it will process code after the setup is complete. In every other case, it will process code either before the code in the editor has run at least once, or after such code run already, it's up to the user.

Checklist

  • All tests pass locally
  • I have updated CHANGELOG.md
  • I have created documentation for this(if applicable)

WebReflection and others added 4 commits May 8, 2024 09:58
* Even better PyEditor offline use case

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@WebReflection WebReflection merged commit 04222b0 into pyscript:main May 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants