How to distribute and deploy a Brython application - tests and feedback welcome

149 views
Skip to first unread message

Pierre Quentel

unread,
Jul 2, 2017, 3:38:14 PM7/2/17
to brython
For those who don't follow the discussion on Github issue #491, here is a new proposal for the distribution and deployment of an application written in Brython.

It uses the CPython package brython, located in folder /setup of the repository. This script in run with CPython on the developer's PC. If you want to test the process, you should install it locally by running

python setup.py sdist
python setup.py install


from this /setup folder. There is a version of this package on PyPI but it's not yet updated.

So, if you have installed it, the process is as follows :
  1. create a new directory for the application and run python -m brython --install to install the basic Brython files (brython.js, brython_stdlib.js)

  2. the developer writes HTML pages and Python scripts for the application

  3. the new command-line option python -m brython --make_dist executes the following tasks :

  • generate brython_modules.js by parsing the code in all Brython scripts (forget .bundle_include used in the previous version !). The code to generate it is in a new module in the Brython repo, /setup/list_modules.py ; it is based on an AST visitor to recursively detect imports
  • copies the application files in a subdirectory called __dist__
  • in this directory, for HTML pages, <script src="/path/to/brython/brython_stdlib.js"> is replaced by <script src="/path/to/brython/brython_modules.js">
  • the user is asked to enter basic setup information : application name, version, author, author email, url. This information is stored in a file brython_setup.json to avoid having to enter the information each time a --make_dist is run
  • this information is used to generate a setup.py script, and another script called like the application name (eg myapp.py)
  1. from the __dist__ subdirectory, running python setup.py sdist and python setup.py install installs the package myapp. This is done manually in case the developer wishes to edit or add information in setup.py. The package is an ordinary Python package and can be distributed through PyPI and pip.

  2. running python -m myapp --install installs the application files (HTML pages, brython.js, brython_modules.js, Python scripts, etc.) in an empty directory

Feedback on this process and tests of the brython package are very much welcome.

benjamin rigaud

unread,
Jul 15, 2017, 6:56:55 AM7/15/17
to brython
Great job Pierre! It looks promising.

I just tried this new process and got an error at the third command:

> python -m brython --install
Installing Brython in an empty directory
Traceback (most recent call last):
 
File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
   
"__main__", mod_spec)
 
File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
   
exec(code, run_globals)
 
File "/home/me/venvs/myproject/lib/python3.4/site-packages/brython-3.3.3-py3.4.egg/brython.py", line 40, in <module>
    shutil
.copyfile(os.path.join(src_path, path), path)
 
File "/home/me/venvs/myproject/lib/python3.4/shutil.py", line 108, in copyfile
   
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/home/me/venvs/myproject/lib/python3.4/site-packages/brython-3.3.3-py3.4.egg/data/brython.js'


The brython.js file doesn't exist. 

Ben

Pierre Quentel

unread,
Jul 15, 2017, 4:38:59 PM7/15/17
to brython


Le samedi 15 juillet 2017 12:56:55 UTC+2, benjamin rigaud a écrit :

Great job Pierre! It looks promising.

I just tried this new process and got an error at the third command:

> python -m brython --install
Installing Brython in an empty directory
Traceback (most recent call last):
 
File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
   
"__main__", mod_spec)
 
File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
   
exec(code, run_globals)
 
File "/home/me/venvs/myproject/lib/python3.4/site-packages/brython-3.3.3-py3.4.egg/brython.py", line 40, in <module>
    shutil
.copyfile(os.path.join(src_path, path), path)
 
File "/home/me/venvs/myproject/lib/python3.4/shutil.py", line 108, in copyfile
   
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/home/me/venvs/myproject/lib/python3.4/site-packages/brython-3.3.3-py3.4.egg/data/brython.js'


The brython.js file doesn't exist. 

Ben

Merci Benjamin !

Many thanks for reporting this. I forgot to copy these files from /www/src to /setup/data. It's fixed in the latest commit. Can you try again ?

- Pierre

benjamin rigaud

unread,
Jul 20, 2017, 3:32:19 AM7/20/17
to brython
It works fine up to --make_dist: I didn't yet test the following steps with setup.py & co.
I still have a few 404 due to import mechanism.

Ben

 

- Pierre

Brendan Barnwell

unread,
Aug 28, 2017, 1:47:17 AM8/28/17
to brython
On Sunday, July 2, 2017 at 12:38:14 PM UTC-7, Pierre Quentel wrote:
For those who don't follow the discussion on Github issue #491, here is a new proposal for the distribution and deployment of an application written in Brython.


I just tested it up to the make_dist part and it seems to work.  Looking at the code, it seems it doesn't actually compile Python code to JS, so this is mostly just a convenience for bundling.  Is that right?  It does seem useful for complex apps but it also seems that the more complex the app the more likely that on-the-fly compilation will be a bottleneck.

Jonathan Verner

unread,
Aug 30, 2017, 2:09:21 AM8/30/17
to brython
Here are some preliminary comments:
  • currently, the modules which are bundled into brython_modules.js only come from the app directory; it would be nice if the script also searched the current site-packages directory (so that other brython packages installed via pip would be added)
  • it seems fragile to me to rewrite the html pages replacing brython_stdlib.js with brython_modules.js; in my oppinion, it would be better to initially install brython_stdlib.js into brython_modules.js and then replace this file so that the user could just include brython_modules.js in his html and we wouldn't have to rewrite anything
  • I am not sure how useful the package creation will be; I can imagine, that it might make sense for simple apps with no server component --- in that case, after installing the package, I would expect a myapp script to be created, which would just run a simple web server serving the files on localhost & open a web browser on the page; however, for apps with a server component, I think that the different deployment scenarios are too diverse for us to have brython do anything very useful beyond generating the brython_modules.js script
  • I think it would be nice if installing brython also installed a brython script so that we could run brython --make_dist instead of python -m brython --make_dist
  • It might be useful to have the make_dist as a library function which would be usable from different python scripts to allow simple integration with, e.g., Dajngo's system for bundling static files... 
  • I think it would make more sense for the the install command to just create a subdirectory called brython with the relevant files and also a link to to the site-packages directory so that pip-installed brython libraries can be used; the reason for not creating a directory with a html file and the brython js scripts is that, at least for more complex applications, I like to have downloadable resources in subdirectories (e.g. js, img, css, ...) not cluttering the main dir; also, if I start with a project and then later decide to add brython to it, the current approach just doesn't make sense; The only downside of this approach is that the user would have to create his own html file. But that could either be overcome with creating (optionally) a simple example.html file or maybe just having the script print out some basic instructions (together with having these instructions in the online documentation)
These are just some of my thoughts... Thank you for working on this!!
Reply all
Reply to author
Forward
0 new messages