[Python-checkins] python/dist/src/Mac/Lib bundlebuilder.py,1.9,1.10

jvr@users.sourceforge.net jvr@users.sourceforge.net
Thu, 28 Nov 2002 03:30:58 -0800


Update of /cvsroot/python/python/dist/src/Mac/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv19365

Modified Files:
	bundlebuilder.py 
Log Message:
- Rewrote bootstapping code in sh so we're really independent of an
installed Python. So we don't use os.execve any longer, which means
we need an actual executable in <myapp>.app/Contents/MacOS. For applets
we make a symlink to the Python executable used to build the applet,
for standalone apps we simply copy it.
- Added support for the new any_missing_maybe() feature of modulefinder.py,
which is pending as patch #643711. Its use is optional so it still works
with the existing version of modulefinder.py


Index: bundlebuilder.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Lib/bundlebuilder.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** bundlebuilder.py	26 Nov 2002 00:34:52 -0000	1.9
--- bundlebuilder.py	28 Nov 2002 11:30:56 -0000	1.10
***************
*** 198,203 ****
  	def report(self):
  		# XXX something decent
! 		import pprint
! 		pprint.pprint(self.__dict__)
  
  
--- 198,202 ----
  	def report(self):
  		# XXX something decent
! 		pass
  
  
***************
*** 228,232 ****
  """ % FROZEN_ARCHIVE
  
! SITE_CO = compile(SITE_PY, "<-bundlebuilder->", "exec")
  
  MAYMISS_MODULES = ['mac', 'os2', 'nt', 'ntpath', 'dos', 'dospath',
--- 227,231 ----
  """ % FROZEN_ARCHIVE
  
