Commits

Ronald Oussoren committed 753bd73

Sync pyobjc_setup.py: all framework wrappers once again have the same copy

Also:
- license= argument for distutils.core.setup() added
- include the version constraints in the platforms= argument
when known.

Comments (0)

Files changed (35)

pyobjc-framework-AddressBook/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initialize_options(self):
+        test.test.initialize_options(self)
+        self.verbosity='1'
 
-        # Ensure that any installed versions of this package aren't on sys.path
+    def finalize_options(self):
+        test.test.finalize_options(self)
+        if isinstance(self.verbosity, str):
+            self.verbosity = int(self.verbosity)
+
+
+    def cleanup_environment(self):
         ei_cmd = self.get_finalized_command('egg_info')
         egg_name = ei_cmd.egg_name.replace('-', '_')
 
-        to_remove = []
+        to_remove =  []
         for dirname in sys.path:
             bn = os.path.basename(dirname)
             if bn.startswith(egg_name + "-"):
                 to_remove.append(dirname)
 
         for dirname in to_remove:
-            log.info("removing installed %r from sys.path before testing"%(dirname,))
+            log.info("removing installed %r from sys.path before testing"%(
+                dirname,))
             sys.path.remove(dirname)
 
-        # Actually run the tests
-        if sys.version_info[0] == 2:
-            sys.path.insert(0, rootdir)
-    
-        import PyObjCTest
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
+    def add_project_to_sys_path(self):
+        from pkg_resources import normalize_path, add_activation_listener
+        from pkg_resources import working_set, require
+
+        if getattr(self.distribution, 'use_2to3', False):
+
+            # Using 2to3, cannot do this inplace:
+            self.reinitialize_command('build_py', inplace=0)
+            self.run_command('build_py')
+            bpy_cmd = self.get_finalized_command("build_py")
+            build_path = normalize_path(bpy_cmd.build_lib)
+
+            self.reinitialize_command('egg_info', egg_base=build_path)
+            self.run_command('egg_info')
+
+            self.reinitialize_command('build_ext', inplace=0)
+            self.run_command('build_ext')
+
+        else:
+            self.reinitialize_command('egg_info')
+            self.run_command('egg_info')
+            self.reinitialize_command('build_ext', inplace=1)
+            self.run_command('build_ext')
+        
+        self.__old_path = sys.path[:]
+        self.__old_modules = sys.modules.copy()
+
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
+
+        ei_cmd = self.get_finalized_command('egg_info')
+        sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+        sys.path.insert(1, os.path.dirname(__file__))
+            
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+        require('%s==%s'%(ei_cmd.egg_name, ei_cmd.egg_version))
+
+    def remove_from_sys_path(self):
+        from pkg_resources import working_set
+        sys.path[:] = self.__old_path
+        sys.modules.clear()
+        sys.modules.update(self.__old_modules)
+        working_set.__init__()
+
+
+    def run(self):
         import unittest
+
+        # Ensure that build directory is on sys.path (py3k)
+        import sys
+
+        self.cleanup_environment()
+        self.add_project_to_sys_path()
+
+        import PyObjCTools.TestSupport as modo
+
         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())
+        try:
+            meta = self.distribution.metadata
+            name = meta.get_name()
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
+            runner = unittest.TextTestRunner(verbosity=self.verbosity)
+            result = runner.run(suite)
+
+            # Print out summary. This is a structured format that
+            # should make it easy to use this information in scripts.
+            summary = dict(
+                count=result.testsRun,
+                fails=len(result.failures),
+                errors=len(result.errors),
+                xfails=len(getattr(result, 'expectedFailures', [])),
+                xpass=len(getattr(result, 'expectedSuccesses', [])),
+                skip=len(getattr(result, 'skipped', [])),
+            )
+            print("SUMMARY: %s"%(summary,))
+
+        finally:
+            self.remove_from_sys_path()
 
 
 from setuptools import setup as _setup, Extension as _Extension, Command
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-AppleScriptKit/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initialize_options(self):
+        test.test.initialize_options(self)
+        self.verbosity='1'
 
-        # Ensure that any installed versions of this package aren't on sys.path
+    def finalize_options(self):
+        test.test.finalize_options(self)
+        if isinstance(self.verbosity, str):
+            self.verbosity = int(self.verbosity)
+
+
+    def cleanup_environment(self):
         ei_cmd = self.get_finalized_command('egg_info')
         egg_name = ei_cmd.egg_name.replace('-', '_')
 
-        to_remove = []
+        to_remove =  []
         for dirname in sys.path:
             bn = os.path.basename(dirname)
             if bn.startswith(egg_name + "-"):
                 to_remove.append(dirname)
 
         for dirname in to_remove:
-            log.info("removing installed %r from sys.path before testing"%(dirname,))
+            log.info("removing installed %r from sys.path before testing"%(
+                dirname,))
             sys.path.remove(dirname)
 
