Changeset View
Changeset View
Standalone View
Standalone View
ext/python/Tools/freeze/freeze.py
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | def main(): | ||||
modargs = 0 | modargs = 0 | ||||
debug = 1 | debug = 1 | ||||
odir = '' | odir = '' | ||||
win = sys.platform[:3] == 'win' | win = sys.platform[:3] == 'win' | ||||
replace_paths = [] # settable with -r option | replace_paths = [] # settable with -r option | ||||
error_if_any_missing = 0 | error_if_any_missing = 0 | ||||
# default the exclude list for each platform | # default the exclude list for each platform | ||||
if win: exclude = exclude + [ | if win: exclude = exclude + [ | ||||
Lint: PEP8 E701: multiple statements on one line (colon) | |||||
'dos', 'dospath', 'mac', 'macpath', 'macfs', 'MACFS', 'posix', | 'dos', 'dospath', 'mac', 'macpath', 'macfs', 'MACFS', 'posix', | ||||
'os2', 'ce', 'riscos', 'riscosenviron', 'riscospath', | 'os2', 'ce', 'riscos', 'riscosenviron', 'riscospath', | ||||
] | ] | ||||
fail_import = exclude[:] | fail_import = exclude[:] | ||||
# output files | # output files | ||||
frozen_c = 'frozen.c' | frozen_c = 'frozen.c' | ||||
Show All 22 Lines | def main(): | ||||
try: | try: | ||||
opts, args = getopt.getopt(sys.argv[1:], 'r:a:dEe:hmo:p:P:b:qs:wX:x:l:') | opts, args = getopt.getopt(sys.argv[1:], 'r:a:dEe:hmo:p:P:b:qs:wX:x:l:') | ||||
except getopt.error, msg: | except getopt.error, msg: | ||||
usage('getopt error: ' + str(msg)) | usage('getopt error: ' + str(msg)) | ||||
# process option arguments | # process option arguments | ||||
for o, a in opts: | for o, a in opts: | ||||
if o == '-h': | if o == '-h': | ||||
print __doc__ | print(__doc__) | ||||
return | return | ||||
if o == '-b': | if o == '-b': | ||||
binlib = a | binlib = a | ||||
if o == '-d': | if o == '-d': | ||||
debug = debug + 1 | debug = debug + 1 | ||||
if o == '-e': | if o == '-e': | ||||
extensions.append(a) | extensions.append(a) | ||||
if o == '-m': | if o == '-m': | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | def main(): | ||||
# determine whether -p points to the Python source tree | # determine whether -p points to the Python source tree | ||||
ishome = os.path.exists(os.path.join(prefix, 'Python', 'ceval.c')) | ishome = os.path.exists(os.path.join(prefix, 'Python', 'ceval.c')) | ||||
# locations derived from options | # locations derived from options | ||||
version = sys.version[:3] | version = sys.version[:3] | ||||
if win: | if win: | ||||
extensions_c = 'frozen_extensions.c' | extensions_c = 'frozen_extensions.c' | ||||
if ishome: | if ishome: | ||||
print "(Using Python source directory)" | print("(Using Python source directory)") | ||||
binlib = exec_prefix | binlib = exec_prefix | ||||
incldir = os.path.join(prefix, 'Include') | incldir = os.path.join(prefix, 'Include') | ||||
config_h_dir = exec_prefix | config_h_dir = exec_prefix | ||||
config_c_in = os.path.join(prefix, 'Modules', 'config.c.in') | config_c_in = os.path.join(prefix, 'Modules', 'config.c.in') | ||||
frozenmain_c = os.path.join(prefix, 'Python', 'frozenmain.c') | frozenmain_c = os.path.join(prefix, 'Python', 'frozenmain.c') | ||||
makefile_in = os.path.join(exec_prefix, 'Makefile') | makefile_in = os.path.join(exec_prefix, 'Makefile') | ||||
if win: | if win: | ||||
frozendllmain_c = os.path.join(exec_prefix, 'Pc\\frozen_dllmain.c') | frozendllmain_c = os.path.join(exec_prefix, 'Pc\\frozen_dllmain.c') | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | def main(): | ||||
# handle -o option | # handle -o option | ||||
base_frozen_c = frozen_c | base_frozen_c = frozen_c | ||||
base_config_c = config_c | base_config_c = config_c | ||||
base_target = target | base_target = target | ||||
if odir and not os.path.isdir(odir): | if odir and not os.path.isdir(odir): | ||||
try: | try: | ||||
os.mkdir(odir) | os.mkdir(odir) | ||||
print "Created output directory", odir | print("Created output directory", odir) | ||||
except os.error, msg: | except os.error, msg: | ||||
usage('%s: mkdir failed (%s)' % (odir, str(msg))) | usage('%s: mkdir failed (%s)' % (odir, str(msg))) | ||||
base = '' | base = '' | ||||
if odir: | if odir: | ||||
base = os.path.join(odir, '') | base = os.path.join(odir, '') | ||||
frozen_c = os.path.join(odir, frozen_c) | frozen_c = os.path.join(odir, frozen_c) | ||||
config_c = os.path.join(odir, config_c) | config_c = os.path.join(odir, config_c) | ||||
target = os.path.join(odir, target) | target = os.path.join(odir, target) | ||||
makefile = os.path.join(odir, makefile) | makefile = os.path.join(odir, makefile) | ||||
if win: extensions_c = os.path.join(odir, extensions_c) | if win: extensions_c = os.path.join(odir, extensions_c) | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
# Handle special entry point requirements | # Handle special entry point requirements | ||||
# (on Windows, some frozen programs do not use __main__, but | # (on Windows, some frozen programs do not use __main__, but | ||||
# import the module directly. Eg, DLLs, Services, etc | # import the module directly. Eg, DLLs, Services, etc | ||||
custom_entry_point = None # Currently only used on Windows | custom_entry_point = None # Currently only used on Windows | ||||
python_entry_is_main = 1 # Is the entry point called __main__? | python_entry_is_main = 1 # Is the entry point called __main__? | ||||
# handle -s option on Windows | # handle -s option on Windows | ||||
if win: | if win: | ||||
Show All 34 Lines | def main(): | ||||
# Add the main script as either __main__, or the actual module name. | # Add the main script as either __main__, or the actual module name. | ||||
if python_entry_is_main: | if python_entry_is_main: | ||||
mf.run_script(scriptfile) | mf.run_script(scriptfile) | ||||
else: | else: | ||||
mf.load_file(scriptfile) | mf.load_file(scriptfile) | ||||
if debug > 0: | if debug > 0: | ||||
mf.report() | mf.report() | ||||
print() | |||||
dict = mf.modules | dict = mf.modules | ||||
if error_if_any_missing: | if error_if_any_missing: | ||||
missing = mf.any_missing() | missing = mf.any_missing() | ||||
if missing: | if missing: | ||||
sys.exit("There are some missing modules: %r" % missing) | sys.exit("There are some missing modules: %r" % missing) | ||||
# generate output for frozen modules | # generate output for frozen modules | ||||
Show All 38 Lines | def main(): | ||||
# report unknown modules | # report unknown modules | ||||
if unknown: | if unknown: | ||||
sys.stderr.write('Warning: unknown modules remain: %s\n' % | sys.stderr.write('Warning: unknown modules remain: %s\n' % | ||||
' '.join(unknown)) | ' '.join(unknown)) | ||||
# windows gets different treatment | # windows gets different treatment | ||||
if win: | if win: | ||||
# Taking a shortcut here... | # Taking a shortcut here... | ||||
import winmakemakefile, checkextensions_win32 | import winmakemakefile, checkextensions_win32 | ||||
Lint: PEP8 E401 multiple imports on one line Lint: PEP8 E401: multiple imports on one line | |||||
checkextensions_win32.write_extension_table(extensions_c, | checkextensions_win32.write_extension_table(extensions_c, | ||||
frozen_extensions) | frozen_extensions) | ||||
# Create a module definition for the bootstrap C code. | # Create a module definition for the bootstrap C code. | ||||
xtras = [frozenmain_c, os.path.basename(frozen_c), | xtras = [frozenmain_c, os.path.basename(frozen_c), | ||||
frozendllmain_c, os.path.basename(extensions_c)] + files | frozendllmain_c, os.path.basename(extensions_c)] + files | ||||
maindefn = checkextensions_win32.CExtension( '__main__', xtras ) | maindefn = checkextensions_win32.CExtension( '__main__', xtras ) | ||||
frozen_extensions.append( maindefn ) | frozen_extensions.append( maindefn ) | ||||
outfp = open(makefile, 'w') | outfp = open(makefile, 'w') | ||||
Show All 24 Lines | def main(): | ||||
if os.path.exists(makefile_in): | if os.path.exists(makefile_in): | ||||
makevars = parsesetup.getmakevars(makefile_in) | makevars = parsesetup.getmakevars(makefile_in) | ||||
for key in makevars.keys(): | for key in makevars.keys(): | ||||
somevars[key] = makevars[key] | somevars[key] = makevars[key] | ||||
somevars['CFLAGS'] = ' '.join(cflags) # override | somevars['CFLAGS'] = ' '.join(cflags) # override | ||||
somevars['CPPFLAGS'] = ' '.join(cppflags) # override | somevars['CPPFLAGS'] = ' '.join(cppflags) # override | ||||
files = [base_config_c, base_frozen_c] + \ | files = [base_config_c, base_frozen_c] + \ | ||||
files + supp_sources + addfiles + libs + \ | files + supp_sources + addfiles + libs + \ | ||||
Lint: PEP8 E222 multiple spaces after operator Lint: PEP8 E222: multiple spaces after operator | |||||
['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)'] | ['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)'] | ||||
outfp = bkfile.open(makefile, 'w') | outfp = bkfile.open(makefile, 'w') | ||||
try: | try: | ||||
makemakefile.makemakefile(outfp, somevars, files, base_target) | makemakefile.makemakefile(outfp, somevars, files, base_target) | ||||
finally: | finally: | ||||
outfp.close() | outfp.close() | ||||
# Done! | # Done! | ||||
if odir: | if odir: | ||||
print 'Now run "make" in', odir, | print('Now run "make" in', odir, end=' ') | ||||
print 'to build the target:', base_target | print('to build the target:', base_target) | ||||
else: | else: | ||||
print 'Now run "make" to build the target:', base_target | print('Now run "make" to build the target:', base_target) | ||||
# Print usage message and exit | # Print usage message and exit | ||||
def usage(msg): | def usage(msg): | ||||
sys.stdout = sys.stderr | sys.stdout = sys.stderr | ||||
print "Error:", msg | print("Error:", msg) | ||||
print "Use ``%s -h'' for help" % sys.argv[0] | print("Use ``%s -h'' for help" % sys.argv[0]) | ||||
sys.exit(2) | sys.exit(2) | ||||
main() | main() |
multiple statements on one line (colon)