Resolving parts of #688907:
- Replaced bootstrap shell script with Python script. This means
standalone apps built with bundlebuilder will not work on MacOS < 10.1,
since we depend (again) on an installed Python.
- Add a hack to set sys.executable; the bootstrap script does os.execve()
with an argv[0] that's different from the actual Python executable
(it has to match the CFBundleExecutable entry in the Info.plist to make
the app work both from the Finder and the command line, and it has to be
the bootstrap script), yet a proper sys.executable is needed to spawn
auxiliary processes.
diff --git a/Lib/plat-mac/bundlebuilder.py b/Lib/plat-mac/bundlebuilder.py
index fd19cbb..4c33e64 100755
--- a/Lib/plat-mac/bundlebuilder.py
+++ b/Lib/plat-mac/bundlebuilder.py
@@ -230,7 +230,17 @@
path = fullname.replace(".", os.sep) + PYC_EXT
return path, MAGIC + '\0\0\0\0' + marshal.dumps(code)
+SITECUSTOMIZE_PY = """\
+import sys, os
+executable = os.getenv("PYTHONEXECUTABLE")
+if executable is not None:
+ sys.executable = executable
+"""
+
+SITE_PY += SITECUSTOMIZE_PY
SITE_CO = compile(SITE_PY, "<-bundlebuilder.py->", "exec")
+SITECUSTOMIZE_CO = compile(SITECUSTOMIZE_PY, "<-bundlebuilder.py->", "exec")
+
EXT_LOADER = """\
def __load():
@@ -255,15 +265,18 @@
STRIP_EXEC = "/usr/bin/strip"
BOOTSTRAP_SCRIPT = """\
-#!/bin/sh
+#!/usr/bin/env python
-execdir=$(dirname "${0}")
-executable="${execdir}/%(executable)s"
-resdir=$(dirname "${execdir}")/Resources
-main="${resdir}/%(mainprogram)s"
-PYTHONPATH="$resdir"
-export PYTHONPATH
-exec "${executable}" "${main}" "$@"
+import sys, os
+execdir = os.path.dirname(sys.argv[0])
+executable = os.path.join(execdir, "%(executable)s")
+resdir = os.path.join(os.path.dirname(execdir), "Resources")
+mainprogram = os.path.join(resdir, "%(mainprogram)s")
+
+sys.argv.insert(1, mainprogram)
+os.environ["PYTHONPATH"] = resdir
+os.environ["PYTHONEXECUTABLE"] = executable
+os.execve(executable, sys.argv, os.environ)
"""
ARGVEMULATOR="""\
@@ -415,6 +428,10 @@
def postProcess(self):
if self.standalone:
self.addPythonModules()
+ else:
+ sitecustomizepath = pathjoin(self.bundlepath, "Contents", "Resources",
+ "sitecustomize" + PYC_EXT)
+ writePyc(SITECUSTOMIZE_CO, sitecustomizepath)
if self.strip and not self.symlink:
self.stripBinaries()
@@ -487,6 +504,9 @@
site.__code__ = SITE_CO
mf.scan_code(SITE_CO, site)
+ # warnings.py gets imported implicitly from C
+ mf.import_hook("warnings")
+
includeModules = self.includeModules[:]
for name in self.includePackages:
includeModules.extend(findPackageContents(name).keys())