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

Pin PyScript #16

Merged
merged 6 commits into from
Dec 10, 2024
Merged

Pin PyScript #16

merged 6 commits into from
Dec 10, 2024

Conversation

rmartin16
Copy link
Member

@rmartin16 rmartin16 commented Oct 11, 2024

Changes

  • PyScript deprecated latest and requires pinning for newer versions
  • <py-script> can just be <script type="py"> now
  • PyScript now enables a top-level loop by default; I added async="false" to disable it
  • <py-config> isn't necessary since it can be specified via <script type="py" config="pyscript.toml">

Notes

  • I think that ideally the PyScript version would live in Briefcase...or via the method I'm working on in Move logic to determine support revision from templates briefcase#1943. But I'll leave that to future work I think
  • I can't figure out a good method to stop Toga's warnings from showing in the page content
    • Although, adding import warnings; warnings.filterwarnings("ignore") to index.html technically works....

BRIEFCASE_REPO: https://github.com/mhsmith/briefcase
BRIEFCASE_REF: pyscript-2024.11.1

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

- PyScript deprecated latest and requires pinning for newer versions
@rmartin16
Copy link
Member Author

Also, I'm a bit mystified by PyScript's configuration. For instance, I find the PR where [splashscreen] was apparently added and where autoclose would be implemented in the code....but I can't find any reference to it in the documentation....so, I don't know if this is still valid config. Similarly, I don't know if terminal = false still does anything; they added a terminal attribute for the <script type="py"> tag 🤷🏼‍♂️

@rmartin16 rmartin16 marked this pull request as ready for review October 11, 2024 17:37
@freakboy3742
Copy link
Member

freakboy3742 commented Oct 12, 2024

Also, I'm a bit mystified by PyScript's configuration. For instance, I find the PR where [splashscreen] was apparently added and where autoclose would be implemented in the code....but I can't find any reference to it in the documentation....so, I don't know if this is still valid config. Similarly, I don't know if terminal = false still does anything; they added a terminal attribute for the <script type="py"> tag 🤷🏼‍♂️

Pyscript has definitely gone through some big changes since I last did a big Toga update; most of those changes have been very welcome (distancing "getting Python working in the browser" from "having opinions about look and feel"). So - the splash screen handling has definitely been removed; and terminal handling has... changed. Part of that seems to be a new default handler for stderr which puts stderr content into the DOM. All documentation says should be possible to disable with plugins = ["!error"]... but this doesn't seem to be working for me. The simple fix is to add a div.py-error { display: none } CSS modification; but that doesn't seem ideal. I've poked PyScript support to get some guidance on this (pyscript/pyscript#2220).

However, we also need to fix some other issues that have slipped in as a result of API updates.

  • Button handlers no longer seem to work. Pressing the button on Tutorial 0 doesn't cause anything to appear in the console.
  • Style appears to have been lost from dialogs. The about dialog in Tutorial 0 displays in "browser default serif", not the Shoelace sans-serif default.
  • We probably need to add a Splash screen, so that we don't get a blank page on load.

On the last point, I'm not sure if that should be a Toga concern or a Briefcase concern - at least for the moment, I suspect it needs to be a Briefcase concern, because Toga can't provide any code that will contribute to the "pre-javascript executing" state of the page. I started looking broadly at this problem in beeware/briefcase#1285; that set of changes would provide a mechanism for a wheel to contribute content to the Briefcase-generated HTML. However, I've been distracted with Py3.13 and getting binary wheels working for the last year, so I haven't been able to give the web backend the attention it needs.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

This is definitely a set of changes we should make; but we need to fix the behavior change issues flagged (which might require a Toga change as well to adapt how button handlers are attached)

@rmartin16
Copy link
Member Author

Makes sense :) I rather doubt I will further pursue additional efforts then to bring support back up to date; I am mostly intrigued because PyScript is particularly interesting...but it's also at the edge of a lot of my knowledge. So, I'll leave to your discretion to just close this PR...or possibly expand upon it...whatever this case is fine with me.

@mhsmith mhsmith mentioned this pull request Dec 9, 2024
4 tasks
@mhsmith
Copy link
Member

mhsmith commented Dec 9, 2024

I've updated to PyScript 2024.11.1, and added a corresponding Briefcase PR to remove the obsolete configuration settings:

  • Button handlers no longer seem to work. Pressing the button on Tutorial 0 doesn't cause anything to appear in the console.

It works fine for me in both Chrome and Safari.

  • Style appears to have been lost from dialogs. The about dialog in Tutorial 0 displays in "browser default serif", not the Shoelace sans-serif default.

Fixed in beeware/toga#3035.

@mhsmith mhsmith requested a review from freakboy3742 December 9, 2024 22:19
Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

I've made 2 small changes:

  1. I've added an animation throb to the splash screen
  2. I've added an initial templated pyscript.toml file that turns on the "official" way to hide error output, rather than a CSS-based approach. This config file will be overwritten by the current mainline Briefcase; but I've updated the Briefcase PR to read-and-rewrite pyscript.toml if it the template provides it. This should allow us to accomodate future pyscript.toml changes without needing a Briefcase change (unless there's a change to the format for packages...)

I'm happy with where this is right now; leaving for @mhsmith to cross-check and merge these changes.

@mhsmith
Copy link
Member

mhsmith commented Dec 10, 2024

In that case, the CSS to hide the stderr should be unnecessary, so I've removed it.

@mhsmith mhsmith merged commit 6532867 into beeware:main Dec 10, 2024
4 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.

3 participants