Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 97 lines (80 sloc) 2.704 kb
6144796 Tool to generate stdlib from pyjs/lib, cpython lib and pypy lib
Daniel Kluev authored
1 #!/usr/bin/env python
2 """
3 Generate stdlib/ from pyjs/lib, /usr/lib/python and pypy/lib
4 """
5
6 import os
7 import sys
8 import shutil
9 from os.path import join, dirname, basename, abspath, exists, isdir
10 from optparse import OptionParser
11
12 root_path = dirname(abspath(__file__))
13 dest_path = join(root_path, 'stdlib')
14
66a5859 Include lib_trans and tests in generated stdlib
Daniel Kluev authored
15 imports = [
16 ('pyjs', join(root_path, 'pyjs', 'src', 'pyjs', 'lib'), ['output', 'test']),
17 ('pyjs', join(root_path, 'pyjs', 'src', 'pyjs', 'lib_trans'), ['output', 'test']),
18 ]
19
20 pypy_excludes = ['site-packages', 'pypy_test']
6144796 Tool to generate stdlib from pyjs/lib, cpython lib and pypy lib
Daniel Kluev authored
21 cpython_excludes = ['site-packages', 'lib-dynload', 'test']
22
23 mod_src = {}
66a5859 Include lib_trans and tests in generated stdlib
Daniel Kluev authored
24 def copy_tests(dest, src):
25 dest = join(dest, 'test')
26 src = join(src, 'test')
27 if not exists(src):
28 return
29 if not isdir(src):
30 return
31 for p in os.listdir(src):
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
32 if (not isdir(join(src, p))
66a5859 Include lib_trans and tests in generated stdlib
Daniel Kluev authored
33 and p.endswith('.py')
34 and not exists(join(dest, p))):
35 shutil.copy2(join(src, p), join(dest, p))
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
36
6144796 Tool to generate stdlib from pyjs/lib, cpython lib and pypy lib
Daniel Kluev authored
37 def copy_libs(dest, src, src_name, excludes):
38 for p in os.listdir(src):
39 if isdir(join(src, p)):
40 mod_name = p
41 elif p.endswith('.py'):
42 mod_name = p.split('.')[0]
43 else:
44 continue
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
45
46 if (not exists(join(dest, mod_name)) and
6144796 Tool to generate stdlib from pyjs/lib, cpython lib and pypy lib
Daniel Kluev authored
47 not exists(join(dest, mod_name + '.py')) and
48 not mod_name in excludes):
49 if isdir(join(src, p)):
50 shutil.copytree(join(src, p), join(dest, p))
51 else:
52 shutil.copy2(join(src, p), join(dest, p))
53 mod_src[mod_name] = src_name
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
54
6144796 Tool to generate stdlib from pyjs/lib, cpython lib and pypy lib
Daniel Kluev authored
55
56 def main():
57 parser = OptionParser()
58 parser.add_option(
59 "--pypy",
60 dest="pypy",
61 help="Path to PyPy libraries")
62 parser.add_option(
63 "--cpython",
64 dest="cpython",
65 help="Path to CPython libraries")
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
66
6144796 Tool to generate stdlib from pyjs/lib, cpython lib and pypy lib
Daniel Kluev authored
67 options, args = parser.parse_args()
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
68 if not options.cpython:
6144796 Tool to generate stdlib from pyjs/lib, cpython lib and pypy lib
Daniel Kluev authored
69 cpython_path = dirname(os.__file__)
70 else:
71 cpython_path = options.cpython
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
72
66a5859 Include lib_trans and tests in generated stdlib
Daniel Kluev authored
73 if options.pypy:
74 imports.append(('pypy', options.pypy, pypy_excludes))
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
75
66a5859 Include lib_trans and tests in generated stdlib
Daniel Kluev authored
76 if cpython_path:
77 imports.append(('cpython', cpython_path, cpython_excludes))
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
78
6144796 Tool to generate stdlib from pyjs/lib, cpython lib and pypy lib
Daniel Kluev authored
79 if exists(dest_path):
80 shutil.rmtree(dest_path)
81 os.mkdir(dest_path)
66a5859 Include lib_trans and tests in generated stdlib
Daniel Kluev authored
82 os.mkdir(join(dest_path, 'test'))
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
83
66a5859 Include lib_trans and tests in generated stdlib
Daniel Kluev authored
84 print ("Exporting data from:")
85 for name, path, exc in imports:
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
86 print ("{0}: {1}".format(name, path))
66a5859 Include lib_trans and tests in generated stdlib
Daniel Kluev authored
87 copy_libs(dest_path, path, name, exc)
88 copy_tests(dest_path, path)
89
6144796 Tool to generate stdlib from pyjs/lib, cpython lib and pypy lib
Daniel Kluev authored
90 f_mod_src = open(join(dest_path, 'modules_sources'), 'w')
91 for mod, src in mod_src.iteritems():
92 f_mod_src.write("{}:{}\n".format(mod, src))
93 f_mod_src.close()
64eff55 @xtfxme find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
94
95
6144796 Tool to generate stdlib from pyjs/lib, cpython lib and pypy lib
Daniel Kluev authored
96 if __name__ == '__main__':
97 main()
Something went wrong with that request. Please try again.