示例#1
0
    def get_outdated_docs(self):
        cfgdict = dict((name, self.config[name])
                       for (name, desc) in iteritems(self.config.values)
                       if desc[1] == 'html')
        self.config_hash = get_stable_hash(cfgdict)
        self.tags_hash = get_stable_hash(sorted(self.tags))
        old_config_hash = old_tags_hash = ''
        try:
            fp = open(path.join(self.outdir, '.buildinfo'))
            try:
                version = fp.readline()
                if version.rstrip() != '# Sphinx build info version 1':
                    raise ValueError
                fp.readline()  # skip commentary
                cfg, old_config_hash = fp.readline().strip().split(': ')
                if cfg != 'config':
                    raise ValueError
                tag, old_tags_hash = fp.readline().strip().split(': ')
                if tag != 'tags':
                    raise ValueError
            finally:
                fp.close()
        except ValueError:
            self.warn('unsupported build info format in %r, building all' %
                      path.join(self.outdir, '.buildinfo'))
        except Exception:
            pass
        if old_config_hash != self.config_hash or \
           old_tags_hash != self.tags_hash:

            for docname in self.env.found_docs:
                yield docname
            return

        if self.templates:
            template_mtime = self.templates.newest_template_mtime()
        else:
            template_mtime = 0

        for docname in self.env.found_docs:
            if docname not in self.env.all_docs:
                yield docname
                continue
            targetname = self.get_outfilename(docname)
            try:
                targetmtime = path.getmtime(targetname)
            except Exception:
                targetmtime = 0
            try:
                srcmtime = max(path.getmtime(self.env.doc2path(docname)),
                               template_mtime)
                if srcmtime > targetmtime:
                    yield docname
            except EnvironmentError:
                # source doesn't exist anymore
                pass
示例#2
0
def fix_build_env(builder, conf):
    """
    Given a builder name and the conf object, this function fixes the build
    artifacts for the current build to prevent a full rebuild. Currently
    re-pickles the environment and dumps the ``.buildinfo`` file in the build
    directory with the correct hashes.
    """

    fn = os.path.join(conf.paths.projectroot, conf.paths.branch_output,
                      builder, '.buildinfo')
    logger.info('updating cache for: ' + builder)

    if not os.path.isfile(fn):
        return

    doctree_dir = os.path.join(conf.paths.projectroot,
                               conf.paths.branch_output, "doctrees-" + builder)

    sphinx_app = Sphinx(srcdir=os.path.join(conf.paths.projectroot,
                                            conf.paths.branch_output,
                                            "source"),
                        confdir=conf.paths.projectroot,
                        outdir=os.path.join(conf.paths.projectroot,
                                            conf.paths.branch_output, builder),
                        doctreedir=doctree_dir,
                        buildername=builder,
                        status=tempfile.NamedTemporaryFile(),
                        warning=tempfile.NamedTemporaryFile())

    sphinx_app.env.topickle(os.path.join(doctree_dir, ENV_PICKLE_FILENAME))

    with open(fn, 'r') as f:
        lns = f.readlines()
        tags_hash_ln = None
        for ln in lns:
            if ln.startswith('tags'):
                tags_hash_ln = ln
                break

        if tags_hash_ln is None:
            tags_hash_ln = 'tags: ' + get_stable_hash(sorted(sphinx_app.tags))

    with open(fn, 'w') as f:
        config_dict = dict(
            (name, sphinx_app.config[name])
            for (name, desc) in sphinx_app.config.values.items()
            if desc[1] == 'html')

        f.write('# Sphinx build info version 1')
        f.write('\n\n')  # current format requires an extra line here.
        f.write('config: ' + get_stable_hash(config_dict))
        f.write('\n')
        f.write(tags_hash_ln)
        f.write('\n')
示例#3
0
def fix_build_env(builder, conf):
    """
    Given a builder name and the conf object, this function fixes the build
    artifacts for the current build to prevent a full rebuild. Currently
    re-pickles the environment and dumps the ``.buildinfo`` file in the build
    directory with the correct hashes.
    """

    fn = os.path.join(conf.paths.projectroot, conf.paths.branch_output, builder, '.buildinfo')
    logger.info('updating cache for: ' + builder)

    if not os.path.isfile(fn):
        return

    doctree_dir = os.path.join(conf.paths.projectroot,
                               conf.paths.branch_output,
                               "doctrees-" + builder)

    sphinx_app = Sphinx(srcdir=os.path.join(conf.paths.projectroot,
                                            conf.paths.branch_output, "source"),
                        confdir=conf.paths.projectroot,
                        outdir=os.path.join(conf.paths.projectroot,
                                            conf.paths.branch_output, builder),
                        doctreedir=doctree_dir,
                        buildername=builder,
                        status=tempfile.NamedTemporaryFile(),
                        warning=tempfile.NamedTemporaryFile())

    sphinx_app.env.topickle(os.path.join(doctree_dir, ENV_PICKLE_FILENAME))

    with open(fn, 'r') as f:
        lns = f.readlines()
        tags_hash_ln = None
        for ln in lns:
            if ln.startswith('tags'):
                tags_hash_ln = ln
                break

        if tags_hash_ln is None:
            tags_hash_ln = 'tags: ' + get_stable_hash(sorted(sphinx_app.tags))

    with open(fn, 'w') as f:
        config_dict = dict((name, sphinx_app.config[name])
                           for (name, desc) in sphinx_app.config.values.items()
                           if desc[1] == 'html')

        f.write('# Sphinx build info version 1')
        f.write('\n\n')  # current format requires an extra line here.
        f.write('config: ' + get_stable_hash(config_dict))
        f.write('\n')
        f.write(tags_hash_ln)
        f.write('\n')
示例#4
0
    def get_outdated_docs(self):
        cfgdict = dict((name, self.config[name]) for (name, desc) in iteritems(self.config.values) if desc[1] == "html")
        self.config_hash = get_stable_hash(cfgdict)
        self.tags_hash = get_stable_hash(sorted(self.tags))
        old_config_hash = old_tags_hash = ""
        try:
            fp = open(path.join(self.outdir, ".buildinfo"))
            try:
                version = fp.readline()
                if version.rstrip() != "# Sphinx build info version 1":
                    raise ValueError
                fp.readline()  # skip commentary
                cfg, old_config_hash = fp.readline().strip().split(": ")
                if cfg != "config":
                    raise ValueError
                tag, old_tags_hash = fp.readline().strip().split(": ")
                if tag != "tags":
                    raise ValueError
            finally:
                fp.close()
        except ValueError:
            self.warn("unsupported build info format in %r, building all" % path.join(self.outdir, ".buildinfo"))
        except Exception:
            pass
        if old_config_hash != self.config_hash or old_tags_hash != self.tags_hash:

            for docname in self.env.found_docs:
                yield docname
            return

        if self.templates:
            template_mtime = self.templates.newest_template_mtime()
        else:
            template_mtime = 0

        for docname in self.env.found_docs:
            if docname not in self.env.all_docs:
                yield docname
                continue
            targetname = self.get_outfilename(docname)
            try:
                targetmtime = path.getmtime(targetname)
            except Exception:
                targetmtime = 0
            try:
                srcmtime = max(path.getmtime(self.env.doc2path(docname)), template_mtime)
                if srcmtime > targetmtime:
                    yield docname
            except EnvironmentError:
                # source doesn't exist anymore
                pass