Example #1
0
    def run(self):
        environ = self.distribution.environment

        if self.devel_support:
            for tpl in self.devel_support:
                if self.distribution.verbose:
                    print 'adding sysdevel support to ' + tpl[0]
                target = os.path.abspath(os.path.join(self.build_lib,
                                                      *tpl[0].split('.')))
                util.mkdir(target)
                source_dir = os.path.abspath(os.path.join(
                        os.path.dirname(__file__), 'support'))
                for mod in tpl[1]:
                    src_file = os.path.join(source_dir, mod + '.py.in')
                    if not os.path.exists(src_file):
                        src_file = src_file[:-3]
                    dst_file = os.path.join(target, mod + '.py')
                    util.configure_file(environ, src_file, dst_file)


        if self.antlr_modules:
            here = os.getcwd()
            for grammar in self.antlr_modules:
                if self.distribution.verbose:
                    print 'building antlr grammar "' + \
                        grammar.name + '" sources'
                ##TODO build in build_src, add to build_lib modules
                target = os.path.abspath(os.path.join(self.build_lib,
                                                      grammar.directory))
                util.mkdir(target)
                source_dir = os.path.abspath(grammar.directory)
                os.chdir(target)

                reprocess = True
                ref = os.path.join(target, grammar.name + '2Py.py')
                if os.path.exists(ref):
                    reprocess = False
                    for src in grammar.sources:
                        src_path = os.path.join(source_dir, src)
                        if os.path.getmtime(ref) < os.path.getmtime(src_path):
                            reprocess = True
                if reprocess:
                    for src in grammar.sources:
                        ## ANTLR cannot parse from a separate directory
                        shutil.copy(os.path.join(source_dir, src), '.')
                        cmd_line = list(environ['ANTLR'])
                        cmd_line.append(src)
                        status = subprocess.call(cmd_line)
                        if status != 0:
                            raise Exception("Command '" + str(cmd_line) +
                                            "' returned non-zero exit status "
                                            + str(status))
                    ## Cleanup so that it's only Python modules
                    for f in glob.glob('*.g'):
                        os.unlink(f)
                    for f in glob.glob('*.tokens'):
                        os.unlink(f)
                os.chdir(here)
        _build_src.run(self)
Example #2
0
    def run(self):
        if not self.distribution.pypp_ext_modules:
            return
        environ = self.distribution.environment

        ## Make sure that extension sources are complete.
        self.run_command('build_src')
        build = self.get_finalized_command('build')
        if self.distribution.verbose:
            print 'Creating Py++ code generators ...'

        my_build_temp = os.path.join(build.build_base, 'pypp')
        builders = []
        for pext in self.distribution.pypp_ext_modules:
            builder = os.path.basename(pext.pyppdef)[:-6]  ## assumes '.py.in'
            pext.builder = builder
            builders.append(builder)
            builder_py = os.path.join(my_build_temp, builder + '.py')
            if util.is_out_of_date(pext.pyppdef, builder_py):
                util.configure_file(environ, pext.pyppdef, builder_py)

        init = open(os.path.join(my_build_temp, '__init__.py'), 'w')
        init.write('__all__ = ' + str(builders) + '\n\n')
        init.close()
        main = open(os.path.join(my_build_temp, '__main__.py'), 'w')
        main.write('for m in __all__:\n    m.generate()\n\n')
        main.close()
        init = open(os.path.join(build.build_base, '__init__.py'), 'w')
        init.write("__all__ = ['" + os.path.basename(my_build_temp) + "']\n\n")
        init.close()

        self.extensions = []
        for pext in self.distribution.pypp_ext_modules:
            if util.is_out_of_date(os.path.join(my_build_temp,
                                                pext.builder + '.py'),
                                   pext.binding_file):
                if self.distribution.verbose:
                    print '\tfor ' + pext.name
                build_mod = my_build_temp.replace(os.sep, '.')
                full_qual = build_mod + '.' + pext.builder
                __import__(full_qual)
                generator = sys.modules[full_qual]
                pext.sources += generator.generate()
                self.extensions.append(pext)
                    
        build_ext.run(self)
Example #3
0
    def build_module (self, module, module_file, package):
        environ = self.distribution.environment

        if type(package) is StringType:
            package = package.split('.')
        elif type(package) not in (ListType, TupleType):
            raise TypeError, \
                  "'package' must be a string (dot-separated), list, or tuple"

        # Now put the module source file into the "build" area -- this is
        # easy, we just copy it somewhere under self.build_lib (the build
        # directory for Python source).
        outfile = self.get_module_outfile(self.build_lib, package, module)
        dir = os.path.dirname(outfile)
        self.mkpath(dir)
        util.configure_file(environ, module_file, outfile)
        return (outfile, 1)
