Kaydet (Commit) 072bb405 authored tarafından Ronald Oussoren's avatar Ronald Oussoren

Fix for issues #841800 and #900506

üst 0bbebbbe
...@@ -245,10 +245,10 @@ if not %(semi_standalone)s: ...@@ -245,10 +245,10 @@ if not %(semi_standalone)s:
del sys.path[1:] # sys.path[0] is Contents/Resources/ del sys.path[1:] # sys.path[0] is Contents/Resources/
""" """
if USE_ZIPIMPORT: ZIP_ARCHIVE = "Modules.zip"
ZIP_ARCHIVE = "Modules.zip" SITE_PY_ZIP = SITE_PY + ("sys.path.append(sys.path[0] + '/%s')\n" % ZIP_ARCHIVE)
SITE_PY += "sys.path.append(sys.path[0] + '/%s')\n" % ZIP_ARCHIVE
def getPycData(fullname, code, ispkg): def getPycData(fullname, code, ispkg):
if ispkg: if ispkg:
fullname += ".__init__" fullname += ".__init__"
path = fullname.replace(".", os.sep) + PYC_EXT path = fullname.replace(".", os.sep) + PYC_EXT
...@@ -301,6 +301,9 @@ resdir = os.path.join(os.path.dirname(execdir), "Resources") ...@@ -301,6 +301,9 @@ resdir = os.path.join(os.path.dirname(execdir), "Resources")
libdir = os.path.join(os.path.dirname(execdir), "Frameworks") libdir = os.path.join(os.path.dirname(execdir), "Frameworks")
mainprogram = os.path.join(resdir, "%(mainprogram)s") mainprogram = os.path.join(resdir, "%(mainprogram)s")
if %(optimize)s:
sys.argv.insert(1, '-O')
sys.argv.insert(1, mainprogram) sys.argv.insert(1, mainprogram)
if %(standalone)s or %(semi_standalone)s: if %(standalone)s or %(semi_standalone)s:
os.environ["PYTHONPATH"] = resdir os.environ["PYTHONPATH"] = resdir
...@@ -311,6 +314,7 @@ else: ...@@ -311,6 +314,7 @@ else:
if pypath: if pypath:
pypath = ":" + pypath pypath = ":" + pypath
os.environ["PYTHONPATH"] = resdir + pypath os.environ["PYTHONPATH"] = resdir + pypath
os.environ["PYTHONEXECUTABLE"] = executable os.environ["PYTHONEXECUTABLE"] = executable
os.environ["DYLD_LIBRARY_PATH"] = libdir os.environ["DYLD_LIBRARY_PATH"] = libdir
os.environ["DYLD_FRAMEWORK_PATH"] = libdir os.environ["DYLD_FRAMEWORK_PATH"] = libdir
...@@ -350,6 +354,8 @@ SITE_PACKAGES = os.path.join(LIB, "site-packages") ...@@ -350,6 +354,8 @@ SITE_PACKAGES = os.path.join(LIB, "site-packages")
class AppBuilder(BundleBuilder): class AppBuilder(BundleBuilder):
use_zipimport = USE_ZIPIMPORT
# Override type of the bundle. # Override type of the bundle.
type = "APPL" type = "APPL"
...@@ -506,6 +512,7 @@ class AppBuilder(BundleBuilder): ...@@ -506,6 +512,7 @@ class AppBuilder(BundleBuilder):
hashbang = os.path.realpath(sys.executable) hashbang = os.path.realpath(sys.executable)
standalone = self.standalone standalone = self.standalone
semi_standalone = self.semi_standalone semi_standalone = self.semi_standalone
optimize = sys.flags.optimize
open(bootstrappath, "w").write(BOOTSTRAP_SCRIPT % locals()) open(bootstrappath, "w").write(BOOTSTRAP_SCRIPT % locals())
os.chmod(bootstrappath, 0775) os.chmod(bootstrappath, 0775)
...@@ -552,13 +559,14 @@ class AppBuilder(BundleBuilder): ...@@ -552,13 +559,14 @@ class AppBuilder(BundleBuilder):
self.files.append((src, dst)) self.files.append((src, dst))
def _getSiteCode(self): def _getSiteCode(self):
if self.use_zipimport:
return compile(SITE_PY % {"semi_standalone": self.semi_standalone}, return compile(SITE_PY % {"semi_standalone": self.semi_standalone},
"<-bundlebuilder.py->", "exec") "<-bundlebuilder.py->", "exec")
def addPythonModules(self): def addPythonModules(self):
self.message("Adding Python modules", 1) self.message("Adding Python modules", 1)
if USE_ZIPIMPORT: if self.use_zipimport:
# Create a zip file containing all modules as pyc. # Create a zip file containing all modules as pyc.
import zipfile import zipfile
relpath = pathjoin("Contents", "Resources", ZIP_ARCHIVE) relpath = pathjoin("Contents", "Resources", ZIP_ARCHIVE)
...@@ -624,7 +632,7 @@ class AppBuilder(BundleBuilder): ...@@ -624,7 +632,7 @@ class AppBuilder(BundleBuilder):
self.message("Finding module dependencies", 1) self.message("Finding module dependencies", 1)
import modulefinder import modulefinder
mf = modulefinder.ModuleFinder(excludes=self.excludeModules) mf = modulefinder.ModuleFinder(excludes=self.excludeModules)
if USE_ZIPIMPORT: if self.use_zipimport:
# zipimport imports zlib, must add it manually # zipimport imports zlib, must add it manually
mf.import_hook("zlib") mf.import_hook("zlib")
# manually add our own site.py # manually add our own site.py
...@@ -658,7 +666,7 @@ class AppBuilder(BundleBuilder): ...@@ -658,7 +666,7 @@ class AppBuilder(BundleBuilder):
filename = os.path.basename(path) filename = os.path.basename(path)
pathitems = name.split(".")[:-1] + [filename] pathitems = name.split(".")[:-1] + [filename]
dstpath = pathjoin(*pathitems) dstpath = pathjoin(*pathitems)
if USE_ZIPIMPORT: if self.use_zipimport:
if name != "zlib": if name != "zlib":
# neatly pack all extension modules in a subdirectory, # neatly pack all extension modules in a subdirectory,
# except zlib, since it's neccesary for bootstrapping. # except zlib, since it's neccesary for bootstrapping.
...@@ -672,9 +680,9 @@ class AppBuilder(BundleBuilder): ...@@ -672,9 +680,9 @@ class AppBuilder(BundleBuilder):
self.files.append((path, pathjoin("Contents", "Resources", dstpath))) self.files.append((path, pathjoin("Contents", "Resources", dstpath)))
if mod.__code__ is not None: if mod.__code__ is not None:
ispkg = mod.__path__ is not None ispkg = mod.__path__ is not None
if not USE_ZIPIMPORT or name != "site": if not self.use_zipimport or name != "site":
# Our site.py is doing the bootstrapping, so we must # Our site.py is doing the bootstrapping, so we must
# include a real .pyc file if USE_ZIPIMPORT is True. # include a real .pyc file if self.use_zipimport is True.
self.pymodules.append((name, mod.__code__, ispkg)) self.pymodules.append((name, mod.__code__, ispkg))
if hasattr(mf, "any_missing_maybe"): if hasattr(mf, "any_missing_maybe"):
...@@ -820,6 +828,7 @@ Options: ...@@ -820,6 +828,7 @@ Options:
--semi-standalone build a standalone application, which depends on --semi-standalone build a standalone application, which depends on
an installed Python, yet includes all third-party an installed Python, yet includes all third-party
modules. modules.
--no-zipimport Do not copy code into a zip file
--python=FILE Python to use in #! line in stead of current Python --python=FILE Python to use in #! line in stead of current Python
--lib=FILE shared library or framework to be copied into --lib=FILE shared library or framework to be copied into
the bundle the bundle
...@@ -847,7 +856,9 @@ def main(builder=None): ...@@ -847,7 +856,9 @@ def main(builder=None):
"mainprogram=", "creator=", "nib=", "plist=", "link", "mainprogram=", "creator=", "nib=", "plist=", "link",
"link-exec", "help", "verbose", "quiet", "argv", "standalone", "link-exec", "help", "verbose", "quiet", "argv", "standalone",
"exclude=", "include=", "package=", "strip", "iconfile=", "exclude=", "include=", "package=", "strip", "iconfile=",
"lib=", "python=", "semi-standalone", "bundle-id=", "destroot=") "lib=", "python=", "semi-standalone", "bundle-id=", "destroot="
"no-zipimport"
)
try: try:
options, args = getopt.getopt(sys.argv[1:], shortopts, longopts) options, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
...@@ -911,6 +922,8 @@ def main(builder=None): ...@@ -911,6 +922,8 @@ def main(builder=None):
builder.strip = 1 builder.strip = 1
elif opt == '--destroot': elif opt == '--destroot':
builder.destroot = arg builder.destroot = arg
elif opt == '--no-zipimport':
builder.use_zipimport = False
if len(args) != 1: if len(args) != 1:
usage("Must specify one command ('build', 'report' or 'help')") usage("Must specify one command ('build', 'report' or 'help')")
......
...@@ -238,6 +238,10 @@ Library ...@@ -238,6 +238,10 @@ Library
- Issue #1149804: macostools.mkdirs now even works when another process - Issue #1149804: macostools.mkdirs now even works when another process
creates one of the needed subdirectories. creates one of the needed subdirectories.
- Issue #900506: added --no-zipimport flag to the bundlebuilder script
- Issue #841800: bundlebuilder now works with 'python -O'
Tools/Demos Tools/Demos
----------- -----------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment