diff options
author | Just van Rossum <just@letterror.com> | 2003-02-25 20:15:40 (GMT) |
---|---|---|
committer | Just van Rossum <just@letterror.com> | 2003-02-25 20:15:40 (GMT) |
commit | 7322b1ad46d6eeb7af609082f2a4896719e382d6 (patch) | |
tree | 525c2e089584cd4ee6cccd36fad138b1248d803e /Lib | |
parent | 74b9a7a71f6da74da872198dcb226ec1e7fbe966 (diff) | |
download | cpython-7322b1ad46d6eeb7af609082f2a4896719e382d6.zip cpython-7322b1ad46d6eeb7af609082f2a4896719e382d6.tar.gz cpython-7322b1ad46d6eeb7af609082f2a4896719e382d6.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/plat-mac/bundlebuilder.py | 38 |
1 files changed, 29 insertions, 9 deletions
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 @@ if USE_ZIPIMPORT: 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 @@ MAYMISS_MODULES = ['mac', 'os2', 'nt', 'ntpath', 'dos', 'dospath', STRIP_EXEC = "/usr/bin/strip" BOOTSTRAP_SCRIPT = """\ -#!/bin/sh - -execdir=$(dirname "${0}") -executable="${execdir}/%(executable)s" -resdir=$(dirname "${execdir}")/Resources -main="${resdir}/%(mainprogram)s" -PYTHONPATH="$resdir" -export PYTHONPATH -exec "${executable}" "${main}" "$@" +#!/usr/bin/env python + +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 @@ class AppBuilder(BundleBuilder): 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 @@ class AppBuilder(BundleBuilder): 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()) |