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