Permalink
Browse files

Updating OSX packaging script

-Adding a shell script to build a distributable app for OSX.
-Updating py2app script to use icon, set title etc.
-Removing build generated files from repo and ignoring in .gitignore.
-Couple of minor issues on OSX.
--multiprocessing.Queue.qwait isn't implemented for some unix platforms, so using multiprocessing.Queue.empty instead.
--use correct path on OSX to load images.
  • Loading branch information...
1 parent 806c9dc commit a8ff71e83c3b30ad90ca60f07f7f1353d390b33f @cvanes cvanes committed Nov 30, 2013
View
@@ -1 +1,2 @@
-*.pyc
+*.pyc
+osx_build/
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+cd plumbing
+python py2app_setup.py py2app
+
+# workaround for now to strip out 64 bit libs as wxPython only supports 32 bit
+cd ../../osx_dist
+mv PythonTurtle.app PythonTurtle64.app
+ditto --rsrc --arch i386 PythonTurtle64.app PythonTurtle.app
+rm -rf PythonTurtle64.app
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDisplayName</key>
+ <string>PythonTurtle</string>
+ <key>CFBundleExecutable</key>
+ <string>PythonTurtle</string>
+ <key>CFBundleIdentifier</key>
+ <string>org.pythonmac.unspecified.pythonturtle</string>
+ <key>CFBundleName</key>
+ <string>PythonTurtle</string>
+ <key>CFBundleShortVersionString</key>
+ <string>0.1</string>
+ <key>CFBundleVersion</key>
+ <string>0.1</string>
+ <key>LSArchitecturePriority</key>
+ <array>
+ <string>i386</string>
+ </array>
+</dict>
+</plist>
@@ -2,18 +2,37 @@
This is a setup.py script generated by py2applet
Usage:
- python setup.py py2app
+ python py2app_setup.py py2app
"""
+import os
from setuptools import setup
+from pythonturtlebuildtools import smart_join, data_files
-APP = ['pythonturtle.py']
-DATA_FILES = []
-OPTIONS = {'argv_emulation': True}
+cwd = os.getcwd()
+root_dir = smart_join(cwd, "..", "..")
+src_dir = smart_join(root_dir, "src")
+build_dir = smart_join(cwd, "osx_build")
+dist_dir = smart_join(root_dir, "osx_dist")
+resources_dir = smart_join(src_dir, "resources")
+osx_resources_dir = smart_join(cwd, "osx_resources")
+path_to_script = smart_join(src_dir, "pythonturtle.py")
+path_to_icon = smart_join(resources_dir, "icon.icns")
+path_to_plist = smart_join(osx_resources_dir, "Info.plist")
+
+py2app_options = {
+ 'arch': 'i386',
+ 'argv_emulation': True,
+ 'bdist_base': build_dir,
+ 'dist_dir': dist_dir,
+ 'iconfile': path_to_icon,
+ 'includes': 'wx',
+ 'plist': path_to_plist,
+}
setup(
- app=APP,
- data_files=DATA_FILES,
- options={'py2app': OPTIONS},
- setup_requires=['py2app'],
-)
+ app=[path_to_script],
+ data_files=data_files(resources_dir),
+ options={'py2app': py2app_options},
+ setup_requires=['py2app', 'wxPython'],
+)
@@ -0,0 +1,15 @@
+import os
+
+def smart_join(*args):
+ temp = os.path.join(*args)
+ optimized = os.path.realpath(temp)
+ return str(optimized) # to convert from unicode to ascii
+
+def data_files(resources_dir):
+ data_files=[]
+ for file in os.listdir(resources_dir):
+ f1 = smart_join(resources_dir, file)
+ if os.path.isfile(f1): # skip directories
+ f2 = 'resources', [f1]
+ data_files.append(f2)
+ return data_files
@@ -1,97 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
- <key>CFBundleDevelopmentRegion</key>
- <string>English</string>
- <key>CFBundleDisplayName</key>
- <string>pythonturtle</string>
- <key>CFBundleDocumentTypes</key>
- <array>
- <dict>
- <key>CFBundleTypeOSTypes</key>
- <array>
- <string>****</string>
- <string>fold</string>
- <string>disk</string>
- </array>
- <key>CFBundleTypeRole</key>
- <string>Viewer</string>
- </dict>
- </array>
- <key>CFBundleExecutable</key>
- <string>pythonturtle</string>
- <key>CFBundleIconFile</key>
- <string>pythonturtle</string>
- <key>CFBundleIdentifier</key>
- <string>org.pythonmac.unspecified.pythonturtle</string>
- <key>CFBundleInfoDictionaryVersion</key>
- <string>6.0</string>
- <key>CFBundleName</key>
- <string>pythonturtle</string>
- <key>CFBundlePackageType</key>
- <string>APPL</string>
- <key>CFBundleShortVersionString</key>
- <string>0.0.0</string>
- <key>CFBundleSignature</key>
- <string>????</string>
- <key>CFBundleVersion</key>
- <string>0.0.0</string>
- <key>LSHasLocalizedDisplayName</key>
- <false/>
- <key>NSAppleScriptEnabled</key>
- <false/>
- <key>NSHumanReadableCopyright</key>
- <string>Copyright not specified</string>
- <key>NSMainNibFile</key>
- <string>MainMenu</string>
- <key>NSPrincipalClass</key>
- <string>NSApplication</string>
- <key>PyMainFileNames</key>
- <array>
- <string>__boot__</string>
- </array>
- <key>PyOptions</key>
- <dict>
- <key>alias</key>
- <false/>
- <key>argv_emulation</key>
- <true/>
- <key>no_chdir</key>
- <false/>
- <key>optimize</key>
- <integer>0</integer>
- <key>prefer_ppc</key>
- <false/>
- <key>site_packages</key>
- <false/>
- <key>use_pythonpath</key>
- <false/>
- </dict>
- <key>PyResourcePackages</key>
- <array>
- </array>
- <key>PyRuntimeLocations</key>
- <array>
- <string>@executable_path\..\Frameworks\libpython2.6.dylib</string>
- </array>
- <key>PythonInfoDict</key>
- <dict>
- <key>PythonExecutable</key>
- <string>C:\Python26\python.exe</string>
- <key>PythonLongVersion</key>
- <string>2.6.2c1 (r262c1:71369, Apr 7 2009, 18:44:00) [MSC v.1500 32 bit (Intel)]</string>
- <key>PythonShortVersion</key>
- <string>2.6</string>
- <key>py2app</key>
- <dict>
- <key>alias</key>
- <false/>
- <key>template</key>
- <string>app</string>
- <key>version</key>
- <string>0.3.6</string>
- </dict>
- </dict>
-</dict>
-</plist>
Binary file not shown.
@@ -1 +0,0 @@
-APPL????
@@ -1,137 +0,0 @@
-def _get_argvemulator():
- """argvemulator - create sys.argv from OSA events. Used by applets that
- want unix-style arguments.
- """
-
- import sys
- import traceback
- from Carbon import AE
- from Carbon.AppleEvents import kCoreEventClass, kAEOpenApplication, \
- kAEOpenDocuments, keyDirectObject, typeAEList, typeAlias
- from Carbon import Evt
- from Carbon import File
- from Carbon.Events import highLevelEventMask, kHighLevelEvent
-
- class ArgvCollector:
-
- """A minimal FrameWork.Application-like class"""
-
- def __init__(self):
- self.quitting = 0
-
- AE.AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
- self.__runapp)
- AE.AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
- self.__openfiles)
-
- def close(self):
- AE.AERemoveEventHandler(kCoreEventClass, kAEOpenApplication)
- AE.AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments)
-
- def mainloop(self, mask = highLevelEventMask, timeout = 1*60):
- # Note: this is not the right way to run an event loop in OSX or
- # even "recent" versions of MacOS9. This is however code that has
- # proven itself.
-
- # Remove the funny -psn_xxx_xxx argument
- if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn':
- del sys.argv[1]
-
- stoptime = Evt.TickCount() + timeout
- while not self.quitting and Evt.TickCount() < stoptime:
- self._dooneevent(mask, timeout)
-
- if not self.quitting:
- print "argvemulator: timeout waiting for arguments"
-
- self.close()
-
- def _dooneevent(self, mask = highLevelEventMask, timeout = 1*60):
- got, event = Evt.WaitNextEvent(mask, timeout)
- if got:
- self._lowlevelhandler(event)
-
- def _lowlevelhandler(self, event):
- what, message, when, where, modifiers = event
- h, v = where
- if what == kHighLevelEvent:
- try:
- AE.AEProcessAppleEvent(event)
- except AE.Error, err:
- msg = "High Level Event: %r %r" % (hex(message),
- hex(h | (v<<16)))
- print 'AE error: ', err
- print 'in', msg
- traceback.print_exc()
- return
- else:
- print "Unhandled event:", event
-
-
- def _quit(self):
- self.quitting = 1
-
- def __runapp(self, requestevent, replyevent):
- self._quit()
-
- def __openfiles(self, requestevent, replyevent):
- try:
- listdesc = requestevent.AEGetParamDesc(keyDirectObject,
- typeAEList)
- for i in range(listdesc.AECountItems()):
- aliasdesc = listdesc.AEGetNthDesc(i+1, typeAlias)[1]
- alias = File.Alias(rawdata=aliasdesc.data)
- fsref = alias.FSResolveAlias(None)[0]
- pathname = fsref.as_pathname()
- sys.argv.append(pathname)
- except Exception, e:
- print "argvemulator.py warning: can't unpack an open document event"
- import traceback
- traceback.print_exc()
-
- self._quit()
-
- return ArgvCollector()
-
-def _argv_emulation():
- import sys
- # only use if started by LaunchServices
- for arg in sys.argv[1:]:
- if arg.startswith('-psn'):
- _get_argvemulator().mainloop()
- break
-_argv_emulation()
-
-
-
-def _chdir_resource():
- import os
- os.chdir(os.environ['RESOURCEPATH'])
-_chdir_resource()
-
-
-def _disable_linecache():
- import linecache
- def fake_getline(*args, **kwargs):
- return ''
- linecache.orig_getline = linecache.getline
- linecache.getline = fake_getline
-_disable_linecache()
-
-
-def _run(*scripts):
- global __file__
- import os, sys, site
- sys.frozen = 'macosx_app'
- base = os.environ['RESOURCEPATH']
- site.addsitedir(base)
- site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
- if not scripts:
- import __main__
- for script in scripts:
- path = os.path.join(base, script)
- sys.argv[0] = __file__ = path
- execfile(path, globals(), globals())
-
-
-_run('pythonturtle.py')
@@ -1,16 +0,0 @@
-#!/bin/sh
-#
-# This is the default apptemplate error script
-#
-if ( test -n "$2" ) ; then
- echo "$1 Error"
- echo "An unexpected error has occurred during execution of the main script"
- echo ""
- echo "$2: $3"
- echo ""
- echo "See the Console for a detailed traceback."
-else
- echo "$1 Error"
- echo "MacPython 2.3 is required to run this application.";
- echo "ERRORURL: http://homepages.cwi.nl/~jack/macpython/index.html Visit the MacPython Website";
-fi
Oops, something went wrong.

0 comments on commit a8ff71e

Please sign in to comment.