util.py change to support Python 2.6.x on Mac

Kevin Altis <[email protected]> Wed, 29 Jul 2009 16:45:24 -0700
Newsgroups gmane.comp.python.pythoncard.devel,gmane.comp.python.pythoncard
Message-ID <[email protected]>
I just got done upgrading to Leopard (finally) on a couple of machines  
and decided to revisit the Python 2.6 problem with any sample or tool  
that makes use of paths such as the codeeditor module. It appears  
there was just a poorly coded hack to support bundlebuilder on the Mac  
that needed a tweak in PythonCard/util.py.

def main_is_frozen():
     if sys.platform == 'darwin':
         # this is a temporary hack for bundlebuilder
         return not (sys.executable == '/System/Library/Frameworks/ 
Python.framework/Versions/2.3/Resources/Python.app/Contents/MacOS/ 
Python' or \
                     sys.executable == '/Library/Frameworks/ 
Python.framework/Versions/2.4/Resources/Python.app/Contents/MacOS/ 
Python' or \
                     sys.executable == '/Library/Frameworks/ 
Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/ 
Python')
     else:
         return (hasattr(sys, "frozen") or # new py2exe, McMillan
                 hasattr(sys, "importers") # old py2exe
                 or imp.is_frozen("__main__")) # tools/freeze, cx_freeze


becomes

def main_is_frozen():
     if sys.platform == 'darwin':
         # this is a temporary hack for bundlebuilder
         return not (sys.executable.endswith('Resources/Python.app/ 
Contents/MacOS/Python')
     else:
         return (hasattr(sys, "frozen") or # new py2exe, McMillan
                 hasattr(sys, "importers") # old py2exe
                 or imp.is_frozen("__main__")) # tools/freeze, cx_freeze


This is still a hack and possibly needs a better solution, but at  
least it appears to allow codeEditor, tabcodeEditor, and the  
resourceEditor among other things to load. Hopefully, this will make  
it easier to find other issues that need to be addressed for  
PythonCard to run correctly with Python 3.x

BTW, if you are messing with various versions of Python on the Mac  
remember that PythonLauncher uses the same settings regardless of  
which version you run from the Finder. In the Terminal, you probably  
need to edit the .cshrc in your home directory if you're trying to run  
python 2.5 by default after installing 2.6. The MacPython installer  
adds the following lines

# Setting PATH for MacPython 2.5
# The orginal version is saved in .cshrc.pysave
set path=(/Library/Frameworks/Python.framework/Versions/Current/bin  
$path)

# Setting PATH for MacPython 2.6
# The orginal version is saved in .cshrc.pysave
set path=(/Library/Frameworks/Python.framework/Versions/2.6/bin $path)

You can always run the version you want by using an explicit path  
like /usr/local/bin/python2.5 or /usr/local/bin/python2.6

ka

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july