Commits

Ronald Oussoren committed 02318f8

Port to py3k

Comments (0)

Files changed (4)

pyobjc-framework-ServiceManagement/PyObjCTest/test_servicemanagement.py

 class TestServiceManagement (TestCase):
     @min_os_level('10.6')
     def testConstants(self):
-        self.failUnlessEqual(kSMRightBlessPrivilegedHelper, "com.apple.ServiceManagement.blesshelper")
-        self.failUnlessEqual(kSMRightModifySystemDaemons, "com.apple.ServiceManagement.daemons.modify")
+        self.assertEqual(kSMRightBlessPrivilegedHelper, b"com.apple.ServiceManagement.blesshelper")
+        self.assertEqual(kSMRightModifySystemDaemons, b"com.apple.ServiceManagement.daemons.modify")
 
-        self.failUnlessIsInstance(kSMDomainSystemLaunchd, unicode)
-        self.failUnlessIsInstance(kSMDomainUserLaunchd, unicode)
-        self.failUnlessIsInstance(kSMInfoKeyPrivilegedExecutables, unicode)
-        self.failUnlessIsInstance(kSMInfoKeyAuthorizedClients, unicode)
+        self.assertIsInstance(kSMDomainSystemLaunchd, unicode)
+        self.assertIsInstance(kSMDomainUserLaunchd, unicode)
+        self.assertIsInstance(kSMInfoKeyPrivilegedExecutables, unicode)
+        self.assertIsInstance(kSMInfoKeyAuthorizedClients, unicode)
 
     @min_os_level('10.6')
     def testFunctions(self):
-        self.failUnlessResultHasType(SMJobCopyDictionary, '^{__CFDictionary=}')
-        self.failUnlessArgHasType(SMJobCopyDictionary, 0, '^{__CFString=}')
-        self.failUnlessArgHasType(SMJobCopyDictionary, 1, '^{__CFString=}')
-        self.failUnlessResultIsCFRetained(SMJobCopyDictionary)
+        self.assertResultHasType(SMJobCopyDictionary, b'^{__CFDictionary=}')
+        self.assertArgHasType(SMJobCopyDictionary, 0, b'^{__CFString=}')
+        self.assertArgHasType(SMJobCopyDictionary, 1, b'^{__CFString=}')
+        self.assertResultIsCFRetained(SMJobCopyDictionary)
         v = SMJobCopyDictionary(kSMDomainUserLaunchd, u'com.apple.FileSyncAgent')
-        self.failUnlessIsInstance(v, CFDictionaryRef)
+        self.assertIsInstance(v, CFDictionaryRef)
 
-        self.failUnlessResultHasType(SMCopyAllJobDictionaries, '^{__CFArray=}')
-        self.failUnlessArgHasType(SMCopyAllJobDictionaries, 0, '^{__CFString=}')
-        self.failUnlessResultIsCFRetained(SMCopyAllJobDictionaries)
+        self.assertResultHasType(SMCopyAllJobDictionaries, b'^{__CFArray=}')
+        self.assertArgHasType(SMCopyAllJobDictionaries, 0, b'^{__CFString=}')
+        self.assertResultIsCFRetained(SMCopyAllJobDictionaries)
         v = SMCopyAllJobDictionaries(kSMDomainUserLaunchd)
-        self.failUnlessIsInstance(v, CFArrayRef)
+        self.assertIsInstance(v, CFArrayRef)
 
-        self.failUnlessResultIsBOOL(SMJobSubmit)
-        self.failUnlessArgHasType(SMJobSubmit, 0, '^{__CFString=}')
-        self.failUnlessArgHasType(SMJobSubmit, 1, '^{__CFDictionary=}')
-        self.failUnlessArgHasType(SMJobSubmit, 2, '^{AuthorizationOpaqueRef=}')
-        self.failUnlessArgHasType(SMJobSubmit, 3, 'o^^{__CFError}')
+        self.assertResultIsBOOL(SMJobSubmit)
+        self.assertArgHasType(SMJobSubmit, 0, b'^{__CFString=}')
+        self.assertArgHasType(SMJobSubmit, 1, b'^{__CFDictionary=}')
+        self.assertArgHasType(SMJobSubmit, 2, b'^{AuthorizationOpaqueRef=}')
+        self.assertArgHasType(SMJobSubmit, 3, b'o^^{__CFError}')
 
-        self.failUnlessResultIsBOOL(SMJobRemove)
-        self.failUnlessArgHasType(SMJobRemove, 0, '^{__CFString=}')
-        self.failUnlessArgHasType(SMJobRemove, 1, '^{__CFString=}')
-        self.failUnlessArgHasType(SMJobRemove, 2, '^{AuthorizationOpaqueRef=}')
-        self.failUnlessArgIsBOOL(SMJobRemove, 3)
-        self.failUnlessArgHasType(SMJobRemove, 4, 'o^^{__CFError}')
+        self.assertResultIsBOOL(SMJobRemove)
+        self.assertArgHasType(SMJobRemove, 0, b'^{__CFString=}')
+        self.assertArgHasType(SMJobRemove, 1, b'^{__CFString=}')
+        self.assertArgHasType(SMJobRemove, 2, b'^{AuthorizationOpaqueRef=}')
+        self.assertArgIsBOOL(SMJobRemove, 3)
+        self.assertArgHasType(SMJobRemove, 4, b'o^^{__CFError}')
 
-        self.failUnlessResultIsBOOL(SMJobBless)
-        self.failUnlessArgHasType(SMJobBless, 0, '^{__CFString=}')
-        self.failUnlessArgHasType(SMJobBless, 1, '^{__CFString=}')
-        self.failUnlessArgHasType(SMJobBless, 2, '^{AuthorizationOpaqueRef=}')
-        self.failUnlessArgHasType(SMJobBless, 3, 'o^^{__CFError}')
+        self.assertResultIsBOOL(SMJobBless)
+        self.assertArgHasType(SMJobBless, 0, b'^{__CFString=}')
+        self.assertArgHasType(SMJobBless, 1, b'^{__CFString=}')
+        self.assertArgHasType(SMJobBless, 2, b'^{AuthorizationOpaqueRef=}')
+        self.assertArgHasType(SMJobBless, 3, b'o^^{__CFError}')
 
 
 

