Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/doc/common/inventory_builder.py
8815 views
1
# -*- coding: utf-8 -*-
2
"""
3
inventory builder
4
~~~~~~~~~~~~~~~~~
5
6
A customized HTML builder which only generates intersphinx "object.inv"
7
inventory files and pickle files. The documentation files are not written.
8
"""
9
from sphinx.builders.html import StandaloneHTMLBuilder
10
from sphinx.util.console import bold
11
from os import path
12
try:
13
from hashlib import md5
14
except ImportError:
15
# 2.4 compatibility
16
from md5 import md5
17
18
class InventoryBuilder(StandaloneHTMLBuilder):
19
"""
20
A customized HTML builder which only generates intersphinx "object.inv"
21
inventory files and pickle files. The documentation files are not written.
22
"""
23
name = "inventory"
24
25
def get_outdated_docs(self):
26
cfgdict = dict((name, self.config[name])
27
for (name, desc) in self.config.values.iteritems()
28
if desc[1] == 'html')
29
self.config_hash = md5(unicode(cfgdict).encode('utf-8')).hexdigest()
30
self.tags_hash = md5(unicode(sorted(self.tags)).encode('utf-8')) \
31
.hexdigest()
32
old_config_hash = old_tags_hash = ''
33
try:
34
fp = open(path.join(self.outdir, '.buildinfo'))
35
try:
36
version = fp.readline()
37
if version.rstrip() != '# Sphinx build info version 1':
38
raise ValueError
39
fp.readline() # skip commentary
40
cfg, old_config_hash = fp.readline().strip().split(': ')
41
if cfg != 'config':
42
raise ValueError
43
tag, old_tags_hash = fp.readline().strip().split(': ')
44
if tag != 'tags':
45
raise ValueError
46
finally:
47
fp.close()
48
except ValueError:
49
self.warn('unsupported build info format in %r, building all' %
50
path.join(self.outdir, '.buildinfo'))
51
except Exception:
52
pass
53
if old_config_hash != self.config_hash or \
54
old_tags_hash != self.tags_hash:
55
for docname in self.env.found_docs:
56
yield docname
57
return
58
59
if self.templates:
60
template_mtime = self.templates.newest_template_mtime()
61
else:
62
template_mtime = 0
63
for docname in self.env.found_docs:
64
if docname not in self.env.all_docs:
65
yield docname
66
continue
67
targetname = path.join(self.outdir, 'objects.inv')
68
try:
69
targetmtime = path.getmtime(targetname)
70
except Exception:
71
targetmtime = 0
72
try:
73
srcmtime = max(path.getmtime(self.env.doc2path(docname)),
74
template_mtime)
75
if srcmtime > targetmtime:
76
yield docname
77
except EnvironmentError:
78
# source doesn't exist anymore
79
pass
80
81
def write_doc(self, docname, doctree):
82
"""
83
Don't write any doc
84
"""
85
86
def finish(self):
87
"""
88
Only write the inventory files.
89
"""
90
self.write_buildinfo()
91
self.dump_inventory()
92
93
def removed_method_error(self):
94
"""
95
Raise an error if this method is called.
96
97
This is just for making sure that some writer methods are indeed
98
deactivated.
99
"""
100
raise RuntimeError, "This function shouldn't be called in \"%s\" builder"%(self.name)
101
102
copy_image_files = removed_method_error
103
copy_download_files = removed_method_error
104
copy_static_files = removed_method_error
105
handle_finish = removed_method_error
106
107
def setup(app):
108
app.add_builder(InventoryBuilder)
109
110
111