Can I use URLS in brython(pythonpath:["http://server.modules"]?

52 views
Skip to first unread message

Carlo Oliveira

unread,
Sep 24, 2024, 2:37:06 PM9/24/24
to brython
I have some contents and Brython apps running in a server.
I am handling the contents with docsify and I can specify
basePath: docBasePath
where docBasePath can be of form "http://someserver"
I have set docBasePath to point at a github raw repo so that
when I commit, content is updated.
However, brython code is bound to local server files and when there is an update I have to redeploy. Since I am using some unstable software, every time I redeploy, apps stop working together, and I have to hack into configurations to bring the site back to life.
If I could serve python paths directly from github I would just have to commit and the apps would update promptly.
I imagine that since docsify can pull the trick, brython could do as well.

Thank you in advance for any advice.

Carlo

Pierre Quentel

unread,
Sep 29, 2024, 2:54:12 AM9/29/24
to brython
Hi Carlo,

I suspect that this is the same issue as https://github.com/brython-dev/brython/issues/2480. I am relaseing version 3.12.5 today, it should fix the bug.

Carlo Oliveira

unread,
Oct 11, 2024, 12:13:28 PM10/11/24
to brython
And Now for Something Completely Different (as John Cleese would say)
There is this new options setup
<brython-options debug="1" cache="true" pythonpath="_prog _core"></brython-options>
It
It worked mostly fine, unless when I try to import something from inside an exec():
Cross-origin request blocked: The Same Origin directive does not allow reading from the remote resource at https://cdnjs.cloudflare.com/ajax/libs/brython/3.12.0/Lib/site-packages/kwarwp.py (reason: missing CORS 'Access-Control-Allow-Origin' header). Status code: 403
Module kwarwp.py is under _core directory, but it is looking up somewhere else.
I had to stick to version 11.3, the last one where import inside exec works. Tried all new ones to no avail.

Pierre Quentel

unread,
Oct 13, 2024, 2:53:59 AM10/13/24
to brython
Hi Carlo,

Sorry, I can't reproduce the issue. The code below successfully imports a module kwarwp.py in directory _core under the html page:

<html>

<head>
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/bry...@3.13.0/brython.min.js">
    </script>
</head>

<brython-options debug="1" pythonpath="_prog _core"></brython-options>

<body>

<script type="text/python">
exec('import kwarwp')
print(kwarwp)
</script>
</body>

</html>



Carlo Oliveira

unread,
Oct 15, 2024, 12:50:47 PM10/15/24
to brython
With 3.11, relative paths worked fine:  pythonpath="_prog _core"
In my code, from inside exec, I called an outside function that imported kwarwp (the code and kwarwp are under directory _core).
It was passed as global in exec call:
exec(self.vit, dict(c__=c, v__=vitollino, kwarwp_prepara=self.prepara))

def prepara(self, mapa):
     from kwarwp.kwarapp import main as kwp_main, Indio

relative path result in code fetcher trying a relative search in 3.12 and above:

with absolute import, it works fine in 3.12 and above:  pythonpath="/_prog /_core"
I reported this so you can investigate if this behavior is harmful and may need correction.
Reply all
Reply to author
Forward
0 new messages