Example #4
0
    def run(self):
        if not self.distribution.doc_modules:
            return

        ## Make sure that sources are complete in build_lib.
        self.run_command('build_src')
        ## Ditto extensions
        self.run_command('build_ext')

        build = self.get_finalized_command('build')
        buildpy = self.get_finalized_command('build_py')
        target = os.path.abspath(os.path.join(build.build_base, 'http'))
        util.mkdir(target)
        build_verbose = self.distribution.verbose
        environ = self.distribution.environment

        for dext in self.distribution.doc_modules:
            if self.distribution.verbose:
                print 'building documentation "' + dext.name + '" sources'

            doc_dir = os.path.abspath(dext.source_directory)
            extra_dirs = dext.extra_directories
            working_dir = os.path.abspath(os.path.join(self.build_temp,
                                                       dext.source_directory))
            here = os.getcwd()

            reprocess = True
            ref = os.path.join(target, dext.name + '.html')
            root_dir = dext.name
            if os.path.exists(ref) and not self.force:
                reprocess = False
                docbase = os.path.join(doc_dir, 'modules')
                for root, dirnames, filenames in os.walk(docbase):
                    for fn in fnmatch.filter(filenames, '*.rst'):
                        doc = os.path.join(root, fn)
                        if os.path.getmtime(ref) < os.path.getmtime(doc):
                            reprocess = True
                            break
                        src = os.path.join(root_dir, root[len(docbase)+1:],
                                            fn[:-3] + 'py')
                        if os.path.exists(src):
                            if os.path.getmtime(ref) < os.path.getmtime(src):
                                reprocess = True
                                break
            if reprocess:
                src_dirs = []
                for package in buildpy.packages:
                    # Locate package source directory
                    src_dirs.append(os.path.abspath(buildpy.get_package_dir(package)))
                #FIXME rst files in package sources (mutiple packages)
                #src_dir = src_dirs[0]
                src_dir = os.path.abspath('.')
                bld_dir = os.path.abspath(self.build_lib)
                doc_bld_dir = os.path.join(bld_dir,
                                           os.path.relpath(doc_dir, src_dir))
                environ['BUILD_DIR'] = bld_dir
                environ['SOURCE_DIR'] = src_dir
                environ['RELATIVE_SOURCE_DIR'] = os.path.relpath(src_dir,
                                                                 doc_bld_dir)

                util.copy_tree(doc_dir, working_dir, True,
                                excludes=['.svn', 'CVS', '.git', '.hg*'])
                for d in extra_dirs:
                    subdir = os.path.basename(os.path.normpath(d))
                    util.copy_tree(d, os.path.join(target, subdir), True,
                                   excludes=['.svn', 'CVS', '.git', '.hg*'])

                ## Configure rst files
                util.configure_files(environ, src_dir, '*.rst', working_dir)

                if os.path.exists(os.path.join(doc_dir, dext.doxygen_cfg)):
                    ## Doxygen + breathe
                    'Config ' + os.path.join(doc_dir, dext.doxygen_cfg)
                    util.configure_file(environ,
                                        os.path.join(doc_dir, dext.doxygen_cfg),
                                        os.path.join(working_dir,
                                                     dext.doxygen_cfg),
                                        style=dext.style)
                    for s in dext.doxygen_srcs:
                        util.configure_file(environ,
                                            os.path.join(doc_dir, s),
                                            os.path.join(working_dir, s),
                                            style=dext.style)
                    try:
                        doxygen_exe = util.find_program('doxygen')
                    except:
                        sys.stderr.write('ERROR: Doxygen not installed ' +
                                         '(required for documentation).\n')
                        return

                    reprocess = True
                    ref = os.path.join(working_dir, 'html', 'index.html')
                    if os.path.exists(ref) and not self.force:
                        reprocess = False
                        for d in environ['C_SOURCE_DIRS'].split(' '):
                            for orig in glob.glob(os.path.join(d, '*.h*')):
                               if os.path.getmtime(ref) < \
                                        os.path.getmtime(orig):
                                    reprocess = True
                                    break
                    if reprocess:
                        if self.distribution.verbose:
                            out = sys.stdout
                            err = sys.stderr
                        else:
                            out = err = open('doxygen.log', 'w')
                        os.chdir(working_dir)
                        cmd_line = [doxygen_exe, dext.doxygen_cfg]
                        status = subprocess.call(cmd_line,
                                                 stdout=out, stderr=err)
                        if status != 0:
                            raise Exception("Command '" + str(cmd_line) +
                                            "' returned non-zero exit status "
                                            + str(status))

                        if not self.distribution.verbose:
                            out.close()
                        util.copy_tree('html', os.path.join(target, 'html'), True,
                                       excludes=['.svn', 'CVS', '.git', '.hg*'])
                        os.chdir(here)
                        create_breathe_stylesheet(target)

                for f in dext.extra_docs:
                    shutil.copy(os.path.join(doc_dir, f), target)

                ## Sphinx
                if dext.without_sphinx:
                    return
                if dext.sphinx_config is None:
                    dext.sphinx_config = os.path.join(os.path.dirname(__file__),
                                                      'sphinx_conf.py.in')
                elif os.path.dirname(dext.sphinx_config) == '':
                    dext.sphinx_config =  os.path.join(doc_dir,
                                                       dext.sphinx_config)
                util.configure_file(environ, dext.sphinx_config,
                                    os.path.join(working_dir, 'conf.py'))
                import warnings
                try:
                    import sphinx
                    from sphinx.application import Sphinx
                    if 'windows' in platform.system().lower() or \
                            not build_verbose:
                        from sphinx.util.console import nocolor
                except:
                    sys.stderr.write('ERROR: Sphinx not installed ' +
                                     '(required for documentation).\n')
                    return
                warnings.filterwarnings("ignore",
                                        category=PendingDeprecationWarning)
                warnings.filterwarnings("ignore", category=UserWarning)

                status = sys.stdout
                if not build_verbose:
                    status = open('sphinx.log', 'w')
                if 'windows' in platform.system().lower() or not build_verbose:
                    nocolor()
                try:
                    sphinx_app = Sphinx(working_dir, working_dir, target,
                                        os.path.join(target, '.doctrees'),
                                        'html', None, status)
                    sphinx_app.build(True)
                except Exception, e:
                    if build_verbose:
                        print 'ERROR: ' + str(e)
                    else:
                        pass
                if not build_verbose:
                    status.close()
                warnings.resetwarnings()
