-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·76 lines (61 loc) · 2.37 KB
/
Copy pathmain.py
File metadata and controls
executable file
·76 lines (61 loc) · 2.37 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
67
68
69
70
71
72
73
74
75
76
#!/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.veloce import Veloce
from .compliant.compliant import Compliant
from .utils import pythonium_generate_js
__version__ = '0.6.3'
def main(argv=None):
from docopt import docopt
args = docopt(__doc__, argv, version='pythonium ' + __version__)
if args['--generate']:
# call ourself for each file in pythonium.lib:
from pythonium import compliant
from pythonium.compliant import builtins
# runtime is built separatly
# it must appear first in the file
# and it must be built using veloce mode
path = compliant.__path__[0]
argv = ['--veloce', os.path.join(path, 'runtime.py')]
main(argv)
# compile builtins
for path in builtins.__path__:
for name in sorted(os.listdir(path)):
if name.endswith('.py'):
argv = [os.path.join(path, name)]
main(argv)
return
filepaths = args['FILE']
if not filepaths:
main(['--help'])
return
translator = Veloce if args['--veloce'] else Compliant
options = {'translator_class': translator,
'requirejs': args['--requirejs'],
'deep': args['--deep'],
}
outfile = args['--output']
if outfile:
with open(outfile, 'w') as output:
for filepath in filepaths:
pythonium_generate_js(filepath, output=output, **options)
else:
for filepath in filepaths:
pythonium_generate_js(filepath, output=sys.stdout, **options)
if __name__ == '__main__':
main()