MCPcopy Index your code
hub / github.com/python/cpython / makefreeze

Function makefreeze

Tools/freeze/makefreeze.py:32–70  ·  view source on GitHub ↗
(base, dict, debug=0, entry_point=None, fail_import=())

Source from the content-addressed store, hash-verified

30"""
31
32def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
33 if entry_point is None: entry_point = default_entry_point
34 done = []
35 files = []
36 mods = sorted(dict.keys())
37 for mod in mods:
38 m = dict[mod]
39 mangled = "__".join(mod.split("."))
40 if m.__code__:
41 file = 'M_' + mangled + '.c'
42 with bkfile.open(base + file, 'w') as outfp:
43 files.append(file)
44 if debug:
45 print("freezing", mod, "...")
46 str = marshal.dumps(m.__code__)
47 size = len(str)
48 is_package = '0'
49 if m.__path__:
50 is_package = '1'
51 done.append((mod, mangled, size, is_package))
52 writecode(outfp, mangled, str)
53 if debug:
54 print("generating table of frozen modules")
55 with bkfile.open(base + 'frozen.c', 'w') as outfp:
56 for mod, mangled, size, _ in done:
57 outfp.write('extern unsigned char M_%s[];\n' % mangled)
58 outfp.write(header)
59 for mod, mangled, size, is_package in done:
60 outfp.write('\t{"%s", M_%s, %d, %s},\n' % (mod, mangled, size, is_package))
61 outfp.write('\n')
62 # The following modules have a NULL code pointer, indicating
63 # that the frozen program should not search for them on the host
64 # system. Importing them will *always* raise an ImportError.
65 # The zero value size is never used.
66 for mod in fail_import:
67 outfp.write('\t{"%s", NULL, 0},\n' % (mod,))
68 outfp.write(trailer)
69 outfp.write(entry_point)
70 return files
71
72
73

Callers

nothing calls this directly

Calls 8

writecodeFunction · 0.70
keysMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45
openMethod · 0.45
appendMethod · 0.45
dumpsMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…