PortableOSXPackage

This is just a list of the steps I performed in order to get a portable pymt package for OSX.

DO NOT USE THIS GUIDE. USE THE FINISHED OSX PACKAGE THAT WE PROVIDE.

1. On a fresh install of OSX 10.6 Snow Leopard (i.e., no pymt, no easy_install stuff, no ports, no fink), I installed homebrew: http://github.com/mxcl/homebrew and used it to install SDL and all the other binaries required by pymt.

2. For the gstreamer stuff I used this branch from jodal's fork: http://github.com/jodal/homebrew/tree/gstreamer-to-be-merged - This also installs the python bindings for gstreamer.

3. I installed all the python wrappings via easy_install. I.e., pyopengl, etc.

4. pygame had to be manually adjusted. Their config_darwin.py file seems pretty broken. It didn't find the sdl headers, and adding it to incdirs didn't help. The DependencyFramework class didn't really make that much sense and I just replaced it by normal dependencies. It now found the headers.

5. Although it found the headers, it had problems compiling and esp. linking. I adjusted the Setup file, fixed some strange but obviously wrong includes and built again.

6. I created a directory called pymt_portable and put pymt into it.

7. Also put all the site-packages stuff (might be scattered across the OS. Just import the dependency on a python shell and check with e.g. OpenGL.__file__) into pymt_portable/sitepackages

8. This is not really enough for most packages cause there is some setup.py/site foo going on. I just manually copied the actual source to the appropriate places in the pymt_portable/sitepackages folder

9. Since all that stuff depends on the binaries we built with homebrew, I copied all of those into pymt_portable/lib:

 find . -iname '*.a' -exec cp {} /Users/dennda/pymt_portable/lib/ \;
 find . -iname '*.dylib' -exec cp {} /Users/dennda/pymt_portable/lib/ \;

10. Wrote a small script to test this stuff. It's important to a) add the sitepackages folder and b) the lib/ folder to DYLD_FALLBACK_LIBRARY_PATH. It did NOT WORK with LD_LIBRARY_PATH or DYLD_LIBRARY_PATH. Script:

	import sys
	sys.path = [p for p in sys.path if 'Users' not in p]
	sys.path = [p for p in sys.path if 'site-packages' not in p]
	sys.path.insert(1, '/Users/dennda/pymt_portable/sitepackages')
	sys.path.insert(0, '')
	import os
	os.environ['LD_LIBRARY_PATH'] = os.environ['LD_PRELOAD_PATH'] = '/Users/dennda/pymt_portable/lib'
	print sys.path
	import OpenGL
	print OpenGL.__file__
	import pygame
	print pygame.__file__
	import pygst
	print pygst.__file__
	pygst.require('0.10')
	import gobject
	print gobject.__file__
	import gst
	print gst.__file__
	from gst.extend import discoverer
	print discoverer
	from pymt import *

11. Copied all that stuff to a very fresh 10.6 system (just out of factory) with no ports and stuff installed. Unzipped, adjusted paths in the script, run the script. Should work. EDIT: NOPE! You have to set DYLD_FALLBACK_LIBRARY_PATH manually yourself BEFORE running the python script.

12. I'm sure I forgot half of all the stuff that I did since I tried for ages to get it working. This is just a rough guideline for myself, so AGAIN: DO NOT USE IT, USE OUR FINISHED PACKAGE!

13. One thing I forgot: The python wrappers that homebrew generates are placed as .pth files into system site-packages. These are just references and contain the hardcoded path to the actual sources. Open file in text editor to see the folder and copy the files from there.

14. Next thing i forgot to mention: I also added the compiled cython modules. I just compiled them via the build-ext command of setup.py. (I had to fix the path to GL.h in the generated c files manually because there's still a bug with that on OSX we have to sort out.) I then just kept the .so files around and deleted the .c files.

Making a OSX Application Bundle and DMG

I have put all teh files needed to make a DMG for a new pymt app bundle online here: http://tehansen.de/osx_pymt_installer.zip teh zip file contains a working pymt.app bundle that can be updated a DMG Canvas project file and teh apple script to create symlinks in addition to a REAMDE with more detailed info about each part

OSX Application Bundle

1. Download Platypus: http://www.sveinbjorn.org/platypus

2. Start platypus and fill out teh form: I did teh following:

App Name: PyMT
Script Path: Here You select teh pymt.sh bash script that sets the ENV vars and launches python
Select teh Icon you want (you can also just switch it out later it will be in the app bundle at pymt.app/Contents/Resources/appIcon.icns). The one I made is here: http://tehansen.de/appIcon.icns
Output: None (otherwise it opens other windows)
On teh checkboxes make sure to check "Droppable" so teh app takes dropped files as arguments to the script

Advanced Options (this is stuff that gets populated into the app bundles plist setting file):

Identifier: eu.pymt.PyMT
Author: PyMT Team
Version: I put 0.5..put teh cirrent version

Resource Files (At the bottom): we need to add the lib and pymt (pymt root directory, the one that includes setup.py) here

3.When all this is filled out we just need to hit create and it creates teh launcher. To launch from command line we have to do sh pymt.app/Contents/Resources/script

4. Since we are going to make a symlink, we want this script to be executable, so if it modified, make sure to do chmod +x pymt.app/Contents/Resources/script before putting it in the dmg

DMG (Apples standard way of distributing apps)

1. Download DMGCanvas: http://www.araelium.com/dmgcanvas/

2. Its pretty straight forward, make the background look like you want by setting a background Image

3. Drag teh pymt.app into the canvas as well as teh applications folder (on app folder hold ctrl to create a link...

4.then hit create and your done)

NOTE: There's a problem with pygame. In the easy-install.pth file it does some patchery so a system-installed pygame version is preferred if there is one. If that one's broken or incompatible, it will break the app. A possible solution would be to execute python -S instead of just python which stops the site magic from happening, but that also excludes other 3rd party libraries. My policy here was "if the user has a broken installation, that should be removed anyways and is none of my business". So I didn't use -S, but wanted to note it for the future.

Also the python call should be: exec python "$@", and the Make Symlinks script has to also do a chmod +x on the link it creates, or the user will get a Permission denied error when trying to execute the pymt link. If the script in teh .app bundle is chmod'ed to be executable, all we need to do is create a symlink to it, this also makes sure if the target is changed/updated the symlink still functions properly