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

New version of Brython doesn't work anymore on Deno #2521

Open
denis-migdal opened this issue Dec 4, 2024 · 7 comments
Open

New version of Brython doesn't work anymore on Deno #2521

denis-migdal opened this issue Dec 4, 2024 · 7 comments

Comments

@denis-migdal
Copy link
Contributor

denis-migdal commented Dec 4, 2024

EDIT: workaround here.

A little bug I encountered when trying to execute Brython inside Deno :

Error: not a url: #python_script_666512880644291
    at Object.$B.strip_host (eval at load_brython (file:///home/demigda/Data/Recherche/Git/VSHS-TS-/index.ts:61:3), <anonymous>:1:2062)
    at Object.$B.run_script (eval at load_brython (file:///home/demigda/Data/Recherche/Git/VSHS-TS-/index.ts:61:3), <anonymous>:1:58356)
    at Object.$B.runPythonSource (eval at load_brython (file:///home/demigda/Data/Recherche/Git/VSHS-TS-/index.ts:61:3), <anonymous>:1:8984
@denis-migdal
Copy link
Contributor Author

Note: with the new versions of Brython, I also have a "inner" is not defined error that I didn't have with this version :
https://github.com/brython-dev/brython/blob/2ba9571d865a60770675f75d128dda0d1e888dcc/www/src/brython.js

@denis-migdal

This comment was marked as outdated.

@denis-migdal

This comment was marked as outdated.

@denis-migdal
Copy link
Contributor Author

denis-migdal commented Dec 6, 2024

ReferenceError: inner is not defined

Seems to occur when I try to execute the following code in Deno (works in the browser) :

#  /Hello World/GET.bry

from browser import self

async def RequestHandler(request, _):
    return self.Response.new("Hello World ;)")

Strangely, the following code does work in Deno :

#  /echo (url)/POST.bry

from browser import self

async def RequestHandler(request, _):
    return self.Response.new(request.url)

@denis-migdal
Copy link
Contributor Author

It seems the inner is not defined error is generated in the py2js step, when converting the Python code to the AST.

@denis-migdal
Copy link
Contributor Author

denis-migdal commented Dec 6, 2024

Okay, now it works by adding :

globalThis.$B  = globalThis.__BRYTHON__ = {};
globalThis.inner = null;

To make Brython work on Deno, I had to :

  1. define the previous symbols globally ;
  2. make $B.isWebBrowser=true ;
  3. make strip_host(url) returning url.
  4. use from browser import self instead of from browser import window

@denis-migdal denis-migdal changed the title Not an URL when calling runPythonSource() in Deno New version of Brython doesn't work anymore on Deno Dec 6, 2024
@denis-migdal
Copy link
Contributor Author

Upgraded my version of Deno.

Had to add :

globalThis.global = {};
globalThis.module = {};

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

No branches or pull requests

1 participant