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 brythonTo create a Brython environment in an empty folder, run
python -m brython --installThis 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 --modulesBecause 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.