! SITE_CO = compile(SITE_PY, "<-bundlebuilder.py->", "exec")
  
  MAYMISS_MODULES = ['mac', 'os2', 'nt', 'ntpath', 'dos', 'dospath',
***************
*** 237,258 ****
  STRIP_EXEC = "/usr/bin/strip"
  
! EXECVE_WRAPPER = """\
! #!/usr/bin/env python
  
! import os
! from sys import argv, executable
! resources = os.path.join(os.path.dirname(os.path.dirname(argv[0])),
! 		"Resources")
! mainprogram = os.path.join(resources, "%(mainprogram)s")
! assert os.path.exists(mainprogram)
! argv.insert(1, mainprogram)
! os.environ["PYTHONPATH"] = resources
! %(setexecutable)s
! os.execve(executable, argv, os.environ)
  """
  
- setExecutableTemplate = """executable = os.path.join(resources, "%s")"""
- pythonhomeSnippet = """os.environ["home"] = resources"""
- 
  
  class AppBuilder(BundleBuilder):
--- 236,251 ----
  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} ${1}
  """
  
  
  class AppBuilder(BundleBuilder):
***************
*** 301,304 ****
--- 294,298 ----
  	# Modules that modulefinder couldn't find:
  	missingModules = []
+ 	maybeMissingModules = []
  
  	# List of all binaries (executables or shared libs), for stripping purposes
***************
*** 322,325 ****
--- 316,324 ----
  			self.name += ".app"
  
+ 		if self.executable is None:
+ 			if not self.standalone:
+ 				self.symlink_exec = 1
+ 			self.executable = sys.executable
+ 
  		if self.nibname:
  			self.plist.NSMainNibFile = self.nibname
***************
*** 332,337 ****
  
  		if self.standalone:
- 			if self.executable is None:  # *assert* that it is None?
- 				self.executable = sys.executable
  			self.findDependencies()
  
--- 331,334 ----
***************
*** 340,354 ****
  		if self.executable is not None:
  			if self.mainprogram is None:
! 				execpath = pathjoin(self.execdir, self.name)
  			else:
! 				execpath = pathjoin(resdir, os.path.basename(self.executable))
  			if not self.symlink_exec:
  				self.files.append((self.executable, execpath))
  				self.binaries.append(execpath)
  			self.execpath = execpath
- 			# For execve wrapper
- 			setexecutable = setExecutableTemplate % os.path.basename(self.executable)
- 		else:
- 			setexecutable = ""  # XXX for locals() call
  
  		if self.mainprogram is not None:
--- 337,348 ----
  		if self.executable is not None:
  			if self.mainprogram is None:
! 				execname = self.name
  			else:
! 				execname = os.path.basename(self.executable)
! 			execpath = pathjoin(self.execdir, execname)
  			if not self.symlink_exec:
  				self.files.append((self.executable, execpath))
  				self.binaries.append(execpath)
  			self.execpath = execpath
  
  		if self.mainprogram is not None:
***************
*** 357,364 ****
  			# Create execve wrapper
  			mainprogram = self.mainprogram  # XXX for locals() call
  			execdir = pathjoin(self.bundlepath, self.execdir)
  			mainwrapperpath = pathjoin(execdir, self.name)
  			makedirs(execdir)
! 			open(mainwrapperpath, "w").write(EXECVE_WRAPPER % locals())
  			os.chmod(mainwrapperpath, 0777)
  
--- 351,359 ----
  			# Create execve wrapper
  			mainprogram = self.mainprogram  # XXX for locals() call
+ 			executable = os.path.basename(self.executable)
  			execdir = pathjoin(self.bundlepath, self.execdir)
  			mainwrapperpath = pathjoin(execdir, self.name)
  			makedirs(execdir)
! 			open(mainwrapperpath, "w").write(BOOTSTRAP_SCRIPT % locals())
  			os.chmod(mainwrapperpath, 0777)
  
***************
*** 375,379 ****
  			os.symlink(os.path.abspath(self.executable), dst)
  
! 		if self.missingModules:
  			self.reportMissing()
  
--- 370,374 ----
  			os.symlink(os.path.abspath(self.executable), dst)
  
! 		if self.missingModules or self.maybeMissingModules:
  			self.reportMissing()
  
***************
*** 475,496 ****
  					self.pymodules.append((name, mod.__code__, ispkg))
  
! 		self.missingModules.extend(mf.any_missing())
  
  	def reportMissing(self):
  		missing = [name for name in self.missingModules
  				if name not in MAYMISS_MODULES]
! 		missingsub = [name for name in missing if "." in name]
! 		missing = [name for name in missing if "." not in name]
  		missing.sort()
! 		missingsub.sort()
  		if missing:
  			self.message("Warning: couldn't find the following modules:", 1)
! 			self.message("  " + ", ".join(missing))
! 		if missingsub:
! 			self.message("Warning: couldn't find the following submodules "
! 				"(but it's probably OK since modulefinder can't distinguish "
! 				"between from \"module import submodule\" and "
! 				"\"from module import name\"):", 1)
! 			self.message("  " + ", ".join(missingsub))
  
  #
--- 470,510 ----
  					self.pymodules.append((name, mod.__code__, ispkg))
  
! 		if hasattr(mf, "any_missing_maybe"):
! 			missing, maybe = mf.any_missing_maybe()
! 		else:
! 			missing = mf.any_missing()
! 			maybe = []
! 		self.missingModules.extend(missing)
! 		self.maybeMissingModules.extend(maybe)
  
  	def reportMissing(self):
  		missing = [name for name in self.missingModules
  				if name not in MAYMISS_MODULES]
! 		if self.maybeMissingModules:
! 			maybe = self.maybeMissingModules
! 		else:
! 			maybe = [name for name in missing if "." in name]
! 			missing = [name for name in missing if "." not in name]
  		missing.sort()
! 		maybe.sort()
! 		if maybe:
! 			self.message("Warning: couldn't find the following submodules:", 1)
! 			self.message("    (Note that these could be false alarms -- "
! 			             "it's not always", 1)
! 			self.message("    possible to distinguish between from \"package import submodule\" ", 1)
! 			self.message("    and \"from package import name\")", 1)
! 			for name in maybe:
! 				self.message("  ? " + name, 1)
  		if missing:
  			self.message("Warning: couldn't find the following modules:", 1)
! 			for name in missing:
! 				self.message("  ? " + name, 1)
! 
! 	def report(self):
! 		# XXX something decent
! 		import pprint
! 		pprint.pprint(self.__dict__)
! 		if self.standalone:
! 			self.reportMissing()
  
  #