-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_doc.py
132 lines (108 loc) · 4.28 KB
/
make_doc.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# ********************************************************************************
# Copyright © 2020-2021, ETH Zurich, D-BSSE, Andreas P. Cuny & Aaron Ponti
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the GNU Public License v3.0
# which accompanies this distribution, and is available at
# http://www.gnu.org/licenses/gpl
#
# Contributors:
# * Andreas P. Cuny - initial API and implementation
# * Aaron Ponti - initial API and implementation
# *******************************************************************************
import os
import sys
import errno
import shutil
import subprocess
from pathlib import Path
try:
from pypocquant.manual import build_manual
except:
pypocquant_path = Path(__file__).resolve().parent / 'src' / 'main' / 'python' / 'pyPOCQuantUI'
sys.path.insert(0, str(pypocquant_path))
from pypocquant.manual import build_manual, build_quickstart
def run_process(command):
working_dir = str(Path(__file__).parent / "docs")
p = subprocess.Popen(command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=working_dir)
stdout, stderr = p.communicate()
def copy_files(src, dst):
try:
if os.path.exists(dst):
pass
else:
shutil.copytree(src, dst)
except OSError as e:
if e.errno == errno.ENOTDIR:
os.remove(dst)
shutil.copy(src, dst)
else:
print('Directory not copied. Error: %s' % e)
def make_doc():
"""Run Sphinx to build the doc."""
try:
# First, build the manual
build_manual()
# Build quickstart
build_quickstart()
# removing previous build
print("|---------------------------------------------------------------------------------------------------|")
print('BUILDING DOCS')
print("|---------------------------------------------------------------------------------------------------|")
print('removing previous build')
run_process('make clean')
print('copy files')
manual_dir = Path(__file__).parent / "src" / "main" / "python" / "pyPOCQuantUI" / "pypocquant" / "manual"
docs_dir = Path(__file__).parent / "docs"
src = [
str(manual_dir / "ui_images"),
str(manual_dir / "demo_image"),
str(manual_dir / "problem_solutions"),
str(manual_dir / "setup"),
str(manual_dir / "QuickStart.md"),
str(manual_dir / "UserInstructions.md")
]
dst = [
str(docs_dir / "ui_images"),
str(docs_dir / "demo_image"),
str(docs_dir / "problem_solutions"),
str(docs_dir / "setup"),
str(docs_dir / "QuickStart.md"),
str(docs_dir / "UserInstructions.md")
]
for idx in range(0, len(src)):
copy_files(src[idx], dst[idx])
print('building docs')
# new build
run_process('make html')
# copy missing resources to build directory
print('copy files')
src = [
str(docs_dir / "ui_images"),
str(docs_dir / "demo_image"),
str(docs_dir / "problem_solutions"),
str(docs_dir / "setup")
]
dst = [
str(docs_dir / "_build" / "html" / "ui_images"),
str(docs_dir / "_build" / "html" / "demo_image"),
str(docs_dir / "_build" / "html" / "problem_solutions"),
str(docs_dir / "_build" / "html" / "setup")
]
for idx in range(0, len(src)):
copy_files(src[idx], dst[idx])
# Copy files for README
shutil.copytree(
str(Path(__file__).parent / "src" / "main" / "resources" / "base" / "img"),
str(docs_dir / "_build" / "html" / "src" / "main" / "resources" / "base" / "img")
)
print("|---------------------------------------------------------------------------------------------------|")
print('Done.')
print("|---------------------------------------------------------------------------------------------------|")
except Exception as error:
print(error)
if __name__ == '__main__':
make_doc()