Installing and working with Brython

348 views
Skip to first unread message

Pierre Quentel

unread,
Dec 17, 2016, 4:30:08 AM12/17/16
to brython
Hi,

After many trials and errors, the discussion initiated by Glyph on the Github tracker has led to a new way of installing and working with Brython.

A package called brython is now available on the Python Package Index and can be installed like any other module by

pip install brython

To create a Brython environment in an empty folder, run

python -m brython --install


This will install 2 main files : brython.js (the core Brython engine) and brython_stdlib.js (a script with the minified Python source code of the Brython version of the standard distribution ; it is the same as the current py_VFS.js, only with a more explicit name). Another file, demo.html, is included to give a quick overview of what can be done with Brython for web development client-side.

Brython pages will have to load brython.js as usual, plus brython_stdlib.js if the scripts use modules from the standard library. User-defined modules and packages can still be added in the application directory, they will be loaded by Ajax calls.

If the size of brython_stdlib.js is a problem (currently 3.2 Mb), developers can generate another script, brython_modules.js, limited to the modules and packages that are actually used by the application (either from the standard library or user-defined).

For this, a file .bundle-include must be added in the application directory, then run

python -m brython --modules

Because of chained imports it is not always easy to know exactly which modules of the standard library are used ; a way to list them is to run the application in the browser, open the browser console and in the console command line, run

__BRYTHON__.imports()


This will open a new browser window with the list of all the modules currently imported (the same as sys.modules in Python), this list can be saved in .bundle-include to generate brython_modules.js.

These new features will be documented in the next release (3.3.0) ; before I publish it I am interested in your feedback.



Brandon Keith Biggs

unread,
Dec 17, 2016, 5:05:29 AM12/17/16
to bry...@googlegroups.com
Hello,
This looks super cool!
Why not have a brython program in the python scripts folder and just have brython be on the command line?
This way commands could be like:
brython init
brython start
...
It would save one from needing to have server files inside their project dir. It would also be easier for newbies to use.
Thanks,


Brandon Keith Biggs

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/d30df89c-8ba7-4815-9ff4-b25987eeb097%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christophe Bal

unread,
Dec 17, 2016, 6:13:37 AM12/17/16
to bry...@googlegroups.com
Thanks for this new great feature ! 


Christophe BAL
Enseignant de mathématiques en Lycée et développeur Python amateur
---
French teacher of math in a high school and amateur Python developer

To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.

To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/d30df89c-8ba7-4815-9ff4-b25987eeb097%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.

To post to this group, send email to bry...@googlegroups.com.

André

unread,
Dec 17, 2016, 12:00:00 PM12/17/16
to brython
This sounds like an excellent idea, for most uses of Brython, and should help to attract even more attention to it. 

Currently, I import brython.js from cdn.rawgit and, based on the users' scripts, individual modules are also imported from that location, without me having to knowning ahead of time which modules are going to be imported, nor having to keep a copy of the standard library on the server I use.   I assume that this will still be possible to do after this additional feature is implemented. Would it be possible to confirm this?

(I also "stupidly" copy the entire content of Brython's standard library in a directory in my repository, allowing me to easily switch to a totally local version to do testing or demos when an Internet connection is not available ... I do this instead of simply copying py_VFS.js [as I did not realize its true nature] but will now copy brython_stdlib.js instead.)

Final comment, ... very minor bikeshedding suggestion: I would think that a more explicit name, like __BRYTHON__.show_imports()  or __BRYTHON__.list_imports() would be preferable over the proposed __BRYTHON__.imports() ,,, but that's probably just me.

Great work as always, Pierre!

André
 
Reply all
Reply to author
Forward
0 new messages