-        # Actually run the tests
-        if sys.version_info[0] == 2:
-            sys.path.insert(0, rootdir)
-    
-        import PyObjCTest
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
+    def add_project_to_sys_path(self):
+        from pkg_resources import normalize_path, add_activation_listener
+        from pkg_resources import working_set, require
+
+        if getattr(self.distribution, 'use_2to3', False):
+
+            # Using 2to3, cannot do this inplace:
+            self.reinitialize_command('build_py', inplace=0)
+            self.run_command('build_py')
+            bpy_cmd = self.get_finalized_command("build_py")
+            build_path = normalize_path(bpy_cmd.build_lib)
+
+            self.reinitialize_command('egg_info', egg_base=build_path)
+            self.run_command('egg_info')
+
+            self.reinitialize_command('build_ext', inplace=0)
+            self.run_command('build_ext')
+
+        else:
+            self.reinitialize_command('egg_info')
+            self.run_command('egg_info')
+            self.reinitialize_command('build_ext', inplace=1)
+            self.run_command('build_ext')
+        
+        self.__old_path = sys.path[:]
+        self.__old_modules = sys.modules.copy()
+
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
+
+        ei_cmd = self.get_finalized_command('egg_info')
+        sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+        sys.path.insert(1, os.path.dirname(__file__))
+            
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+        require('%s==%s'%(ei_cmd.egg_name, ei_cmd.egg_version))
+
+    def remove_from_sys_path(self):
+        from pkg_resources import working_set
+        sys.path[:] = self.__old_path
+        sys.modules.clear()
+        sys.modules.update(self.__old_modules)
+        working_set.__init__()
+
+
+    def run(self):
         import unittest
+
+        # Ensure that build directory is on sys.path (py3k)
+        import sys
+
+        self.cleanup_environment()
+        self.add_project_to_sys_path()
+
+        import PyObjCTools.TestSupport as modo
+
         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())
+        try:
+            meta = self.distribution.metadata
+            name = meta.get_name()
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
+            runner = unittest.TextTestRunner(verbosity=self.verbosity)
+            result = runner.run(suite)
+
+            # Print out summary. This is a structured format that
+            # should make it easy to use this information in scripts.
+            summary = dict(
+                count=result.testsRun,
+                fails=len(result.failures),
+                errors=len(result.errors),
+                xfails=len(getattr(result, 'expectedFailures', [])),
+                xpass=len(getattr(result, 'expectedSuccesses', [])),
+                skip=len(getattr(result, 'skipped', [])),
+            )
+            print("SUMMARY: %s"%(summary,))
+
+        finally:
+            self.remove_from_sys_path()
 
 
 from setuptools import setup as _setup, Extension as _Extension, Command
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-AppleScriptObjC/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initialize_options(self):
+        test.test.initialize_options(self)
+        self.verbosity='1'
 
-        # Ensure that any installed versions of this package aren't on sys.path
+    def finalize_options(self):
+        test.test.finalize_options(self)
+        if isinstance(self.verbosity, str):
+            self.verbosity = int(self.verbosity)
+
+
+    def cleanup_environment(self):
         ei_cmd = self.get_finalized_command('egg_info')
         egg_name = ei_cmd.egg_name.replace('-', '_')
 
-        to_remove = []
+        to_remove =  []
         for dirname in sys.path:
             bn = os.path.basename(dirname)
             if bn.startswith(egg_name + "-"):
                 to_remove.append(dirname)
 
         for dirname in to_remove:
-            log.info("removing installed %r from sys.path before testing"%(dirname,))
+            log.info("removing installed %r from sys.path before testing"%(
+                dirname,))
             sys.path.remove(dirname)
 
-        # Actually run the tests
-        if sys.version_info[0] == 2:
-            sys.path.insert(0, rootdir)
-    
-        import PyObjCTest
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
+    def add_project_to_sys_path(self):
+        from pkg_resources import normalize_path, add_activation_listener
+        from pkg_resources import working_set, require
+
+        if getattr(self.distribution, 'use_2to3', False):
+
+            # Using 2to3, cannot do this inplace:
+            self.reinitialize_command('build_py', inplace=0)
+            self.run_command('build_py')
+            bpy_cmd = self.get_finalized_command("build_py")
+            build_path = normalize_path(bpy_cmd.build_lib)
+
+            self.reinitialize_command('egg_info', egg_base=build_path)
+            self.run_command('egg_info')
+
+            self.reinitialize_command('build_ext', inplace=0)
+            self.run_command('build_ext')
+
+        else:
+            self.reinitialize_command('egg_info')
+            self.run_command('egg_info')
+            self.reinitialize_command('build_ext', inplace=1)
+            self.run_command('build_ext')
+        
+        self.__old_path = sys.path[:]
+        self.__old_modules = sys.modules.copy()
+
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
+
+        ei_cmd = self.get_finalized_command('egg_info')
+        sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+        sys.path.insert(1, os.path.dirname(__file__))
+            
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+        require('%s==%s'%(ei_cmd.egg_name, ei_cmd.egg_version))
+
+    def remove_from_sys_path(self):
+        from pkg_resources import working_set
+        sys.path[:] = self.__old_path
+        sys.modules.clear()
+        sys.modules.update(self.__old_modules)
+        working_set.__init__()
+
+
+    def run(self):
         import unittest
+
+        # Ensure that build directory is on sys.path (py3k)
+        import sys
+
+        self.cleanup_environment()
+        self.add_project_to_sys_path()
+
+        import PyObjCTools.TestSupport as modo
+
         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())