pyobjc-framework-ServiceManagement/PyObjCTest/test_smerrors.py

 class TestSMErrors (TestCase):
     @min_os_level('10.6')
     def testConstants(self):
-        self.failUnlessIsInstance(kSMErrorDomainIPC, unicode)
-        self.failUnlessIsInstance(kSMErrorDomainFramework, unicode)
-        self.failUnlessIsInstance(kSMErrorDomainLaunchd, unicode)
+        self.assertIsInstance(kSMErrorDomainIPC, unicode)
+        self.assertIsInstance(kSMErrorDomainFramework, unicode)
+        self.assertIsInstance(kSMErrorDomainLaunchd, unicode)
 
-        self.failUnlessEqual(kSMErrorInternalFailure, 2)
-        self.failUnlessEqual(kSMErrorInvalidSignature, 3)
-        self.failUnlessEqual(kSMErrorAuthorizationFailure, 4)
-        self.failUnlessEqual(kSMErrorToolNotValid, 5)
-        self.failUnlessEqual(kSMErrorJobNotFound, 6)
-        self.failUnlessEqual(kSMErrorServiceUnavailable, 7)
-        self.failUnlessEqual(kSMErrorJobPlistNotFound, 8)
-        self.failUnlessEqual(kSMErrorJobMustBeEnabled, 9)
+        self.assertEqual(kSMErrorInternalFailure, 2)
+        self.assertEqual(kSMErrorInvalidSignature, 3)
+        self.assertEqual(kSMErrorAuthorizationFailure, 4)
+        self.assertEqual(kSMErrorToolNotValid, 5)
+        self.assertEqual(kSMErrorJobNotFound, 6)
+        self.assertEqual(kSMErrorServiceUnavailable, 7)
+        self.assertEqual(kSMErrorJobPlistNotFound, 8)
+        self.assertEqual(kSMErrorJobMustBeEnabled, 9)
 
 if __name__ == "__main__":
     main()

pyobjc-framework-ServiceManagement/distribute_setup.py

