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

Improve precompile tool #239

Closed
olemis opened this Issue Aug 9, 2015 · 10 comments

Comments

Projects
None yet
4 participants
@olemis
Contributor

olemis commented Aug 9, 2015

Implemented in #222 . Further details TBD .

@glyph

This comment has been minimized.

Show comment
Hide comment
@glyph

glyph Sep 18, 2015

Contributor

Still waiting for those further details :). I tried a few things but could not get it to work at all. How am I supposed to run this?

Contributor

glyph commented Sep 18, 2015

Still waiting for those further details :). I tried a few things but could not get it to work at all. How am I supposed to run this?

@olemis

This comment has been minimized.

Show comment
Hide comment
@olemis

olemis Sep 21, 2015

Contributor

There is a simple pre-compilation tool aimed at translating Python code to its internal js equivalent . You should be able to use it to build your own VFS file that you can load afterwards.

Regarding improvements , we are the ones waiting for users to tell us what needs to be improved in the pre-compilation workflow .

Contributor

olemis commented Sep 21, 2015

There is a simple pre-compilation tool aimed at translating Python code to its internal js equivalent . You should be able to use it to build your own VFS file that you can load afterwards.

Regarding improvements , we are the ones waiting for users to tell us what needs to be improved in the pre-compilation workflow .

@glyph

This comment has been minimized.

Show comment
Hide comment
@glyph

glyph Oct 18, 2015

Contributor

@olemis - I'm still a bit lost.

There is a simple pre-compilation tool aimed at translating Python code to its internal js equivalent . You should be able to use it to build your own VFS file that you can load afterwards.

It looks like precompile.html just works on a single python module pasted into a text field on a web page. The tricky part, for me, is getting this code to run in an environment that can see the actual filesystem, where my pip install'ed files live, and convert them into a .vfs.js; pasting hundreds of modules into a text field is a non-starter. I am not really sure how to get started with node.js to run this, since scripts/node_bridge.js just gives me this error when I start it:

fs.js:549
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open '../src/brython.js'
    at Error (native)
    at Object.fs.openSync (fs.js:549:18)
    at Object.fs.readFileSync (fs.js:397:15)
    at Object.<anonymous> (�.../Brython/scripts/node_bridge.js:31:13)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:117:18)
Contributor

glyph commented Oct 18, 2015

@olemis - I'm still a bit lost.

There is a simple pre-compilation tool aimed at translating Python code to its internal js equivalent . You should be able to use it to build your own VFS file that you can load afterwards.

It looks like precompile.html just works on a single python module pasted into a text field on a web page. The tricky part, for me, is getting this code to run in an environment that can see the actual filesystem, where my pip install'ed files live, and convert them into a .vfs.js; pasting hundreds of modules into a text field is a non-starter. I am not really sure how to get started with node.js to run this, since scripts/node_bridge.js just gives me this error when I start it:

fs.js:549
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open '../src/brython.js'
    at Error (native)
    at Object.fs.openSync (fs.js:549:18)
    at Object.fs.readFileSync (fs.js:397:15)
    at Object.<anonymous> (�.../Brython/scripts/node_bridge.js:31:13)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:117:18)
@glyph

This comment has been minimized.

Show comment
Hide comment
@glyph

glyph Oct 18, 2015

Contributor

Regarding improvements , we are the ones waiting for users to tell us what needs to be improved in the pre-compilation workflow .

Well, if you are waiting 😄 , here is what I want from the pre-compilation workflow:

$ mkvirtualenv -p `which python3` my-brython-project
$ . my-brython-project/bin/activate
$ pip install brython
$ pip install foo
$ pip install bar
$ pip install baz
$ cat > my_project.py
import foo
import bar
import baz
def do_fun_brython_stuff():
    "use foo, bar, baz..."
^D
$ brythonify --package=foo --package=bar --package=baz --script=my_project.py --output=my_project.vfs.js
$ cat > my_project.html
<html>
<script src="my_project.vfs.js" />
<body onload="brython()">
</body>
</html>
^D
$ scp my_project.html my_project.vfs.js my-server.example.com:
$ open https://my-server.example.com/my_project.html
Contributor

glyph commented Oct 18, 2015

Regarding improvements , we are the ones waiting for users to tell us what needs to be improved in the pre-compilation workflow .

Well, if you are waiting 😄 , here is what I want from the pre-compilation workflow:

$ mkvirtualenv -p `which python3` my-brython-project
$ . my-brython-project/bin/activate
$ pip install brython
$ pip install foo
$ pip install bar
$ pip install baz
$ cat > my_project.py
import foo
import bar
import baz
def do_fun_brython_stuff():
    "use foo, bar, baz..."
^D
$ brythonify --package=foo --package=bar --package=baz --script=my_project.py --output=my_project.vfs.js
$ cat > my_project.html
<html>
<script src="my_project.vfs.js" />
<body onload="brython()">
</body>
</html>
^D
$ scp my_project.html my_project.vfs.js my-server.example.com:
$ open https://my-server.example.com/my_project.html
@glyph

This comment has been minimized.

Show comment
Hide comment
@glyph

