Bob Ippolito avatar Bob Ippolito committed 081bbd5

remove some more 2.2 cruft
move framework support modules inside their respective packages
expose __C_API__ from objc package instead of _objc module
make the preflight rm safer for Xcode and PB projects with bdist_mpkg

Comments (0)

Files changed (5)

Lib/objc/__init__.py

 This module defines the core interfaces of the Python<->Objective-C bridge.
 """
 
-##
-## Disable gc -- blows up w/Python 2.2.0
-##
-import sys as _sys
-if _sys.version_info[:3] == (2,2,0):
-    import warnings
-    warnings.warn(
-        "Python 2.2.0's garbage collector crashes when used with PyObjC, disabling.  Python 2.3 or later is highly recommended.",
-        RuntimeWarning,
-    )
-    import gc
-    gc.disable()
-
 # Aliases for some common Objective-C constants
 nil=None
 
 from _objc import *
-from _objc import __version__
+from _objc import __version__, __C_API__
 import _FoundationSignatures
 
 try:

Lib/objc/_convenience.py

 TODO:
 - Add external interface: Framework specific modules may want to add to this.
 """
-from objc import setClassExtender, selector, runtime
+from objc import setClassExtender, selector, lookUpClass
 import warnings
 
+__all__ = []
+
 CONVENIENCE_METHODS = {}
 CLASS_METHODS = {}
 
     NSDictionary.items()
     """
     keys = aDict.allKeys()
-    values = aDict.objectsForKeys_notFoundMarker_(keys, runtime.NSNull.null())
+    values = aDict.objectsForKeys_notFoundMarker_(keys, NSNull.null())
     return zip(keys, values)
 
 
 # NSNumber seems to be and abstract base-class that is implemented using
 # NSCFNumber, a CoreFoundation 'proxy'.
 #
-NSDecimalNumber = runtime.NSDecimalNumber
-from _Foundation import NSDecimal
+NSDecimalNumber = lookUpClass('NSDecimalNumber')
+NSNull = lookUpClass('NSNull')
+from Foundation import NSDecimal
 
 def _num_to_python(v):
     """
     Magic method that converts NSNumber values to Python, see
     <Foundation/CFNumber.h> for the magic numbers
     """
-    global NSDecimal
-
     if isinstance(v, NSDecimalNumber):
         return v.decimalValue()
 
     else:
         return r
 
-import __builtin__
-if not hasattr(__builtin__, 'bool'):
-    def bool(x):
-        if x:
-            return 1
-        else:
-            return 0
-
 def __nonzero__CFNumber(numA):
     return bool(_num_to_python(numA))
 

Modules/objc/pyobjc-api.h

 	PyObject* m;
 	PyObject* d;
 	PyObject* api_obj;
-	PyObject* name = PyString_FromString("_objc");
+	PyObject* name = PyString_FromString("objc");
 	
 	m = PyImport_Import(name);
 	Py_DECREF(name);

setup-lib/pyobjc_mpkg.py

 import sys
 from distutils.version import LooseVersion
 from distutils import log
-from bdist_mpkg.bdist_mpkg import bdist_mpkg as _bdist_mpkg
+from bdist_mpkg.command import bdist_mpkg as _bdist_mpkg
 from py2app.util import copy_tree, skipscm
 try:
     set
         self.scheme_map[scheme] = '/Developer/ProjectBuilder Extras'
         copy_tree('ProjectBuilder Extras', schemedir,
             condition=skipjunk, dry_run=self.dry_run, verbose=self.verbose)
+        # skip clean.py
+        cleanpath = os.path.join(schemedir, 'ProjectBuilder Extras', 'Project Templates', 'clean.py')
+        if os.path.exists(cleanpath):
+            os.unlink(cleanpath)
         files = []
         files.extend([
             os.path.join('Project Templates', fn)
         schemedir = os.path.join(self.pkg_base, scheme)
         self.scheme_map[scheme] = '/Library/Application Support/Apple/Developer Tools'
         files = []
-        for path in ['Project Templates', 'File Templates']:
+        for path in [
+                    'Project Templates',
+                    'File Templates/Cocoa',
+                    'File Templates/Pure Python',
+                ]:
             copy_tree(
                 os.path.join('Xcode', path),
                 os.path.join(schemedir, path),
 
 CorePackages = [ 'objc' ]
 CoreExtensions =  [
-    Extension("_objc",
+    Extension("objc._objc",
               sourceFiles,
               extra_compile_args=[
               ] + LIBFFI_CFLAGS + CFLAGS,
 
 FoundationPackages, FoundationExtensions = \
         IfFrameWork('Foundation.framework', [ 'Foundation' ], [
-          Extension("_Foundation",
+          Extension("Foundation._Foundation",
                     [
                         "Modules/Foundation/_Foundation.m",
                     ],
 
 AppKitPackages, AppKitExtensions = \
         IfFrameWork('AppKit.framework', [ 'AppKit' ], [
-          Extension("_AppKit",
+          Extension("AppKit._AppKit",
                     ["Modules/AppKit/_AppKit.m"],
                     extra_compile_args=[
                         "-IModules/objc",
 # AddressBook framework.
 AddressBookPackages, AddressBookExtensions = \
         IfFrameWork('AddressBook.framework', [ 'AddressBook' ], [
-            Extension('_AddressBook',
+            Extension('AddressBook._AddressBook',
                       [ 'Modules/AddressBook/_AddressBook.m' ],
                       extra_compile_args=[
                         '-IModules/objc',
 
 CoreFoundationPackages, CoreFoundationExtensions = \
         IfFrameWork('CoreFoundation.framework', [ 'CoreFoundation' ], [
-            Extension("_machsignals",
+            Extension("PyObjCTools._machsignals",
                       [ 'Modules/CoreFoundation/machsignals.m' ],
                       extra_compile_args=[
                         '-IModules/objc',
 
 SecurityInterfacePackages, SecurityInterfaceExtensions = \
         IfFrameWork('SecurityInterface.framework', [ 'SecurityInterface' ], [
-            Extension('_SecurityInterface',
+            Extension('SecurityInterface._SecurityInterface',
                       [ 'Modules/SecurityInterface/_SecurityInterface.m' ],
                       extra_compile_args=[
                         '-IModules/objc',
 
 ExceptionHandlingPackages, ExceptionHandlingExtensions = \
         IfFrameWork('ExceptionHandling.framework', [ 'ExceptionHandling' ], [
-            Extension('_ExceptionHandling',
+            Extension('ExceptionHandling._ExceptionHandling',
                       [ 'Modules/ExceptionHandling/_ExceptionHandling.m' ],
                       extra_compile_args=[
                         '-IModules/objc',
 
 PrefPanesPackages, PrefPanesExtensions = \
         IfFrameWork('PreferencePanes.framework', [ 'PreferencePanes' ], [
-            Extension('_PreferencePanes',
+            Extension('PreferencePanes._PreferencePanes',
                       [ 'Modules/PreferencePanes/_PreferencePanes.m' ],
                       extra_compile_args=[
                         '-IModules/objc',
 
 InterfaceBuilderPackages, InterfaceBuilderExtensions = \
         IfFrameWork('InterfaceBuilder.framework', [ 'InterfaceBuilder' ], [
-            Extension('_InterfaceBuilder',
+            Extension('InterfaceBuilder._InterfaceBuilder',
                       [ 'Modules/InterfaceBuilder/_InterfaceBuilder.m' ],
                       extra_compile_args=[
                         '-IModules/objc',
 
 WebKitPackages, WebKitExtensions = \
         IfFrameWork('WebKit.framework', [ 'WebKit' ], [
-            Extension('_WebKit',
+            Extension('WebKit._WebKit',
                       [ 'Modules/WebKit/_WebKit.m' ],
                       extra_compile_args=[
                         '-IModules/objc',
 
 if "install" in sys.argv:
     # Hack to remove a previous version that may have been installed
-    # directly into site-packages (pre 0.9) as opposed to a new subdir.
     import shutil
     inst = dist.get_command_obj("install")
     install_dir = inst.install_platlib
     if install_dir is not None:
+        # clean up cruft from pre 0.9
         for name in ("objc", "Foundation", "AppKit", "AddressBook", "autoGIL"):
             path = os.path.join(install_dir, name)
             if os.path.isdir(path):
                 print "(removing old version: %s)" % path
                 os.remove(path)
 
-    # In version 1.1 some of the extension modules moved, clean up the old
-    # location
-    if install_dir is not None:
-        for name in ('objc', 'AppKit', 'Foundation', 'AddressBook', 'WebKit', 'InterfaceBuilder', 'PreferencePanes', 'SecurityInterface'):
-            path = os.path.join(install_dir, 'PyObjC', name)
-            if not os.path.exists(path): continue
-
-            exts = [ fn for fn in os.listdir(path) if fn.endswith('.so') ]
-            for fn in exts:
-                p = os.path.join(path, fn)
-                print "(removing old version: %s)"%(p,)
-                os.unlink(p)
+        # In version 1.2 some of the extension modules moved, clean up the old
+        # location
+        install_dir = os.path.join(install_dir, 'PyObjC')
+        for fn in os.listdir(install_dir):
+            fn = os.path.join(install_dir, fn)
+            if fn.endswith('.so'):
+                os.unlink(fn)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.