Example #5
0
    def run(self):
        if not self.web_ext_modules:
            return

        ## Make sure that extension sources are complete.
        self.run_command('build_src')
        build = self.get_finalized_command('build')
        environ = self.distribution.environment

        import pyjs
        ## TODO: use pyjs module directly (instead of 'pyjsbuild')
        for wext in self.web_ext_modules:
            if self.distribution.verbose:
                print 'building web extension "' + \
                    os.path.join(wext.public_subdir, wext.name) + '" sources'

            target = os.path.abspath(os.path.join(build.build_base, 'http',
                                                  wext.public_subdir))
            util.mkdir(target)
            here = os.getcwd()
            src_dir = os.path.abspath(wext.source_directory)
            working_dir = os.path.abspath(os.path.join(build.build_temp,
                                                       'web', wext.name))
            util.mkdir(working_dir)

            for support in wext.extra_support_files:
                src_file = util.sysdevel_support_path(support + '.in')
                if not os.path.exists(src_file):
                    src_file = src_file[:-3]
                dst_file = os.path.join(working_dir, support)
                util.configure_file(environ, src_file, dst_file)

            reprocess = True
            ref = os.path.join(target, wext.name + '.html')
            if os.path.exists(ref) and not self.force:
                reprocess = False
                for src in wext.sources:
                    if os.path.getmtime(ref) < os.path.getmtime(src):
                        reprocess = True
            if reprocess:
                for s in wext.sources:
                    util.configure_file(environ, s,
                                        os.path.join(working_dir,
                                                     os.path.basename(s)))
                ## Specifying public-folder is broken (see below)
                util.copy_tree(os.path.join(src_dir, 'public'),
                               os.path.join(working_dir, 'public'),
                               update=True, verbose=self.distribution.verbose,
                               excludes=['.svn', 'CVS'])

                compiler = wext.compiler or \
                    environ['PYJSBUILD'] or self.pyjscompiler
                if compiler is None:
                    raise DistutilsExecError, \
                        "no value pyjsbuild executable found or given"
                cmd_line = [os.path.abspath(compiler)]
                for arg in wext.extra_compile_args:
                    if 'debug' in arg.lower():
                        cmd_line.append('--debug')
                        cmd_line.append('--print-statements')
                    else:
                        cmd_line.append(arg)
                if self.distribution.verbose:
                    cmd_line.append('--log-level=' + str(logging.INFO))
                else:
                    cmd_line.append('--log-level=' + str(logging.ERROR))
                cmd_line.append('--output=' + target)
                ## RuntimeError: File not found '_pyjs.js' (bypassed above)
                #cmd_line.append('--public-folder=' +
                #                os.path.join(src_dir, 'public'))
                cmd_line.append(wext.name)

                os.chdir(working_dir)
                status = subprocess.call(cmd_line)
                if status != 0:
                    raise Exception("Command '" + str(cmd_line) +
                                    "' returned non-zero exit status "
                                    + str(status))
                os.chdir(here)

            for filename in wext.extra_public_files:
                filepath = util.sysdevel_support_path(filename + '.in')
                if not os.path.exists(filepath):
                    filepath = filepath[:-3]
                targetfile = os.path.join(target, filename)
                if not os.path.exists(targetfile):
                    util.configure_file(environ, filepath, targetfile)

            js_dir = os.path.join(build.build_base, util.javascript_dir)
            if os.path.exists(js_dir):
                util.copy_tree(js_dir, os.path.join(target,
                                                    util.javascript_dir))

            if not os.path.lexists(os.path.join(target, 'index.html')):
                shutil.copyfile(os.path.join(target, wext.name + '.html'),
                                os.path.join(target, 'index.html'))