forked from rcarmo/pythonium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·66 lines (56 loc) · 2.23 KB
/
Copy pathmain.py
File metadata and controls
executable file
·66 lines (56 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""pythonium
Usage: pythonium [-h][-d][-r][-V] [FILE ...] [-o FILE]|[-g]
Options:
-h --help show this
-v --version show version
-V --veloce use veloce mode, generated code is faster but least compliant
-o --output FILE specify output file [default: stdout]
-d --deep generate file dependencies. If --output is not provided, it will generate for each source file a coresponding .js file.
-r --requirejs generate requirejs compatible module
-g --generate generate pythonium runtime (exclusive option)
The default mode, without -V or --veloce option is *experimental*.
If you generate code without -V or --veloce you will need to use the library generated with -g or --generate option to run the code.
"""
import os
import sys
from .veloce import veloce_generate_js
from .pythonium import pythonium_generate_js
__version__ = '0.4.4'
def main():
from docopt import docopt
args = docopt(__doc__, version='pythonium ' + __version__)
if args['--generate']:
from pythonium import lib
path = lib.__path__[0]
output = sys.stdout
for name in ['runtime.py', 'builtins.py']:
sys.stderr.write('Processing {}\n'.format(name))
veloce_generate_js(os.path.join(path, name), False, None, output, False)
for name in os.listdir(path):
if name == '__pycache__':
continue
sys.stderr.write('Processing {}\n'.format(name))
if name in ['runtime.py', 'builtins.py']:
continue
else:
pythonium_generate_js(os.path.join(path, name), False, None, output, False)
output.close()
else:
requirejs = args['--requirejs']
filepaths = args['FILE']
output = args['--output']
if output is None:
output = sys.stdout
else:
output = open(output, 'w')
deep = args['--deep']
for filepath in filepaths:
if args['--veloce']:
veloce_generate_js(filepath, requirejs, None, output, deep)
else:
pythonium_generate_js(filepath, requirejs, None, output, deep)
if output:
output.close()
if __name__ == '__main__':
main()