+#!python
+"""Bootstrap distribute installation
+
+If you want to use setuptools in your package's setup.py, just include this
+file in the same directory with it, and add this to the top of your setup.py::
+
+    from distribute_setup import use_setuptools
+    use_setuptools()
+
+If you want to require a specific version of setuptools, set a download
+mirror, or use an alternate download directory, you can do so by supplying
+the appropriate options to ``use_setuptools()``.
+
+This file can also be run as a script to install or upgrade setuptools.
+"""
+import os
+import sys
+import time
+import fnmatch
+import tempfile
+import tarfile
+from distutils import log
+
+try:
+    from site import USER_SITE
+except ImportError:
+    USER_SITE = None
+
+try:
+    import subprocess
+
+    def _python_cmd(*args):
+        args = (sys.executable,) + args
+        return subprocess.call(args) == 0
+
+except ImportError:
+    # will be used for python 2.3
+    def _python_cmd(*args):
+        args = (sys.executable,) + args
+        # quoting arguments if windows
+        if sys.platform == 'win32':
+            def quote(arg):
+                if ' ' in arg:
+                    return '"%s"' % arg
+                return arg
+            args = [quote(arg) for arg in args]
+        return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
+
+DEFAULT_VERSION = "0.6.8"
+DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
+SETUPTOOLS_PKG_INFO = """\
+Metadata-Version: 1.0
+Name: setuptools
+Version: 0.6c9
+Summary: xxxx
+Home-page: xxx
+Author: xxx
+Author-email: xxx
+License: xxx
+Description: xxx
+"""
+
+
+def _install(tarball):
+    # extracting the tarball
+    tmpdir = tempfile.mkdtemp()
+    log.warn('Extracting in %s', tmpdir)
+    old_wd = os.getcwd()
+    try:
+        os.chdir(tmpdir)
+        tar = tarfile.open(tarball)
+        _extractall(tar)
+        tar.close()
+
+        # going in the directory
+        subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
+        os.chdir(subdir)
+        log.warn('Now working in %s', subdir)
+
+        # installing
+        log.warn('Installing Distribute')
+        assert _python_cmd('setup.py', 'install')
+    finally:
+        os.chdir(old_wd)
+
+
+def _build_egg(egg, tarball, to_dir):
+    # extracting the tarball
+    tmpdir = tempfile.mkdtemp()
+    log.warn('Extracting in %s', tmpdir)
+    old_wd = os.getcwd()
+    try:
+        os.chdir(tmpdir)
+        tar = tarfile.open(tarball)
+        _extractall(tar)
+        tar.close()
+
+        # going in the directory
+        subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
+        os.chdir(subdir)
+        log.warn('Now working in %s', subdir)
+
+        # building an egg
+        log.warn('Building a Distribute egg in %s', to_dir)
+        _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
+
+    finally:
+        os.chdir(old_wd)
+    # returning the result
+    log.warn(egg)
+    if not os.path.exists(egg):
+        raise IOError('Could not build the egg.')
+
+
+def _do_download(version, download_base, to_dir, download_delay):
+    egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg'
+                       % (version, sys.version_info[0], sys.version_info[1]))
+    if not os.path.exists(egg):
+        tarball = download_setuptools(version, download_base,
+                                      to_dir, download_delay)
+        _build_egg(egg, tarball, to_dir)
+    sys.path.insert(0, egg)
+    import setuptools
+    setuptools.bootstrap_install_from = egg
+
+
+def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
+                   to_dir=os.curdir, download_delay=15, no_fake=True):
+    # making sure we use the absolute path
+    to_dir = os.path.abspath(to_dir)
+    was_imported = 'pkg_resources' in sys.modules or \
+        'setuptools' in sys.modules
+    try:
+        try:
+            import pkg_resources
+            if not hasattr(pkg_resources, '_distribute'):
+                if not no_fake:
+                    _fake_setuptools()
+                raise ImportError
+        except ImportError:
+            return _do_download(version, download_base, to_dir, download_delay)
+        try:
+            pkg_resources.require("distribute>="+version)
+            return
+        except pkg_resources.VersionConflict:
+            e = sys.exc_info()[1]
+            if was_imported:
+                sys.stderr.write(
+                "The required version of distribute (>=%s) is not available,\n"
+                "and can't be installed while this script is running. Please\n"
+                "install a more recent version first, using\n"
+                "'easy_install -U distribute'."
+                "\n\n(Currently using %r)\n" % (version, e.args[0]))
+                sys.exit(2)
+            else:
+                del pkg_resources, sys.modules['pkg_resources']    # reload ok
+                return _do_download(version, download_base, to_dir,
+                                    download_delay)
+        except pkg_resources.DistributionNotFound:
+            return _do_download(version, download_base, to_dir,
+                                download_delay)
+    finally:
+        if not no_fake:
+            _create_fake_setuptools_pkg_info(to_dir)
+
+def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
+                        to_dir=os.curdir, delay=15):
+    """Download distribute from a specified location and return its filename
+
+    `version` should be a valid distribute version number that is available
+    as an egg for download under the `download_base` URL (which should end
+    with a '/'). `to_dir` is the directory where the egg will be downloaded.
+    `delay` is the number of seconds to pause before an actual download
+    attempt.
+    """
+    # making sure we use the absolute path
+    to_dir = os.path.abspath(to_dir)
+    try:
+        from urllib.request import urlopen
+    except ImportError:
+        from urllib2 import urlopen
+    tgz_name = "distribute-%s.tar.gz" % version
+    url = download_base + tgz_name
+    saveto = os.path.join(to_dir, tgz_name)
+    src = dst = None
+    if not os.path.exists(saveto):  # Avoid repeated downloads
+        try:
+            log.warn("Downloading %s", url)
+            src = urlopen(url)
+            # Read/write all in one block, so we don't create a corrupt file
+            # if the download is interrupted.
+            data = src.read()
+            dst = open(saveto, "wb")
+            dst.write(data)
+        finally:
+            if src:
+                src.close()
+            if dst:
+                dst.close()
+    return os.path.realpath(saveto)
+
+
+def _patch_file(path, content):
+    """Will backup the file then patch it"""
+    existing_content = open(path).read()
+    if existing_content == content:
+        # already patched
+        log.warn('Already patched.')
+        return False
+    log.warn('Patching...')
+    _rename_path(path)
+    f = open(path, 'w')
+    try:
+        f.write(content)
+    finally:
+        f.close()
+    return True
+
+
+def _same_content(path, content):
+    return open(path).read() == content
+
+
+def _rename_path(path):
+    new_name = path + '.OLD.%s' % time.time()
+    log.warn('Renaming %s into %s', path, new_name)
+    try:
+        from setuptools.sandbox import DirectorySandbox
+        def _violation(*args):
+            pass
+        DirectorySandbox._violation = _violation
+    except ImportError:
+        pass
+
+    os.rename(path, new_name)
+    return new_name
+
+
+def _remove_flat_installation(placeholder):
+    if not os.path.isdir(placeholder):
+        log.warn('Unkown installation at %s', placeholder)
+        return False
+    found = False
+    for file in os.listdir(placeholder):
+        if fnmatch.fnmatch(file, 'setuptools*.egg-info'):
+            found = True
+            break
+    if not found:
+        log.warn('Could not locate setuptools*.egg-info')
+        return
+
+    log.warn('Removing elements out of the way...')
+    pkg_info = os.path.join(placeholder, file)
+    if os.path.isdir(pkg_info):
+        patched = _patch_egg_dir(pkg_info)
+    else:
+        patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO)
+
+    if not patched:
+        log.warn('%s already patched.', pkg_info)
+        return False
+    # now let's move the files out of the way
+    for element in ('setuptools', 'pkg_resources.py', 'site.py'):
+        element = os.path.join(placeholder, element)
+        if os.path.exists(element):
+            _rename_path(element)
+        else:
+            log.warn('Could not find the %s element of the '
+                     'Setuptools distribution', element)
+    return True
+
+
+def _after_install(dist):
+    log.warn('After install bootstrap.')
+    placeholder = dist.get_command_obj('install').install_purelib
+    _create_fake_setuptools_pkg_info(placeholder)
+
+def _create_fake_setuptools_pkg_info(placeholder):
+    if not placeholder or not os.path.exists(placeholder):
+        log.warn('Could not find the install location')
+        return
+    pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1])
+    setuptools_file = 'setuptools-0.6c9-py%s.egg-info' % pyver
+    pkg_info = os.path.join(placeholder, setuptools_file)
+    if os.path.exists(pkg_info):
+        log.warn('%s already exists', pkg_info)
+        return
+    log.warn('Creating %s', pkg_info)
+    f = open(pkg_info, 'w')
+    try:
+        f.write(SETUPTOOLS_PKG_INFO)
+    finally:
+        f.close()
+    pth_file = os.path.join(placeholder, 'setuptools.pth')
+    log.warn('Creating %s', pth_file)
+    f = open(pth_file, 'w')
+    try:
+        f.write(os.path.join(os.curdir, setuptools_file))
+    finally:
+        f.close()
+
+
+def _patch_egg_dir(path):
+    # let's check if it's already patched
+    pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
+    if os.path.exists(pkg_info):
+        if _same_content(pkg_info, SETUPTOOLS_PKG_INFO):
+            log.warn('%s already patched.', pkg_info)
+            return False
+    _rename_path(path)
+    os.mkdir(path)
+    os.mkdir(os.path.join(path, 'EGG-INFO'))
+    pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
+    f = open(pkg_info, 'w')
+    try:
+        f.write(SETUPTOOLS_PKG_INFO)
+    finally:
+        f.close()
+    return True
+
+
+def _before_install():
+    log.warn('Before install bootstrap.')
+    _fake_setuptools()
+
+
+def _under_prefix(location):
+    if 'install' not in sys.argv:
+        return True
+    args = sys.argv[sys.argv.index('install')+1:]
+    for index, arg in enumerate(args):
+        for option in ('--root', '--prefix'):
+            if arg.startswith('%s=' % option):
+                top_dir = arg.split('root=')[-1]
+                return location.startswith(top_dir)
+            elif arg == option:
+                if len(args) > index:
+                    top_dir = args[index+1]
+                    return location.startswith(top_dir)
+            elif option == '--user' and USER_SITE is not None:
+                return location.startswith(USER_SITE)
+    return True
+
+
+def _fake_setuptools():
+    log.warn('Scanning installed packages')
+    try:
+        import pkg_resources
+    except ImportError:
+        # we're cool
+        log.warn('Setuptools or Distribute does not seem to be installed.')
+        return
+    ws = pkg_resources.working_set
+    try:
+        setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools',
+                                  replacement=False))
+    except TypeError:
+        # old distribute API
+        setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools'))
+
+    if setuptools_dist is None:
+        log.warn('No setuptools distribution found')
+        return
+    # detecting if it was already faked
+    setuptools_location = setuptools_dist.location
+    log.warn('Setuptools installation detected at %s', setuptools_location)
+
+    # if --root or --preix was provided, and if
+    # setuptools is not located in them, we don't patch it
+    if not _under_prefix(setuptools_location):
+        log.warn('Not patching, --root or --prefix is installing Distribute'
+                 ' in another location')
+        return
+
+    # let's see if its an egg
+    if not setuptools_location.endswith('.egg'):
+        log.warn('Non-egg installation')
+        res = _remove_flat_installation(setuptools_location)
+        if not res:
+            return
+    else:
+        log.warn('Egg installation')
+        pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO')
+        if (os.path.exists(pkg_info) and
+            _same_content(pkg_info, SETUPTOOLS_PKG_INFO)):
+            log.warn('Already patched.')
+            return
+        log.warn('Patching...')
+        # let's create a fake egg replacing setuptools one
+        res = _patch_egg_dir(setuptools_location)
+        if not res:
+            return
+    log.warn('Patched done.')
+    _relaunch()
+
+
+def _relaunch():
+    log.warn('Relaunching...')
+    # we have to relaunch the process
+    args = [sys.executable] + sys.argv
+    sys.exit(subprocess.call(args))
+
+
+def _extractall(self, path=".", members=None):
+    """Extract all members from the archive to the current working
+       directory and set owner, modification time and permissions on
+       directories afterwards. `path' specifies a different directory
+       to extract to. `members' is optional and must be a subset of the
+       list returned by getmembers().
+    """
+    import copy
+    import operator
+    from tarfile import ExtractError
+    directories = []
+
+    if members is None:
+        members = self
+
+    for tarinfo in members:
+        if tarinfo.isdir():
+            # Extract directories with a safe mode.
+            directories.append(tarinfo)
+            tarinfo = copy.copy(tarinfo)
+            tarinfo.mode = 448 # decimal for oct 0700
+        self.extract(tarinfo, path)
+
+    # Reverse sort directories.
+    if sys.version_info < (2, 4):
+        def sorter(dir1, dir2):
+            return cmp(dir1.name, dir2.name)
+        directories.sort(sorter)
+        directories.reverse()
+    else:
+        directories.sort(key=operator.attrgetter('name'), reverse=True)
+
+    # Set correct owner, mtime and filemode on directories.
+    for tarinfo in directories:
+        dirpath = os.path.join(path, tarinfo.name)
+        try:
+            self.chown(tarinfo, dirpath)
+            self.utime(tarinfo, dirpath)
+            self.chmod(tarinfo, dirpath)
+        except ExtractError:
+            e = sys.exc_info()[1]
+            if self.errorlevel > 1:
+                raise
+            else:
+                self._dbg(1, "tarfile: %s" % e)
+
+
+def main(argv, version=DEFAULT_VERSION):
+    """Install or upgrade setuptools and EasyInstall"""
+    tarball = download_setuptools()
+    _install(tarball)
+
+
+if __name__ == '__main__':
+    main(sys.argv[1:])

pyobjc-framework-ServiceManagement/pyobjc_setup.py

 
 __all__ = ('setup', 'Extension', 'Command')
 
-import ez_setup
-ez_setup.use_setuptools()
+import sys
+if sys.version_info[:2] < (3, 0):
+    import ez_setup
+    ez_setup.use_setuptools()
+
+    from setuptools.command.test import test as oc_test
+    from setuptools.command.build_py import build_py as oc_build_py
+
+    extra_args = {}
+
+
+else:
+    import distribute_setup
+    distribute_setup.use_setuptools()
+
+    from setuptools.command import test
+    from setuptools.command import build_py
+
+    from distutils import log
+
+    extra_args=dict(
+        use_2to3 = True,
+    )
+
+
+    class oc_build_py (build_py.build_py):
+        def build_packages(self):
+            log.info("Overriding build_packages to copy PyObjCTest")
+            p = self.packages
+            self.packages = list(self.packages) + ['PyObjCTest']
+            try:
+                build_py.build_py.build_packages(self)
+            finally:
+                self.packages = p
+
+
+
+    class oc_test (test.test):
+        def run_tests(self):
+            import sys, os
+
+            rootdir =  os.path.dirname(os.path.abspath(__file__))
+            if rootdir in sys.path:
+                sys.path.remove(rootdir)
+
+            import PyObjCTest
+            import unittest
+            from pkg_resources import EntryPoint
+            loader_ep = EntryPoint.parse("x="+self.test_loader)
+            loader_class = loader_ep.load(require=False)
+
+            unittest.main(None, None, [unittest.__file__]+self.test_args, testLoader=loader_class())
+
+
 
 from setuptools import setup as _setup, Extension as _Extension, Command
 from distutils.errors import DistutilsPlatformError
 from distutils.command import build, install, install_lib
 from setuptools.command import develop, test, build_ext
+import pkg_resources
+import shutil
+import os
 import plistlib
 import sys
 import __main__
 
 class pyobjc_build_ext (build_ext.build_ext):
     def run(self):
+
+        # Ensure that the PyObjC header files are available
+        # in 2.3 and later the headers are in the egg,
+        # before that we ship a copy.
+        dist, = pkg_resources.require('pyobjc-core')
+
+        include_root = os.path.join(self.build_temp, 'pyobjc-include')
+        if os.path.exists(include_root):
+            shutil.rmtree(include_root)
+
+        os.makedirs(include_root)
+        if dist.has_metadata('include'):
+            for fn in dist.metadata_listdir('include'):
+                data = dist.get_metadata('include/%s'%(fn,))
+                open(os.path.join(include_root, fn), 'w').write(data)
+
+        else:
+            data = gPyObjCAPI_H
+            open(os.path.join(include_rot, 'pyobjc-api.h'), 'w').write(data)
+
+        for e in self.extensions:
+            if include_root not in e.include_dirs:
+                e.include_dirs.append(include_root)
+
+        # Run the actual build
         build_ext.build_ext.run(self)
+
+        # Then tweak the copy_extensions bit to ensure PyObjCTest gets
+        # copied to the right place.
         extensions = self.extensions
         self.extensions = [
             e for e in extensions if e.name.startswith('PyObjCTest') ]
         cmdclass=None,
         **kwds):
 
+
+    k = kwds.copy()
+    k.update(extra_args)
+
     os_level = get_os_level()
     os_compatible = True
     if sys.platform != 'darwin':
             return subcommand
 
         cmdclass['build'] = create_command_subclass(build.build)
-        cmdclass['test'] = create_command_subclass(test.test)
+        cmdclass['test'] = create_command_subclass(oc_test)
         cmdclass['install'] = create_command_subclass(install.install)
         cmdclass['develop'] = create_command_subclass(develop.develop)
+        cmdclass['build_py'] = create_command_subclass(oc_build_py)
     else:
         cmdclass['build_ext'] = pyobjc_build_ext
         cmdclass['install_lib'] = pyobjc_install_lib
+        cmdclass['test'] = oc_test
+        cmdclass['build_py'] = oc_build_py
+
+
 
     _setup(
         cmdclass=cmdclass, 
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = True,
-        **kwds
+        **k
     ) 
+
+
+gPyObjCAPI_H="""\
+#ifndef PyObjC_API_H
+#define PyObjC_API_H
+
+/*
+ * Use this in helper modules for the objc package, and in wrappers
+ * for functions that deal with objective-C objects/classes
+ * 
+ * This header defines some utility wrappers for importing and using 
+ * the core bridge. 
+ *
+ * This is the *only* header file that should be used to access 
+ * functionality in the core bridge.
+ *
+ * WARNING: this file is not part of the public interface of PyObjC and
+ * might change or be removed without warning or regard for backward
+ * compatibility.
+ */
+
+#include "Python.h"
+#include <objc/objc.h>
+
+#import <Foundation/Foundation.h>
+
+#ifndef CGFLOAT_DEFINED
+
+#ifdef __LP64__
+# error "Huh? 64-bit but no CFFloat available???"
+#endif
+
+typedef float CGFloat;
+#define CGFLOAT_MIN FLT_MIN
+#define CGFLOAT_MAX FLT_MAX
+#define CGFLOAT_IS_DOUBLE 0
+#define CGFLOAT_DEFINED
+
+#endif /* CGFLOAT_DEFINED */
+
+
+#ifndef NSINTEGER_DEFINED
+
+#ifdef __LP64__
+# error "Huh? 64-bit but no NSINTEGER available???"
+#endif
+
+typedef int NSInteger;
+typedef unsigned int NSUInteger;
+
+#define NSIntegerMax    LONG_MAX
+#define NSIntegerMin    LONG_MIN
+#define NSUIntegerMax   ULONG_MAX
+
+#define NSINTEGER_DEFINED
+
+#endif
+
+
+#ifndef PyObjC_COMPAT_H
+#if (PY_VERSION_HEX < 0x02050000)
+typedef int Py_ssize_t;
+#define PY_FORMAT_SIZE_T ""
+#define Py_ARG_SIZE_T "n"
+#define PY_SSIZE_T_MAX INT_MAX
+
+#else
+
+#define Py_ARG_SIZE_T "i"
+#endif
+#endif
+
+#import <Foundation/NSException.h>
+
+struct PyObjC_WeakLink {
+	const char* name;
+	void (*func)(void);
+};
+
+
+/* threading support */
+#ifdef NO_OBJC2_RUNTIME
+#define PyObjC_DURING \
+		Py_BEGIN_ALLOW_THREADS \
+		NS_DURING
+
+#define PyObjC_HANDLER NS_HANDLER
+
+#define PyObjC_ENDHANDLER \
+		NS_ENDHANDLER \
+		Py_END_ALLOW_THREADS
+#else
+
+#define	PyObjC_DURING \
+		Py_BEGIN_ALLOW_THREADS \
+		@try {
+
+#define PyObjC_HANDLER } @catch(volatile NSObject* _localException) { \
+		NSException* localException __attribute__((__unused__))= (NSException*)_localException;
+
+#define PyObjC_ENDHANDLER \
+		} \
+		Py_END_ALLOW_THREADS
+
+#endif
+
+#define PyObjC_BEGIN_WITH_GIL \
+	{ \
+		PyGILState_STATE _GILState; \
+		_GILState = PyGILState_Ensure(); 
+
+#define PyObjC_GIL_FORWARD_EXC() \
+		do { \
+            PyObjCErr_ToObjCWithGILState(&_GILState); \
+		} while (0)
+
+
+#define PyObjC_GIL_RETURN(val) \
+		do { \
+			PyGILState_Release(_GILState); \
+			return (val); \
+		} while (0)
+
+#define PyObjC_GIL_RETURNVOID \
+		do { \
+			PyGILState_Release(_GILState); \
+			return; \
+		} while (0)
+
+
+#define PyObjC_END_WITH_GIL \
+		PyGILState_Release(_GILState); \
+	}
+
+
+
+#include <objc/objc-runtime.h>
+
+/* On 10.1 there are no defines for the OS version. */
+#ifndef MAC_OS_X_VERSION_10_1
+#define MAC_OS_X_VERSION_10_1 1010
+#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_1
+
+#error "MAC_OS_X_VERSION_10_1 not defined. You aren't running 10.1 are you?"
+
+#endif
+
+#ifndef MAC_OS_X_VERSION_10_2
+#define MAC_OS_X_VERSION_10_2 1020
+#endif
+
+#ifndef MAC_OS_X_VERSION_10_3
+#define MAC_OS_X_VERSION_10_3 1030
+#endif
+
+#ifndef MAC_OS_X_VERSION_10_4
+#define MAC_OS_X_VERSION_10_4 1040
+#endif
+
+#ifndef MAC_OS_X_VERSION_10_5
+#define MAC_OS_X_VERSION_10_5 1050
+#endif
+
+/* Current API version, increase whenever:
+ * - Semantics of current functions change
+ * - Functions are removed
+ * Do not increase when adding a new function, the struct_len field
+ * can be used for detecting if a function has been added.
+ *
+ * HISTORY:
+ * - Version 2.2 adds PyObjCUnsupportedMethod_IMP 
+ *       and PyObjCUnsupportedMethod_Caller 
+ * - Version 2.1 adds PyObjCPointerWrapper_Register 
+ * - Version 2 adds an argument to PyObjC_InitSuper
+ * - Version 3 adds another argument to PyObjC_CallPython
+ * - Version 4 adds PyObjCErr_ToObjCGILState
+ * - Version 4.1 adds PyObjCRT_AlignOfType and PyObjCRT_SizeOfType
+ *         (PyObjC_SizeOfType is now deprecated)
+ * - Version 4.2 adds PyObjCRT_SELName
+ * - Version 4.3 adds PyObjCRT_SimplifySignature
+ * - Version 4.4 adds PyObjC_FreeCArray, PyObjC_PythonToCArray and
+ *   		PyObjC_CArrayToPython
+ * - Version 5 modifies the signature for PyObjC_RegisterMethodMapping,
+ *	PyObjC_RegisterSignatureMapping and PyObjCUnsupportedMethod_IMP,
+ *      adds PyObjC_RegisterStructType and removes PyObjC_CallPython
+ * - Version 6 adds PyObjCIMP_Type, PyObjCIMP_GetIMP and PyObjCIMP_GetSelector
+ * - Version 7 adds PyObjCErr_AsExc, PyGILState_Ensure
+ * - Version 8 adds PyObjCObject_IsUninitialized,
+        removes PyObjCSelector_IsInitializer
+ * - Version 9 (???)
+ * - Version 10 changes the signature of PyObjCRT_SimplifySignature
+ * - Version 11 adds PyObjCObject_Convert, PyObjCSelector_Convert,
+     PyObjCClass_Convert, PyObjC_ConvertBOOL, and PyObjC_ConvertChar
+ * - Version 12 adds PyObjCObject_New
+ * - Version 13 adds PyObjCCreateOpaquePointerType
+ * - Version 14 adds PyObjCObject_NewTransient, PyObjCObject_ReleaseTransient
+ * - Version 15 changes the interface of PyObjCObject_New
+ * - Version 16 adds PyObjC_PerformWeaklinking
+ * - Version 17 introduces Py_ssize_t support
+ * - Version 18 introduces several API incompatibilities
+ */
+#define PYOBJC_API_VERSION 18
+
+#define PYOBJC_API_NAME "__C_API__"
+
+/* 
+ * Only add items to the end of this list!
+ */
+typedef int (RegisterMethodMappingFunctionType)(
+			Class, 
+			SEL, 
+			PyObject *(*)(PyObject*, PyObject*, PyObject*),
+			void (*)(void*, void*, void**, void*));
+
+struct pyobjc_api {
+	int	      api_version;	/* API version */
+	size_t	      struct_len;	/* Length of this struct */
+	PyTypeObject* class_type;	/* PyObjCClass_Type    */
+	PyTypeObject* object_type;	/* PyObjCObject_Type   */
+	PyTypeObject* select_type;	/* PyObjCSelector_Type */
+
+	/* PyObjC_RegisterMethodMapping */
+	RegisterMethodMappingFunctionType *register_method_mapping;
+
+	/* PyObjC_RegisterSignatureMapping */
+	int (*register_signature_mapping)(
+			char*,
+			PyObject *(*)(PyObject*, PyObject*, PyObject*),
+			void (*)(void*, void*, void**, void*));
+
+	/* PyObjCObject_GetObject */
+	id (*obj_get_object)(PyObject*);
+
+	/* PyObjCObject_ClearObject */
+	void (*obj_clear_object)(PyObject*);
+
+	/* PyObjCClass_GetClass */
+	Class (*cls_get_class)(PyObject*);
+
+	/* PyObjCClass_New */
+	PyObject* (*cls_to_python)(Class cls);
+
+	/* PyObjC_PythonToId */
+	id (*python_to_id)(PyObject*);
+
+	/* PyObjC_IdToPython */
+	PyObject* (*id_to_python)(id);
+
+	/* PyObjCErr_FromObjC */
+	void (*err_objc_to_python)(NSException*);
+
+	/* PyObjCErr_ToObjC */
+	void (*err_python_to_objc)(void);
+
+	/* PyObjC_PythonToObjC */
+	int (*py_to_objc)(const char*, PyObject*, void*);
+
+	/* PyObjC_ObjCToPython */
+	PyObject* (*objc_to_py)(const char*, void*);
+
+	/* PyObjC_SizeOfType */
+	Py_ssize_t   (*sizeof_type)(const char*);
+
+	/* PyObjCSelector_GetClass */
+	Class	   (*sel_get_class)(PyObject* sel);
+
+	/* PyObjCSelector_GetSelector */
+	SEL	   (*sel_get_sel)(PyObject* sel);
+
+	/* PyObjC_InitSuper */ 	
+	void	(*fill_super)(struct objc_super*, Class, id);
+
+	/* PyObjC_InitSuperCls */
+	void	(*fill_super_cls)(struct objc_super*, Class, Class);
+
+	/* PyObjCPointerWrapper_Register */ 
+	int  (*register_pointer_wrapper)(
+		        const char*, PyObject* (*pythonify)(void*),
+			int (*depythonify)(PyObject*, void*)
+		);
+
+	void (*unsupported_method_imp)(void*, void*, void**, void*);
+	PyObject* (*unsupported_method_caller)(PyObject*, PyObject*, PyObject*);
+
+	/* PyObjCErr_ToObjCWithGILState */
+	void (*err_python_to_objc_gil)(PyGILState_STATE* state);
+
+	/* PyObjCRT_AlignOfType */
+	Py_ssize_t (*alignof_type)(const char* typestr);
+
+	/* PyObjCRT_SELName */
+	const char* (*selname)(SEL sel);
+
+	/* PyObjCRT_SimplifySignature */
+	int (*simplify_sig)(char* signature, char* buf, size_t buflen);
+
+	/* PyObjC_FreeCArray */
+	void    (*free_c_array)(int,void*);
+
+	/* PyObjC_PythonToCArray */
+	int     (*py_to_c_array)(BOOL, BOOL, const char*, PyObject*, void**, Py_ssize_t*, PyObject**);
+	
+	/* PyObjC_CArrayToPython */
+	PyObject* (*c_array_to_py)(const char*, void*, Py_ssize_t);
+
+	/* PyObjC_RegisterStructType */
+	PyObject* (*register_struct)(const char*, const char*, const char*, initproc, Py_ssize_t, const char**);
+
+	/* PyObjCIMP_Type */
+	PyTypeObject* imp_type;
+
+	/* PyObjCIMP_GetIMP */
+	IMP  (*imp_get_imp)(PyObject*);
+
+	/* PyObjCIMP_GetSelector */
+	SEL  (*imp_get_sel)(PyObject*);
+
+	/* PyObjCErr_AsExc */
+	NSException* (*err_python_to_nsexception)(void);
+
+	/* PyGILState_Ensure */
+	PyGILState_STATE (*gilstate_ensure)(void);
+
+	/* PyObjCObject_IsUninitialized */
+	int (*obj_is_uninitialized)(PyObject*);
+
+	/* PyObjCObject_Convert */
+	int (*pyobjcobject_convert)(PyObject*,void*);
+
+	/* PyObjCSelector_Convert */
+	int (*pyobjcselector_convert)(PyObject*,void*);
+
+	/* PyObjCClass_Convert */
+	int (*pyobjcclass_convert)(PyObject*,void*);
+
+	/* PyObjC_ConvertBOOL */
+	int (*pyobjc_convertbool)(PyObject*,void*);
+
+	/* PyObjC_ConvertChar */
+	int (*pyobjc_convertchar)(PyObject*,void*);
+
+	/* PyObjCObject_New */
+	PyObject* (*pyobjc_object_new)(id, int , int);
+
+	/* PyObjCCreateOpaquePointerType */
+	PyObject* (*pointer_type_new)(const char*, const char*, const char*);
+
+	/* PyObject* PyObjCObject_NewTransient(id objc_object, int* cookie); */
+	PyObject* (*newtransient)(id objc_object, int* cookie);
+
+	/* void PyObjCObject_ReleaseTransient(PyObject* proxy, int cookie); */
+	void (*releasetransient)(PyObject* proxy, int cookie);
+
+	void (*doweaklink)(PyObject*, struct PyObjC_WeakLink*);
+
+	const char* (*removefields)(char*, const char*);
+
+	PyObject** pyobjc_null;
+
+	int (*dep_c_array_count)(const char* type, Py_ssize_t count, BOOL strict, PyObject* value, void* datum);
+
+	PyObject* (*varlistnew)(const char* tp, void* array);
+};
+
+#ifndef PYOBJC_BUILD
+
+#ifndef PYOBJC_METHOD_STUB_IMPL
+static struct pyobjc_api*	PyObjC_API;
+#endif /* PYOBJC_METHOD_STUB_IMPL */
+
+#define PyObjCObject_Check(obj) PyObject_TypeCheck(obj, PyObjC_API->object_type)
+#define PyObjCClass_Check(obj)  PyObject_TypeCheck(obj, PyObjC_API->class_type)
+#define PyObjCSelector_Check(obj)  PyObject_TypeCheck(obj, PyObjC_API->select_type)
+#define PyObjCIMP_Check(obj)  PyObject_TypeCheck(obj, PyObjC_API->imp_type)
+#define PyObjCObject_GetObject (PyObjC_API->obj_get_object)
+#define PyObjCObject_ClearObject (PyObjC_API->obj_clear_object)
+#define PyObjCClass_GetClass   (PyObjC_API->cls_get_class)
+#define PyObjCClass_New 	     (PyObjC_API->cls_to_python)
+#define PyObjCSelector_GetClass (PyObjC_API->sel_get_class)
+#define PyObjCSelector_GetSelector (PyObjC_API->sel_get_sel)
+#define PyObjC_PythonToId      (PyObjC_API->python_to_id)
+#define PyObjC_IdToPython      (PyObjC_API->id_to_python)
+#define PyObjCErr_FromObjC     (PyObjC_API->err_objc_to_python)
+#define PyObjCErr_ToObjC       (PyObjC_API->err_python_to_objc)
+#define PyObjCErr_ToObjCWithGILState       (PyObjC_API->err_python_to_objc_gil)
+#define PyObjCErr_AsExc        (PyObjC_API->err_python_to_nsexception)
+#define PyObjC_PythonToObjC    (PyObjC_API->py_to_objc)
+#define PyObjC_ObjCToPython    (PyObjC_API->objc_to_py)
+#define PyObjC_RegisterMethodMapping (PyObjC_API->register_method_mapping)
+#define PyObjC_RegisterSignatureMapping (PyObjC_API->register_signature_mapping)
+#define PyObjC_SizeOfType      (PyObjC_API->sizeof_type)
+#define PyObjC_PythonToObjC   (PyObjC_API->py_to_objc)
+#define PyObjC_ObjCToPython   (PyObjC_API->objc_to_py)
+#define PyObjC_InitSuper	(PyObjC_API->fill_super)
+#define PyObjC_InitSuperCls	(PyObjC_API->fill_super_cls)
+#define PyObjCPointerWrapper_Register (PyObjC_API->register_pointer_wrapper)
+#define PyObjCUnsupportedMethod_IMP (PyObjC_API->unsupported_method_imp)
+#define PyObjCUnsupportedMethod_Caller (PyObjC_API->unsupported_method_caller)
+#define PyObjCRT_SizeOfType      (PyObjC_API->sizeof_type)
+#define PyObjCRT_AlignOfType	(PyObjC_API->alignof_type)
+#define PyObjCRT_SELName	(PyObjC_API->selname)
+#define PyObjCRT_SimplifySignature	(PyObjC_API->simplify_sig)
+#define PyObjC_FreeCArray	(PyObjC_API->free_c_array)
+#define PyObjC_PythonToCArray	(PyObjC_API->py_to_c_array)
+#define PyObjC_CArrayToPython	(PyObjC_API->c_array_to_py)
+#define PyObjC_RegisterStructType   (PyObjC_API->register_struct)
+#define PyObjCIMP_GetIMP   (PyObjC_API->imp_get_imp)
+#define PyObjCIMP_GetSelector   (PyObjC_API->imp_get_sel)
+#define PyObjCObject_IsUninitialized (PyObjC_API->obj_is_uninitialized)
+#define PyObjCObject_Convert (PyObjC_API->pyobjcobject_convert)
+#define PyObjCSelector_Convert (PyObjC_API->pyobjcselector_convert)
+#define PyObjCClass_Convert (PyObjC_API->pyobjcselector_convert)
+#define PyObjC_ConvertBOOL (PyObjC_API->pyobjc_convertbool)
+#define PyObjC_ConvertChar (PyObjC_API->pyobjc_convertchar)
+#define PyObjCObject_New (PyObjC_API->pyobjc_object_new)
+#define PyObjCCreateOpaquePointerType (PyObjC_API->pointer_type_new)
+#define PyObjCObject_NewTransient (PyObjC_API->newtransient)
+#define PyObjCObject_ReleaseTransient (PyObjC_API->releasetransient)
+#define PyObjC_PerformWeaklinking (PyObjC_API->doweaklink)
+#define PyObjCRT_RemoveFieldNames (PyObjC_API->removefields)
+#define PyObjC_NULL		  (*(PyObjC_API->pyobjc_null))
+#define PyObjC_DepythonifyCArray  (PyObjC_API->dep_c_array_count)
+#define PyObjC_VarList_New  (PyObjC_API->varlistnew)
+
+
+#ifndef PYOBJC_METHOD_STUB_IMPL
+
+static int
+PyObjC_ImportAPI(PyObject* calling_module)
+{
+	PyObject* m;
+	PyObject* d;
+	PyObject* api_obj;
+	PyObject* name = PyString_FromString("objc");
+	
+	m = PyImport_Import(name);
+	Py_DECREF(name);
+	if (m == NULL) {
+		return -1;
+	}
+
+	d = PyModule_GetDict(m);
+	if (d == NULL) {
+		PyErr_SetString(PyExc_RuntimeError, 
+			"No dict in objc module");
+		return -1;
+	}
+
+	api_obj = PyDict_GetItemString(d, PYOBJC_API_NAME);
+	if (api_obj == NULL) {
+		PyErr_SetString(PyExc_RuntimeError, 
+			"No C_API in objc module");
+		return -1;
+	}
+	PyObjC_API = PyCObject_AsVoidPtr(api_obj);
+	if (PyObjC_API == NULL) {
+		return 0;
+	}
+	if (PyObjC_API->api_version != PYOBJC_API_VERSION) {
+		PyErr_SetString(PyExc_RuntimeError,
+			"Wrong version of PyObjC C API");
+		return -1;
+	}
+	
+	if (PyObjC_API->struct_len < sizeof(struct pyobjc_api)) {
+		PyErr_SetString(PyExc_RuntimeError,
+			"Wrong struct-size of PyObjC C API");
+		return -1;
+	}
+
+	Py_INCREF(api_obj);
+
+	/* Current pyobjc implementation doesn't allow deregistering 
+	 * information, avoid unloading of users of the C-API.
+	 * (Yes this is ugle, patches to fix this situation are apriciated)
+	 */
+	Py_INCREF(calling_module);
+
+	return 0;
+}
+#endif /* PYOBJC_METHOD_STUB_IMPL */
+
+#else /* PyObjC_BUILD */
+
+extern struct pyobjc_api	objc_api;
+
+#endif /* !PYOBJC_BUILD */
+
+#endif /*  PyObjC_API_H */
+"""
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.