+        try:
+            meta = self.distribution.metadata
+            name = meta.get_name()
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
+            runner = unittest.TextTestRunner(verbosity=self.verbosity)
+            result = runner.run(suite)
+
+            # Print out summary. This is a structured format that
+            # should make it easy to use this information in scripts.
+            summary = dict(
+                count=result.testsRun,
+                fails=len(result.failures),
+                errors=len(result.errors),
+                xfails=len(getattr(result, 'expectedFailures', [])),
+                xpass=len(getattr(result, 'expectedSuccesses', [])),
+                skip=len(getattr(result, 'skipped', [])),
+            )
+            print("SUMMARY: %s"%(summary,))
+
+        finally:
+            self.remove_from_sys_path()
 
 
 from setuptools import setup as _setup, Extension as _Extension, Command
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-Automator/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initialize_options(self):
+        test.test.initialize_options(self)
+        self.verbosity='1'
 
-        # Ensure that any installed versions of this package aren't on sys.path
+    def finalize_options(self):
+        test.test.finalize_options(self)
+        if isinstance(self.verbosity, str):
+            self.verbosity = int(self.verbosity)
+
+
+    def cleanup_environment(self):
         ei_cmd = self.get_finalized_command('egg_info')
         egg_name = ei_cmd.egg_name.replace('-', '_')
 
-        to_remove = []
+        to_remove =  []
         for dirname in sys.path:
             bn = os.path.basename(dirname)
             if bn.startswith(egg_name + "-"):
                 to_remove.append(dirname)
 
         for dirname in to_remove:
-            log.info("removing installed %r from sys.path before testing"%(dirname,))
+            log.info("removing installed %r from sys.path before testing"%(
+                dirname,))
             sys.path.remove(dirname)
 
-        # Actually run the tests
-        if sys.version_info[0] == 2:
-            sys.path.insert(0, rootdir)
-    
-        import PyObjCTest
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
+    def add_project_to_sys_path(self):
+        from pkg_resources import normalize_path, add_activation_listener
+        from pkg_resources import working_set, require
+
+        if getattr(self.distribution, 'use_2to3', False):
+
+            # Using 2to3, cannot do this inplace:
+            self.reinitialize_command('build_py', inplace=0)
+            self.run_command('build_py')
+            bpy_cmd = self.get_finalized_command("build_py")
+            build_path = normalize_path(bpy_cmd.build_lib)
+
+            self.reinitialize_command('egg_info', egg_base=build_path)
+            self.run_command('egg_info')
+
+            self.reinitialize_command('build_ext', inplace=0)
+            self.run_command('build_ext')
+
+        else:
+            self.reinitialize_command('egg_info')
+            self.run_command('egg_info')
+            self.reinitialize_command('build_ext', inplace=1)
+            self.run_command('build_ext')
+        
+        self.__old_path = sys.path[:]
+        self.__old_modules = sys.modules.copy()
+
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
+
+        ei_cmd = self.get_finalized_command('egg_info')
+        sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+        sys.path.insert(1, os.path.dirname(__file__))
+            
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+        require('%s==%s'%(ei_cmd.egg_name, ei_cmd.egg_version))
+
+    def remove_from_sys_path(self):
+        from pkg_resources import working_set
+        sys.path[:] = self.__old_path
+        sys.modules.clear()
+        sys.modules.update(self.__old_modules)
+        working_set.__init__()
+
+
+    def run(self):
         import unittest
+
+        # Ensure that build directory is on sys.path (py3k)
+        import sys
+
+        self.cleanup_environment()
+        self.add_project_to_sys_path()
+
+        import PyObjCTools.TestSupport as modo
+
         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())
+        try:
+            meta = self.distribution.metadata
+            name = meta.get_name()
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
+            runner = unittest.TextTestRunner(verbosity=self.verbosity)
+            result = runner.run(suite)
+
+            # Print out summary. This is a structured format that
+            # should make it easy to use this information in scripts.
+            summary = dict(
+                count=result.testsRun,
+                fails=len(result.failures),
+                errors=len(result.errors),
+                xfails=len(getattr(result, 'expectedFailures', [])),
+                xpass=len(getattr(result, 'expectedSuccesses', [])),
+                skip=len(getattr(result, 'skipped', [])),
+            )
+            print("SUMMARY: %s"%(summary,))
+
+        finally:
+            self.remove_from_sys_path()
 
 
 from setuptools import setup as _setup, Extension as _Extension, Command
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-CFNetwork/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initialize_options(self):
+        test.test.initialize_options(self)
+        self.verbosity='1'
 
-        # Ensure that any installed versions of this package aren't on sys.path
+    def finalize_options(self):
+        test.test.finalize_options(self)
+        if isinstance(self.verbosity, str):
+            self.verbosity = int(self.verbosity)
+
+
+    def cleanup_environment(self):
         ei_cmd = self.get_finalized_command('egg_info')
         egg_name = ei_cmd.egg_name.replace('-', '_')
 
-        to_remove = []
+        to_remove =  []
         for dirname in sys.path:
             bn = os.path.basename(dirname)
             if bn.startswith(egg_name + "-"):
                 to_remove.append(dirname)
 
         for dirname in to_remove:
-            log.info("removing installed %r from sys.path before testing"%(dirname,))
+            log.info("removing installed %r from sys.path before testing"%(
+                dirname,))
             sys.path.remove(dirname)
 
-        # Actually run the tests
-        if sys.version_info[0] == 2:
-            sys.path.insert(0, rootdir)
-    
-        import PyObjCTest
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
+    def add_project_to_sys_path(self):
+        from pkg_resources import normalize_path, add_activation_listener
+        from pkg_resources import working_set, require
+
+        if getattr(self.distribution, 'use_2to3', False):
+
+            # Using 2to3, cannot do this inplace:
+            self.reinitialize_command('build_py', inplace=0)
+            self.run_command('build_py')
+            bpy_cmd = self.get_finalized_command("build_py")
+            build_path = normalize_path(bpy_cmd.build_lib)
+
+            self.reinitialize_command('egg_info', egg_base=build_path)
+            self.run_command('egg_info')
+
+            self.reinitialize_command('build_ext', inplace=0)
+            self.run_command('build_ext')
+
+        else:
+            self.reinitialize_command('egg_info')
+            self.run_command('egg_info')
+            self.reinitialize_command('build_ext', inplace=1)
+            self.run_command('build_ext')
+        
+        self.__old_path = sys.path[:]
+        self.__old_modules = sys.modules.copy()
+
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
+
+        ei_cmd = self.get_finalized_command('egg_info')
+        sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+        sys.path.insert(1, os.path.dirname(__file__))
+            
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+        require('%s==%s'%(ei_cmd.egg_name, ei_cmd.egg_version))
+
+    def remove_from_sys_path(self):
+        from pkg_resources import working_set
+        sys.path[:] = self.__old_path
+        sys.modules.clear()
+        sys.modules.update(self.__old_modules)
+        working_set.__init__()
+
+
+    def run(self):
         import unittest
+
+        # Ensure that build directory is on sys.path (py3k)
+        import sys
+
+        self.cleanup_environment()
+        self.add_project_to_sys_path()
+
+        import PyObjCTools.TestSupport as modo
+
         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())
+        try:
+            meta = self.distribution.metadata
+            name = meta.get_name()
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
+            runner = unittest.TextTestRunner(verbosity=self.verbosity)
+            result = runner.run(suite)
+
+            # Print out summary. This is a structured format that
+            # should make it easy to use this information in scripts.
+            summary = dict(
+                count=result.testsRun,
+                fails=len(result.failures),
+                errors=len(result.errors),
+                xfails=len(getattr(result, 'expectedFailures', [])),
+                xpass=len(getattr(result, 'expectedSuccesses', [])),
+                skip=len(getattr(result, 'skipped', [])),
+            )
+            print("SUMMARY: %s"%(summary,))
+
+        finally:
+            self.remove_from_sys_path()
 
 
 from setuptools import setup as _setup, Extension as _Extension, Command
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-CalendarStore/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initialize_options(self):
+        test.test.initialize_options(self)
+        self.verbosity='1'
 
-        # Ensure that any installed versions of this package aren't on sys.path
+    def finalize_options(self):
+        test.test.finalize_options(self)
+        if isinstance(self.verbosity, str):
+            self.verbosity = int(self.verbosity)
+
+
+    def cleanup_environment(self):
         ei_cmd = self.get_finalized_command('egg_info')
         egg_name = ei_cmd.egg_name.replace('-', '_')
 
-        to_remove = []
+        to_remove =  []
         for dirname in sys.path:
             bn = os.path.basename(dirname)
             if bn.startswith(egg_name + "-"):
                 to_remove.append(dirname)
 
         for dirname in to_remove:
-            log.info("removing installed %r from sys.path before testing"%(dirname,))
+            log.info("removing installed %r from sys.path before testing"%(
+                dirname,))
             sys.path.remove(dirname)
 
-        # Actually run the tests
-        if sys.version_info[0] == 2:
-            sys.path.insert(0, rootdir)
-    
-        import PyObjCTest
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
+    def add_project_to_sys_path(self):
+        from pkg_resources import normalize_path, add_activation_listener
+        from pkg_resources import working_set, require
+
+        if getattr(self.distribution, 'use_2to3', False):
+
+            # Using 2to3, cannot do this inplace:
+            self.reinitialize_command('build_py', inplace=0)
+            self.run_command('build_py')
+            bpy_cmd = self.get_finalized_command("build_py")
+            build_path = normalize_path(bpy_cmd.build_lib)
+
+            self.reinitialize_command('egg_info', egg_base=build_path)
+            self.run_command('egg_info')
+
+            self.reinitialize_command('build_ext', inplace=0)
+            self.run_command('build_ext')
+
+        else:
+            self.reinitialize_command('egg_info')
+            self.run_command('egg_info')
+            self.reinitialize_command('build_ext', inplace=1)
+            self.run_command('build_ext')
+        
+        self.__old_path = sys.path[:]
+        self.__old_modules = sys.modules.copy()
+
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
+
+        ei_cmd = self.get_finalized_command('egg_info')
+        sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+        sys.path.insert(1, os.path.dirname(__file__))
+            
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+        require('%s==%s'%(ei_cmd.egg_name, ei_cmd.egg_version))
+
+    def remove_from_sys_path(self):
+        from pkg_resources import working_set
+        sys.path[:] = self.__old_path
+        sys.modules.clear()
+        sys.modules.update(self.__old_modules)
+        working_set.__init__()
+
+
+    def run(self):
         import unittest
+
+        # Ensure that build directory is on sys.path (py3k)
+        import sys
+
+        self.cleanup_environment()
+        self.add_project_to_sys_path()
+
+        import PyObjCTools.TestSupport as modo
+
         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())
+        try:
+            meta = self.distribution.metadata
+            name = meta.get_name()
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
+            runner = unittest.TextTestRunner(verbosity=self.verbosity)
+            result = runner.run(suite)
+
+            # Print out summary. This is a structured format that
+            # should make it easy to use this information in scripts.
+            summary = dict(
+                count=result.testsRun,
+                fails=len(result.failures),
+                errors=len(result.errors),
+                xfails=len(getattr(result, 'expectedFailures', [])),
+                xpass=len(getattr(result, 'expectedSuccesses', [])),
+                skip=len(getattr(result, 'skipped', [])),
+            )
+            print("SUMMARY: %s"%(summary,))
+
+        finally:
+            self.remove_from_sys_path()
 
 
 from setuptools import setup as _setup, Extension as _Extension, Command
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-Cocoa/pyobjc_setup.py

 __all__ = ('setup', 'Extension', 'Command')
 
 import sys
+from pkg_resources import Distribution
 
 try:
     import setuptools
     import distribute_setup
     distribute_setup.use_setuptools()
 
-from pkg_resources import Distribution
-
 from setuptools.command import test
 from setuptools.command import build_py
-from distutils.core import Command
 
 from distutils import log
 
-from fnmatch import fnmatch
-
-
 extra_args=dict(
     use_2to3 = True,
 )
             self.packages = p
 
 
-def recursiveGlob(root, pathPattern):
-    """
-    Recursively look for files matching 'pathPattern'. Return a list
-    of matching files/directories.
-    """
-    result = []
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
-    for rootpath, dirnames, filenames in os.walk(root):
-        for fn in filenames:
-            if fnmatch(fn, pathPattern):
-                result.append(os.path.join(rootpath, fn))
-    return result
-        
-
-def importExternalTestCases(unittest, 
-        pathPattern="test_*.py", root=".", package=None):
-    """
-    Import all unittests in the PyObjC tree starting at 'root'
-    """
-
-    testFiles = recursiveGlob(root, pathPattern)
-    testModules = map(lambda x:x[len(root)+1:-3].replace('/', '.'), testFiles)
-    if package is not None:
-        testModules = [(package + '.' + m) for m in testModules]
-
-    suites = []
-   
-    for modName in testModules:
-        try:
-            module = __import__(modName)
-        except ImportError:
-            print("SKIP %s: %s"%(modName, sys.exc_info()[1]))
-            continue
-
-        if '.' in modName:
-            for elem in modName.split('.')[1:]:
-                module = getattr(module, elem)
-
-        s = unittest.defaultTestLoader.loadTestsFromModule(module)
-        suites.append(s)
-
-    return unittest.TestSuite(suites)
-
-
-
-
-class oc_test (Command):
+class oc_test (test.test):
     description = "run test suite"
     user_options = [
         ('verbosity=', None, "print what tests are run"),
     ]
 
     def initialize_options(self):
+        test.test.initialize_options(self)
         self.verbosity='1'
 
     def finalize_options(self):
+        test.test.finalize_options(self)
         if isinstance(self.verbosity, str):
             self.verbosity = int(self.verbosity)
 
                 dirname,))
             sys.path.remove(dirname)
 
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
     def add_project_to_sys_path(self):
         from pkg_resources import normalize_path, add_activation_listener
         from pkg_resources import working_set, require
         self.__old_path = sys.path[:]
         self.__old_modules = sys.modules.copy()
 
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
 
         ei_cmd = self.get_finalized_command('egg_info')
         sys.path.insert(0, normalize_path(ei_cmd.egg_base))
         import unittest
 
         # Ensure that build directory is on sys.path (py3k)
+        import sys
 
         self.cleanup_environment()
         self.add_project_to_sys_path()
 
+        import PyObjCTools.TestSupport as modo
+
+        from pkg_resources import EntryPoint
+        loader_ep = EntryPoint.parse("x="+self.test_loader)
+        loader_class = loader_ep.load(require=False)
+
         try:
             meta = self.distribution.metadata
             name = meta.get_name()
-            test_pkg = 'PyObjCTest'
-            suite = importExternalTestCases(unittest, 
-                    "test_*.py", test_pkg, test_pkg)
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
             runner = unittest.TextTestRunner(verbosity=self.verbosity)
             result = runner.run(suite)
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-Collaboration/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initialize_options(self):
+        test.test.initialize_options(self)
+        self.verbosity='1'
 
-        # Ensure that any installed versions of this package aren't on sys.path
+    def finalize_options(self):
+        test.test.finalize_options(self)
+        if isinstance(self.verbosity, str):
+            self.verbosity = int(self.verbosity)
+
+
+    def cleanup_environment(self):
         ei_cmd = self.get_finalized_command('egg_info')
         egg_name = ei_cmd.egg_name.replace('-', '_')
 
-        to_remove = []
+        to_remove =  []
         for dirname in sys.path:
             bn = os.path.basename(dirname)
             if bn.startswith(egg_name + "-"):
                 to_remove.append(dirname)
 
         for dirname in to_remove:
-            log.info("removing installed %r from sys.path before testing"%(dirname,))
+            log.info("removing installed %r from sys.path before testing"%(
+                dirname,))
             sys.path.remove(dirname)
 
-        # Actually run the tests
-        if sys.version_info[0] == 2:
-            sys.path.insert(0, rootdir)
-    
-        import PyObjCTest
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
+    def add_project_to_sys_path(self):
+        from pkg_resources import normalize_path, add_activation_listener
+        from pkg_resources import working_set, require
+
+        if getattr(self.distribution, 'use_2to3', False):
+
+            # Using 2to3, cannot do this inplace:
+            self.reinitialize_command('build_py', inplace=0)
+            self.run_command('build_py')
+            bpy_cmd = self.get_finalized_command("build_py")
+            build_path = normalize_path(bpy_cmd.build_lib)
+
+            self.reinitialize_command('egg_info', egg_base=build_path)
+            self.run_command('egg_info')
+
+            self.reinitialize_command('build_ext', inplace=0)
+            self.run_command('build_ext')
+
+        else:
+            self.reinitialize_command('egg_info')
+            self.run_command('egg_info')
+            self.reinitialize_command('build_ext', inplace=1)
+            self.run_command('build_ext')
+        
+        self.__old_path = sys.path[:]
+        self.__old_modules = sys.modules.copy()
+
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
+
+        ei_cmd = self.get_finalized_command('egg_info')
+        sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+        sys.path.insert(1, os.path.dirname(__file__))
+            
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+        require('%s==%s'%(ei_cmd.egg_name, ei_cmd.egg_version))
+
+    def remove_from_sys_path(self):
+        from pkg_resources import working_set
+        sys.path[:] = self.__old_path
+        sys.modules.clear()
+        sys.modules.update(self.__old_modules)
+        working_set.__init__()
+
+
+    def run(self):
         import unittest
+
+        # Ensure that build directory is on sys.path (py3k)
+        import sys
+
+        self.cleanup_environment()
+        self.add_project_to_sys_path()
+
+        import PyObjCTools.TestSupport as modo
+
         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())
+        try:
+            meta = self.distribution.metadata
+            name = meta.get_name()
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
+            runner = unittest.TextTestRunner(verbosity=self.verbosity)
+            result = runner.run(suite)
+
+            # Print out summary. This is a structured format that
+            # should make it easy to use this information in scripts.
+            summary = dict(
+                count=result.testsRun,
+                fails=len(result.failures),
+                errors=len(result.errors),
+                xfails=len(getattr(result, 'expectedFailures', [])),
+                xpass=len(getattr(result, 'expectedSuccesses', [])),
+                skip=len(getattr(result, 'skipped', [])),
+            )
+            print("SUMMARY: %s"%(summary,))
+
+        finally:
+            self.remove_from_sys_path()
 
 
 from setuptools import setup as _setup, Extension as _Extension, Command
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-CoreData/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initialize_options(self):
+        test.test.initialize_options(self)
+        self.verbosity='1'
 
-        # Ensure that any installed versions of this package aren't on sys.path
+    def finalize_options(self):
+        test.test.finalize_options(self)
+        if isinstance(self.verbosity, str):
+            self.verbosity = int(self.verbosity)
+
+
+    def cleanup_environment(self):
         ei_cmd = self.get_finalized_command('egg_info')
         egg_name = ei_cmd.egg_name.replace('-', '_')
 
-        to_remove = []
+        to_remove =  []
         for dirname in sys.path:
             bn = os.path.basename(dirname)
             if bn.startswith(egg_name + "-"):
                 to_remove.append(dirname)
 
         for dirname in to_remove:
-            log.info("removing installed %r from sys.path before testing"%(dirname,))
+            log.info("removing installed %r from sys.path before testing"%(
+                dirname,))
             sys.path.remove(dirname)
 
-        # Actually run the tests
-        if sys.version_info[0] == 2:
-            sys.path.insert(0, rootdir)
-    
-        import PyObjCTest
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
+    def add_project_to_sys_path(self):
+        from pkg_resources import normalize_path, add_activation_listener
+        from pkg_resources import working_set, require
+
+        if getattr(self.distribution, 'use_2to3', False):
+
+            # Using 2to3, cannot do this inplace:
+            self.reinitialize_command('build_py', inplace=0)
+            self.run_command('build_py')
+            bpy_cmd = self.get_finalized_command("build_py")
+            build_path = normalize_path(bpy_cmd.build_lib)
+
+            self.reinitialize_command('egg_info', egg_base=build_path)
+            self.run_command('egg_info')
+
+            self.reinitialize_command('build_ext', inplace=0)
+            self.run_command('build_ext')
+
+        else:
+            self.reinitialize_command('egg_info')
+            self.run_command('egg_info')
+            self.reinitialize_command('build_ext', inplace=1)
+            self.run_command('build_ext')
+        
+        self.__old_path = sys.path[:]
+        self.__old_modules = sys.modules.copy()
+
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
+
+        ei_cmd = self.get_finalized_command('egg_info')
+        sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+        sys.path.insert(1, os.path.dirname(__file__))
+            
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+        require('%s==%s'%(ei_cmd.egg_name, ei_cmd.egg_version))
+
+    def remove_from_sys_path(self):
+        from pkg_resources import working_set
+        sys.path[:] = self.__old_path
+        sys.modules.clear()
+        sys.modules.update(self.__old_modules)
+        working_set.__init__()
+
+
+    def run(self):
         import unittest
+
+        # Ensure that build directory is on sys.path (py3k)
+        import sys
+
+        self.cleanup_environment()
+        self.add_project_to_sys_path()
+
+        import PyObjCTools.TestSupport as modo
+
         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())
+        try:
+            meta = self.distribution.metadata
+            name = meta.get_name()
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
+            runner = unittest.TextTestRunner(verbosity=self.verbosity)
+            result = runner.run(suite)
+
+            # Print out summary. This is a structured format that
+            # should make it easy to use this information in scripts.
+            summary = dict(
+                count=result.testsRun,
+                fails=len(result.failures),
+                errors=len(result.errors),
+                xfails=len(getattr(result, 'expectedFailures', [])),
+                xpass=len(getattr(result, 'expectedSuccesses', [])),
+                skip=len(getattr(result, 'skipped', [])),
+            )
+            print("SUMMARY: %s"%(summary,))
+
+        finally:
+            self.remove_from_sys_path()
 
 
 from setuptools import setup as _setup, Extension as _Extension, Command
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-CoreLocation/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initialize_options(self):
+        test.test.initialize_options(self)
+        self.verbosity='1'
 
-        # Ensure that any installed versions of this package aren't on sys.path
+    def finalize_options(self):
+        test.test.finalize_options(self)
+        if isinstance(self.verbosity, str):
+            self.verbosity = int(self.verbosity)
+
+
+    def cleanup_environment(self):
         ei_cmd = self.get_finalized_command('egg_info')
         egg_name = ei_cmd.egg_name.replace('-', '_')
 
-        to_remove = []
+        to_remove =  []
         for dirname in sys.path:
             bn = os.path.basename(dirname)
             if bn.startswith(egg_name + "-"):
                 to_remove.append(dirname)
 
         for dirname in to_remove:
-            log.info("removing installed %r from sys.path before testing"%(dirname,))
+            log.info("removing installed %r from sys.path before testing"%(
+                dirname,))
             sys.path.remove(dirname)
 
-        # Actually run the tests
-        if sys.version_info[0] == 2:
-            sys.path.insert(0, rootdir)
-    
-        import PyObjCTest
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
+    def add_project_to_sys_path(self):
+        from pkg_resources import normalize_path, add_activation_listener
+        from pkg_resources import working_set, require
+
+        if getattr(self.distribution, 'use_2to3', False):
+
+            # Using 2to3, cannot do this inplace:
+            self.reinitialize_command('build_py', inplace=0)
+            self.run_command('build_py')
+            bpy_cmd = self.get_finalized_command("build_py")
+            build_path = normalize_path(bpy_cmd.build_lib)
+
+            self.reinitialize_command('egg_info', egg_base=build_path)
+            self.run_command('egg_info')
+
+            self.reinitialize_command('build_ext', inplace=0)
+            self.run_command('build_ext')
+
+        else:
+            self.reinitialize_command('egg_info')
+            self.run_command('egg_info')
+            self.reinitialize_command('build_ext', inplace=1)
+            self.run_command('build_ext')
+        
+        self.__old_path = sys.path[:]
+        self.__old_modules = sys.modules.copy()
+
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
+
+        ei_cmd = self.get_finalized_command('egg_info')
+        sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+        sys.path.insert(1, os.path.dirname(__file__))
+            
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+        require('%s==%s'%(ei_cmd.egg_name, ei_cmd.egg_version))
+
+    def remove_from_sys_path(self):
+        from pkg_resources import working_set
+        sys.path[:] = self.__old_path
+        sys.modules.clear()
+        sys.modules.update(self.__old_modules)
+        working_set.__init__()
+
+
+    def run(self):
         import unittest
+
+        # Ensure that build directory is on sys.path (py3k)
+        import sys
+
+        self.cleanup_environment()
+        self.add_project_to_sys_path()
+
+        import PyObjCTools.TestSupport as modo
+
         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())
+        try:
+            meta = self.distribution.metadata
+            name = meta.get_name()
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
+            runner = unittest.TextTestRunner(verbosity=self.verbosity)
+            result = runner.run(suite)
+
+            # Print out summary. This is a structured format that
+            # should make it easy to use this information in scripts.
+            summary = dict(
+                count=result.testsRun,
+                fails=len(result.failures),
+                errors=len(result.errors),
+                xfails=len(getattr(result, 'expectedFailures', [])),
+                xpass=len(getattr(result, 'expectedSuccesses', [])),
+                skip=len(getattr(result, 'skipped', [])),
+            )
+            print("SUMMARY: %s"%(summary,))
+
+        finally:
+            self.remove_from_sys_path()
 
 
 from setuptools import setup as _setup, Extension as _Extension, Command
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-CoreText/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initialize_options(self):
+        test.test.initialize_options(self)
+        self.verbosity='1'
 
-        # Ensure that any installed versions of this package aren't on sys.path
+    def finalize_options(self):
+        test.test.finalize_options(self)
+        if isinstance(self.verbosity, str):
+            self.verbosity = int(self.verbosity)
+
+
+    def cleanup_environment(self):
         ei_cmd = self.get_finalized_command('egg_info')
         egg_name = ei_cmd.egg_name.replace('-', '_')
 
-        to_remove = []
+        to_remove =  []
         for dirname in sys.path:
             bn = os.path.basename(dirname)
             if bn.startswith(egg_name + "-"):
                 to_remove.append(dirname)
 
         for dirname in to_remove:
-            log.info("removing installed %r from sys.path before testing"%(dirname,))
+            log.info("removing installed %r from sys.path before testing"%(
+                dirname,))
             sys.path.remove(dirname)
 
-        # Actually run the tests
-        if sys.version_info[0] == 2:
-            sys.path.insert(0, rootdir)
-    
-        import PyObjCTest
+        from pkg_resources import add_activation_listener
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+
+    def add_project_to_sys_path(self):
+        from pkg_resources import normalize_path, add_activation_listener
+        from pkg_resources import working_set, require
+
+        if getattr(self.distribution, 'use_2to3', False):
+
+            # Using 2to3, cannot do this inplace:
+            self.reinitialize_command('build_py', inplace=0)
+            self.run_command('build_py')
+            bpy_cmd = self.get_finalized_command("build_py")
+            build_path = normalize_path(bpy_cmd.build_lib)
+
+            self.reinitialize_command('egg_info', egg_base=build_path)
+            self.run_command('egg_info')
+
+            self.reinitialize_command('build_ext', inplace=0)
+            self.run_command('build_ext')
+
+        else:
+            self.reinitialize_command('egg_info')
+            self.run_command('egg_info')
+            self.reinitialize_command('build_ext', inplace=1)
+            self.run_command('build_ext')
+        
+        self.__old_path = sys.path[:]
+        self.__old_modules = sys.modules.copy()
+
+        if 'PyObjCTools' in sys.modules:
+            del sys.modules['PyObjCTools']
+
+
+        ei_cmd = self.get_finalized_command('egg_info')
+        sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+        sys.path.insert(1, os.path.dirname(__file__))
+            
+        add_activation_listener(lambda dist: dist.activate())
+        working_set.__init__()
+        require('%s==%s'%(ei_cmd.egg_name, ei_cmd.egg_version))
+
+    def remove_from_sys_path(self):
+        from pkg_resources import working_set
+        sys.path[:] = self.__old_path
+        sys.modules.clear()
+        sys.modules.update(self.__old_modules)
+        working_set.__init__()
+
+
+    def run(self):
         import unittest
+
+        # Ensure that build directory is on sys.path (py3k)
+        import sys
+
+        self.cleanup_environment()
+        self.add_project_to_sys_path()
+
+        import PyObjCTools.TestSupport as modo
+
         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())
+        try:
+            meta = self.distribution.metadata
+            name = meta.get_name()
+            test_pkg = name + "_tests"
+            suite = loader_class().loadTestsFromName(self.distribution.test_suite)
 
+            runner = unittest.TextTestRunner(verbosity=self.verbosity)
+            result = runner.run(suite)
+
+            # Print out summary. This is a structured format that
+            # should make it easy to use this information in scripts.
+            summary = dict(
+                count=result.testsRun,
+                fails=len(result.failures),
+                errors=len(result.errors),
+                xfails=len(getattr(result, 'expectedFailures', [])),
+                xpass=len(getattr(result, 'expectedSuccesses', [])),
+                skip=len(getattr(result, 'skipped', [])),
+            )
+            print("SUMMARY: %s"%(summary,))
+
+        finally:
+            self.remove_from_sys_path()
 
 
 from setuptools import setup as _setup, Extension as _Extension, Command
         cmdclass['test'] = oc_test
         cmdclass['build_py'] = oc_build_py
 
-
+    plat_name = "MacOS X"
+    plat_versions = []
+    if min_os_level is not None:
+        plat_versions.append(">=%s"%(min_os_level,))
+    if max_os_level is not None:
+        plat_versions.append("<=%s"%(min_os_level,))
+    if plat_versions:
+        plat_name += " (%s)"%(", ".join(plat_versions),)
 
     _setup(
         cmdclass=cmdclass, 
         author='Ronald Oussoren',
         author_email='pyobjc-dev@lists.sourceforge.net',
         url='http://pyobjc.sourceforge.net',
-        platforms = [ "MacOS X" ],
+        platforms = [ plat_name ],
         package_dir = { '': 'Lib', 'PyObjCTest': 'PyObjCTest' },
         dependency_links = [],
         package_data = { '': ['*.bridgesupport'] },
         test_suite='PyObjCTest',
         zip_safe = False,
+        license = 'MIT License',
         **k
     ) 
 

pyobjc-framework-DictionaryServices/pyobjc_setup.py

             self.packages = p
 
 
+from pkg_resources import working_set, normalize_path, add_activation_listener, require
 
 class oc_test (test.test):
-    def run_tests(self):
-        import sys, os
+    description = "run test suite"
+    user_options = [
+        ('verbosity=', None, "print what tests are run"),
+    ]
 
-        rootdir =  os.path.dirname(os.path.abspath(__file__))
-        if rootdir in sys.path:
-            sys.path.remove(rootdir)
+    def initia