1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
from __future__ import print_function
# You can register a handler that will be called when a symlink
# Can't be created or deleted.
def handle_autobuild_error(input_path, exception):
pass
def customized_builddir(project,builddir):
from os import path as p
return p.abspath(p.join(builddir,'html',project))
def fetch_inventory(uri):
from sphinx.ext import intersphinx
import warnings
"""Read a Sphinx inventory file into a dictionary."""
class MockConfig(object):
intersphinx_timeout = None # type: int
tls_verify = False
class MockApp(object):
srcdir = ''
config = MockConfig()
def warn(self, msg):
warnings.warn(msg)
return intersphinx.fetch_inventory(MockApp(), '', uri)
def project_builder(project,builddir=None):
"""
Build the project indicated by the input.
A temporary directory is created next to the source directory
of the project, therefore the builder should have writing permission to it.
"""
from sphinx_multibuild import SphinxMultiBuilder
from os import path as p
projpath=p.abspath(project)
source=p.join(projpath,'source')
tmp=p.join(projpath,'tmp')
build=p.join(projpath,'build') if builddir is None else customized_builddir(project,builddir)
print('Creating builder for package: ',project)
# Instantiate multi builder. The last two params are optional.
return SphinxMultiBuilder(# input directories
[source],
# Temp directory where symlinks are placed.
tmp,
# Output directory
build,
# Sphinx arguments, this doesn't include the in-
# and output directory and filenames argments.
["-M", "html", "-c", source],
# Specific files to build(optional).
#["index.rst"],
# Callback that will be called when symlinking
# error occurs during autobuilding. (optional)
#handle_autobuild_error
)
# Example configuration for intersphinx: refer to the Python standard library.
def project_tuple(project,builddir=None):
"""
Function which is needed to retrieve the absolute paths
for the local intersphinx mapping file `objects.inv`.
Thanks to this functions the `BigDFT-suite` packages can
be referred each other.
"""
import os
build_path=os.path.join(project,'build') if builddir is None else customized_builddir(project,builddir)
html_path=os.path.join(build_path,'html')
object_path=os.path.abspath(html_path)
return (object_path,os.path.join(object_path,'objects.inv'))
if __name__=='__main__':
import logging
import time
import sys,os
# Package respects loglevel set by application. Info prints out change events
# in input directories and warning prints exception that occur during symlink
# creation/deletion.
loglevel = logging.INFO
logging.basicConfig(format='%(message)s', level=loglevel)
builder = project_builder('PyBigDFT')
# build once
builder.build()
# start autobuilding on change in any input directory until ctrl+c is pressed.
builder.start_autobuilding()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
builder.stop_autobuilding()
# return the last exit code sphinx build returned had as program exit code.
sys.exit(builder.get_last_exit_code())
|