glyph Oct 18, 2015

Contributor

To explain that workflow a bit better: I want to be able to have a tool which does all the work of enumerating all the Python files that need to be translated, translating them, putting them into a .vfs file, and including brython.js itself, possibly. I want it to be distributed via pip, as a regular python package, not something I have to git clone myself.

I would work on this myself, except I can't figure out how to get to the basic first level of what node_bridge.js is supposed to do, allowing me to run brython code in a command-line context. If I could do that, I could happily put together a Python program (run with CPython or PyPy) which could feed each module to a VFS builder.

Contributor

glyph commented Oct 18, 2015

To explain that workflow a bit better: I want to be able to have a tool which does all the work of enumerating all the Python files that need to be translated, translating them, putting them into a .vfs file, and including brython.js itself, possibly. I want it to be distributed via pip, as a regular python package, not something I have to git clone myself.

I would work on this myself, except I can't figure out how to get to the basic first level of what node_bridge.js is supposed to do, allowing me to run brython code in a command-line context. If I could do that, I could happily put together a Python program (run with CPython or PyPy) which could feed each module to a VFS builder.

@glyph

This comment has been minimized.

Show comment
Hide comment
@glyph

glyph Jan 3, 2016

Contributor

Is there any more documentation on this yet?

Contributor

glyph commented Jan 3, 2016

Is there any more documentation on this yet?

@olemis

This comment has been minimized.

Show comment
Hide comment
@olemis

olemis Jan 14, 2016

Contributor

I've not been able to take a look into this yet . Sorry . I'm hoping to have time to do something about it in the next few days .

Contributor

olemis commented Jan 14, 2016

I've not been able to take a look into this yet . Sorry . I'm hoping to have time to do something about it in the next few days .

@glyph

This comment has been minimized.

Show comment
Hide comment
@glyph

glyph Jan 14, 2016

Contributor

Thanks for the update! No need to apologize; I know open source is hard. I am very excited to see what you come up with :).

To maybe refine that workflow a little bit:

$ mkvirtualenv -p `which python3` my-brython-project
$ . my-brython-project/bin/activate
$ cat > requirements.txt
brython==999.999
foo==1.0
bar==2.6
baz==3.7
^D
$ pip install -r requirements.txt
$ cat > my_project.py
import foo
import bar
import baz
def do_fun_brython_stuff():
    "use foo, bar, baz..."
^D
$ brythonify --requirement=requirements.txt --script=my_project.py --output=my_project.vfs.js
$ cat > my_project.html
<html>
<script src="my_project.vfs.js" />
<body onload="brython()">
</body>
</html>
^D
$ scp my_project.html my_project.vfs.js my-server.example.com:
$ open https://my-server.example.com/my_project.html

Even better would be for my_project to have its own setup.py that describes it as a package, just as if I were doing a server-side Python app. The key thing is to provide the same kind of tooling that pip provides, or piggyback on pip as much as possible, to include everything from a particular setuptools "distribution", and only do optimization (pruning unused modules, for example) after things are already working well.

Contributor

glyph commented Jan 14, 2016

Thanks for the update! No need to apologize; I know open source is hard. I am very excited to see what you come up with :).

To maybe refine that workflow a little bit:

$ mkvirtualenv -p `which python3` my-brython-project
$ . my-brython-project/bin/activate
$ cat > requirements.txt
brython==999.999
foo==1.0
bar==2.6
baz==3.7
^D
$ pip install -r requirements.txt
$ cat > my_project.py
import foo
import bar
import baz
def do_fun_brython_stuff():
    "use foo, bar, baz..."
^D
$ brythonify --requirement=requirements.txt --script=my_project.py --output=my_project.vfs.js
$ cat > my_project.html
<html>
<script src="my_project.vfs.js" />
<body onload="brython()">
</body>
</html>
^D
$ scp my_project.html my_project.vfs.js my-server.example.com:
$ open https://my-server.example.com/my_project.html

Even better would be for my_project to have its own setup.py that describes it as a package, just as if I were doing a server-side Python app. The key thing is to provide the same kind of tooling that pip provides, or piggyback on pip as much as possible, to include everything from a particular setuptools "distribution", and only do optimization (pruning unused modules, for example) after things are already working well.

@trengere

This comment has been minimized.

Show comment
Hide comment
@trengere

trengere Apr 21, 2016

is it not possible to precompile list comprehension (eg [i*i for i in range(10)])
i am using the 'test/precompile.html' tool
or am I doing something wrong...
works if i translate it to

res = []
for i in range(10):
res.append(i*i)

trengere commented Apr 21, 2016

is it not possible to precompile list comprehension (eg [i*i for i in range(10)])
i am using the 'test/precompile.html' tool
or am I doing something wrong...
works if i translate it to

res = []
for i in range(10):
res.append(i*i)

@PierreQuentel

This comment has been minimized.

Show comment
Hide comment
@PierreQuentel

PierreQuentel Sep 18, 2017

Contributor

I think we can close this thread, #491 also deals with precompilation.

Contributor

PierreQuentel commented Sep 18, 2017

I think we can close this thread, #491 also deals with precompilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment