1. Ronald Oussoren
  2. py2app

Commits

Ronald Oussoren  committed ab7a996

Explicitly disable argv emulation for python 3.x

Argv emulation uses Carbon and those modules aren't supported
in python 3.x. In the longer run usage of the carbon
modules should be replaced by a ctypes based version.

  • Participants
  • Parent commits 3c669e6
  • Branches default

Comments (0)

Files changed (4)

File doc/changelog.rst

View file
 - alias builds no longer use Carbon Aliases and therefore are
   supported with python3 as well (patch by Virgil Dupras)
 
+- argv emulation doesn't work in python 3, this release
+  will tell you abou this instead of silently failing to 
+  build a working bundle.
+
 Bug fixes:
 
 - The ``--alias`` option didn't work when building a plugin

File doc/options.rst

View file
   --no-strip              do not strip debug and local symbols from output
   --no-chdir (-C)         do not change to the data directory
                           (Contents/Resources) [forced for plugins]
-  --semi-standalone (-s)  depend on an existing installation of Python 2.4
+  --semi-standalone (-s)  depend on an existing installation of Python
   --alias (-A)            Use an alias to current source file (for development
                           only!)
-  --argv-emulation (-a)   Use argv emulation [disabled for plugins]
+  --argv-emulation (-a)   Use argv emulation [disabled for plugins]. Does not work with python 3.x
   --argv-inject           Inject some commands into the argv
   --use-pythonpath        Allow PYTHONPATH to effect the interpreter's
                           environment

File py2app/bootstrap/argv_emulation.py

View file
-def _get_argvemulator():
-    """argvemulator - create sys.argv from OSA events. Used by applets that
-    want unix-style arguments.
-    """
+import sys
+if sys.version_info[0] == 3:
+    def _argv_emulation():
+        pass
 
-    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
+else:
+    def _get_argvemulator():
+        """argvemulator - create sys.argv from OSA events. Used by applets that
+        want unix-style arguments.
+        """
 
-    class ArgvCollector:
+        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
 
-        """A minimal FrameWork.Application-like class"""
+        class ArgvCollector:
 
-        def __init__(self):
-            self.quitting = 0
+            """A minimal FrameWork.Application-like class"""
 
-            AE.AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
-                self.__runapp)
-            AE.AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
-                self.__openfiles)
+            def __init__(self):
+                self.quitting = 0
 
-        def close(self):
-            AE.AERemoveEventHandler(kCoreEventClass, kAEOpenApplication)
-            AE.AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments)
+                AE.AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
+                    self.__runapp)
+                AE.AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
+                    self.__openfiles)
 
-        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.
+            def close(self):
+                AE.AERemoveEventHandler(kCoreEventClass, kAEOpenApplication)
+                AE.AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments)
 
-            # Remove the funny -psn_xxx_xxx argument
-            if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn':
-                del sys.argv[1]
+            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.
 
-            stoptime = Evt.TickCount() + timeout
-            while not self.quitting and Evt.TickCount() < stoptime:
-                self._dooneevent(mask, timeout)
+                # Remove the funny -psn_xxx_xxx argument
+                if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn':
+                    del sys.argv[1]
 
-            if not self.quitting:
-                print "argvemulator: timeout waiting for arguments"
+                stoptime = Evt.TickCount() + timeout
+                while not self.quitting and Evt.TickCount() < stoptime:
+                    self._dooneevent(mask, timeout)
 
-            self.close()
+                if not self.quitting:
+                    print "argvemulator: timeout waiting for arguments"
 
-        def _dooneevent(self, mask = highLevelEventMask, timeout = 1*60):
-            got, event = Evt.WaitNextEvent(mask, timeout)
-            if got:
-                self._lowlevelhandler(event)
+                self.close()
 
-        def _lowlevelhandler(self, event):
-            what, message, when, where, modifiers = event
-            h, v = where
-            if what == kHighLevelEvent:
+            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:
-                    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
+                    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()
-                return
-            else:
-                print "Unhandled event:", event
 
+                self._quit()
 
-        def _quit(self):
-            self.quitting = 1
+        return ArgvCollector()
 
-        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
+    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()
 

File py2app/build_app.py

View file
         ("alias", 'A',
          "Use an alias to current source file (for development only!)"),
         ("argv-emulation", 'a',
-         "Use argv emulation [disabled for plugins]"),
+         "Use argv emulation [disabled for plugins]. Does not work with python 3.x"),
         ("argv-inject=", None,
          "Inject some commands into the argv"),
         ("use-pythonpath", None,
         self.eggs = []
 
     def finalize_options (self):
+        if sys.version_info[0] == 3:
+            if self.argv_emulation:
+                raise DistutilsOptionError("argv-emulation is not supported on python 3.x")
+
         if not self.strip:
             self.no_strip = True
         elif self.no_strip: