Esempio n. 1
0
    def run(self):
        # Remove .pyc, .lreg and .sibling files
        if hasattr(os, 'walk'):
            for _, _, files in os.walk('.'):
                for f in files:
                    if f.endswith('.pyc') or \
                            f.endswith('.lreg') or f.endswith('.sibling'):
                        try:
                            os.unlink(f)
                        except OSError:
                            pass

        # Remove generated directories
        build = self.get_finalized_command('build')
        build_dir = build.build_base
        if os.path.exists(build_dir):
            try:
                shutil.rmtree(build_dir, ignore_errors=True)
            except OSError:
                pass
        if self.distribution.subpackages != None:
            subs = []
            for (pkg_name, pkg_dir) in self.distribution.subpackages:
                rf = RequirementsFinder(os.path.join(pkg_dir, 'setup.py'))
                if rf.is_sysdevel_build:
                    subs.append((pkg_name, pkg_dir))
            idx = 0
            for i in range(len(sys.argv)):
                idx = i
                if 'setup.py' in sys.argv[idx]:
                    break
            argv = list(sys.argv[idx+1:])
            process_subpackages(build.distribution.parallel_build, 'clean',
                                build.build_base, subs, argv, False)

        # Remove user-specified generated files
        if self.distribution.generated_files != None:
            for path in self.distribution.generated_files:
                if os.path.isfile(path) or os.path.islink(path):
                    try:
                        os.unlink(path)
                    except OSError:
                        pass
                elif os.path.isdir(path):
                    try:
                        shutil.rmtree(path, ignore_errors=True)
                    except OSError:
                        pass

        # Remove sysdevel
        if os.path.exists('pysysdevel'):
            try:
                ## ignores symlinked directory
                shutil.rmtree('pysysdevel', ignore_errors=True)
            except OSError:
                pass

        old_clean.run(self)
        delete_cache()
Esempio n. 2
0
    def run(self):
        deps = self.get_finalized_command('dependencies')
        build = self.get_finalized_command('build')
        level_list = [deps.sublevel, build.sublevel, self.sublevel]
        ## detect malformed usage
        if len(set([l for l in level_list if l])) > 1:
            raise Exception("Multiple sublevels specified.")
        self.sublevel = build.sublevel = deps.sublevel = max(*level_list)

        ## before anything else (runs in case build hasn't run)
        if self.sublevel == 0 and not deps.ran:
            self.run_command('dependencies')

        options.set_top_level(self.sublevel)
        if self.distribution.subpackages != None:
            try:
                os.makedirs(build.build_base)
            except OSError:
                pass
            idx = 0
            for i in range(len(sys.argv)):
                idx = i
                if 'setup.py' in sys.argv[idx]:
                    break
            argv = list(sys.argv[idx+1:])
            for arg in sys.argv:
                if arg == 'build' or \
                   arg == 'clean' or \
                   '--sublevel' in arg:
                    argv.remove(arg)

            argv += ['--sublevel=' + str(self.sublevel + 1)]
            process_subpackages(build.distribution.parallel_build, 'install',
                                build.build_base, self.distribution.subpackages,
                                argv, build.distribution.quit_on_error)

            if build.has_pure_modules() or build.has_c_libraries() or \
                    build.has_ext_modules() or build.has_shared_libraries() or \
                    build.has_pypp_extensions() or \
                    build.has_web_extensions() or \
                    build.has_documents() or build.has_executables() or \
                    build.has_scripts() or build.has_data():
                old_install.run(self)
        else:
            old_install.run(self)
        self.ran = True
Esempio n. 3
0
    def run(self):
        deps = self.get_finalized_command('dependencies')
        install = self.get_finalized_command('install')
        level_list = [deps.sublevel, self.sublevel, install.sublevel]
        ## detect malformed usage
        if len(set([l for l in level_list if l])) > 1:
            raise Exception("Multiple sublevels specified.")
        level = max(self.sublevel, install.sublevel, deps.sublevel)
        self.sublevel = install.sublevel = deps.sublevel = max(*level_list)

        ## before anything else
        if self.sublevel == 0 and not deps.ran:
            self.run_command('dependencies')

        options.set_top_level(self.sublevel)
        if self.distribution.subpackages != None:
            install = self.get_finalized_command('install')
            if install.ran:
                return  ## avoid build after install
            for cmd in install.get_sub_commands():
                if getattr(cmd, 'ran', False):
                    return
                ## TODO avoid build after any install_* cmd
            try:
                os.makedirs(self.build_base)
            except OSError:
                pass
            idx = 0
            for i in range(len(sys.argv)):
                idx = i
                if 'setup.py' in sys.argv[idx]:
                    break
            argv = list(sys.argv[idx+1:])
            for arg in sys.argv:
                if arg == 'clean' or '--sublevel' in arg:
                    argv.remove(arg)

            argv += ['--sublevel=' + str(self.sublevel + 1)]
            process_subpackages(self.distribution.parallel_build, 'build',
                                self.build_base, self.distribution.subpackages,
                                argv, self.distribution.quit_on_error)

        old_build.run(self)
        self.ran = True
Esempio n. 4
0
    def run(self):
        failed = False
        build = self.get_finalized_command('build')
        if self.sublevel == 0 and not build.ran:
            self.run_command('build')

        if self.distribution.subpackages != None:
            subs = []
            for (pkg_name, pkg_dir) in self.distribution.subpackages:
                rf = RequirementsFinder(os.path.join(pkg_dir, 'setup.py'))
                if rf.is_sysdevel_build:
                    subs.append((pkg_name, pkg_dir))
            idx = 0
            for i in range(len(sys.argv)):
                idx = i
                if 'setup.py' in sys.argv[idx]:
                    break
            argv = list(sys.argv[idx+1:])
            for arg in sys.argv:
                if arg == 'clean' or '--sublevel' in arg:
                    argv.remove(arg)

            argv += ['--sublevel=' + str(self.sublevel + 1)]
            failed = process_subpackages(build.distribution.parallel_build,
                                         'test',
                                         os.path.abspath(build.build_base),
                                         subs, argv, False)

        ## PYTHON
        if self._has_python_tests():
            self.run_command('build')
            build = self.get_finalized_command('build')
            build_dir = os.path.abspath(build.build_base)
            environ = self.distribution.environment

            pkg_dirs = [build_dir, os.path.abspath(build.build_lib),
                        os.path.join(build_dir, 'python')]
            lib_dirs = [os.path.abspath(build.build_temp)]
            try:
                lib_dirs += environ['PATH']  ## need dlls for windows
            except KeyError:
                pass
            try:
                lib_dirs.append(os.path.join(environ['MINGW_DIR'], 'bin'))
                lib_dirs.append(os.path.join(environ['MSYS_DIR'], 'bin'))
                lib_dirs.append(os.path.join(environ['MSYS_DIR'], 'lib'))
            except KeyError:
                pass
            #postfix = '.'.join(build.build_temp.split('.')[1:])        

            for pkg, units in self._get_python_tests():
                test_dir = os.path.join(build_dir, 'test_' + pkg)
                if not os.path.exists(test_dir):
                    copy_tree('test', test_dir, excludes=['.svn*', 'CVS*'])
                f = open(os.path.join(test_dir, '__init__.py'), 'w')
                f.write("__all__ = ['" +
                        "', '".join(units) + "']\n")
                f.close()
                outfile = os.path.join(build_dir, 'test_' + pkg + '.py')
                create_testscript('test_' + pkg, units, outfile, pkg_dirs)
                wrap = create_test_wrapper(outfile, build_dir, lib_dirs)
                log.info('Python unit tests for ' + pkg)
                try:
                    check_call([wrap])
                except subprocess.CalledProcessError:
                    failed = True
                    print(sys.exc_info()[1])

        ## FORTRAN
        if self._has_fortran_tests():
            env = configure_package('fruit')
            fortran_unittest_framework = [
                os.path.join(env['FRUIT_SOURCE_DIR'], src)
                for src in env['FRUIT_SOURCE_FILES']]
            orig_exes = self.distribution.native_executables

            build = self.get_finalized_command('build')
            lib_dir = os.path.abspath(build.build_temp)
            for pkg, units in self._get_fortran_tests():
                for unit in units:
                    unit.sources = fortran_unittest_framework + unit.sources + \
                        create_fruit_driver(unit.name, unit.sources[0])
                    unit.library_dirs.append(lib_dir)
                    self.distribution.native_executables.append(unit)

            ## build w/ distutils thru backdoor
            cmd_obj = self.get_command_obj('build_exe')
            cmd_obj.ensure_finalized()
            cmd_obj.run()
            self.distribution.native_executables = orig_exes

            for pkg, units in self._get_fortran_tests():
                log.info('Fortran unit tests for ' + pkg)
                for unit in units:
                    try:
                        check_call([os.path.join(lib_dir, unit.name)])
                    except subprocess.CalledProcessError:
                        failed = True
                        print(sys.exc_info()[1])

        ## C
        if self._has_c_tests():
            env = configure_package('cunit')
            orig_exes = self.distribution.native_executables

            build = self.get_finalized_command('build')
            lib_dir = os.path.abspath(build.build_temp)
            for pkg, units in self._get_c_tests():
                for unit in units:
                    unit.sources += create_cunit_driver(unit.name,
                                                             unit.sources[0])
                    unit.include_dirs.append(env['CUNIT_INCLUDE_DIR'])
                    unit.libraries.append(env['CUNIT_LIBRARIES'])
                    unit.library_dirs.append(env['CUNIT_LIB_DIR'])
                    self.distribution.native_executables.append(unit)

            ## build w/ distutils thru backdoor
            cmd_obj = self.get_command_obj('build_exe')
            cmd_obj.ensure_finalized()
            cmd_obj.run()
            self.distribution.native_executables = orig_exes

            for pkg, units in self._get_c_tests():
                log.info('C unit tests for ' + pkg)
                for unit in units:
                    try:
                        check_call([os.path.join(lib_dir, unit.name)])
                    except subprocess.CalledProcessError:
                        failed = True
                        print(sys.exc_info()[1])

        ## C++
        if self._has_cpp_tests():
            env = configure_package('cppunit')
            orig_exes = self.distribution.native_executables

            build = self.get_finalized_command('build')
            lib_dir = os.path.abspath(build.build_temp)
            for pkg, units in self._get_cpp_tests():
                for unit in units:
                    unit.sources += create_cppunit_driver(unit.name)
                    unit.include_dirs.append(env['CPPUNIT_INCLUDE_DIR'])
                    unit.libraries.append(env['CPPUNIT_LIBRARIES'])
                    unit.library_dirs.append(env['CPPUNIT_LIB_DIR'])
                    self.distribution.native_executables.append(unit)

            ## build w/ distutils thru backdoor
            cmd_obj = self.get_command_obj('build_exe')
            cmd_obj.ensure_finalized()
            cmd_obj.run()
            self.distribution.native_executables = orig_exes

            for pkg, units in self._get_cpp_tests():
                log.info('C++ unit tests for ' + pkg)
                for unit in units:
                    try:
                        check_call([os.path.join(lib_dir, unit.name)])
                    except subprocess.CalledProcessError:
                        failed = True
                        print(sys.exc_info()[1])

        ## Javascript
        if self._has_js_tests():
            env = configure_package('qunitsuite')
            from qunitsuite.suite import QUnitSuite  \
                # pylint: disable=F0401,E0602
            for pkg, units in self._get_js_tests():
                for unit in units:
                    suite = QUnitSuite(unit)
                    result = unittest.TextTestRunner(verbosity=2).run(suite)
                    if len(result.errors) > 0:
                        failed = True
                        for error in result.errors:
                            print(error[1])
                    if len(result.failures) > 0:
                        failed = True
                        for failure in result.failures:
                            print(failure[1])

        if failed:
            sys.exit(1)