Skip to content

Commit c40fc5d

Browse files
committed
set up auto gen PDFs
1 parent 0b6101a commit c40fc5d

File tree

3 files changed

+52
-15
lines changed

3 files changed

+52
-15
lines changed

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
3333
- name: Build PDF Documentation
3434
run: |
35-
sphinx-build -b pdf source build/pdf
35+
python source/make_spec_versions.py
3636
3737
- name: Deploy to GitHub Pages
3838
uses: peaceiris/actions-gh-pages@v3

source/conf.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
import sys
1414
import os
1515

16-
sys.path.append(os.path.dirname(__file__))
17-
from make_spec_version_toc import make_spec_version_toc
16+
build_type = sys.argv[2]
1817

19-
SPEC_DIR = "specification"
2018
project_title = "Uncertainty Metadata Conventions Specifications"
2119

2220
# -- General configuration ---------------------------------------------
@@ -139,7 +137,10 @@
139137
# ),
140138
# ]
141139

142-
pdf_documents = [('unc_specification', u'rst2pdf', u'Sample rst2pdf doc', u'Your Name'),]
143-
144140
# create specification TOC table
145-
make_spec_version_toc(SPEC_DIR)
141+
if build_type == "html":
142+
sys.path.append(os.path.dirname(__file__))
143+
from make_spec_versions import make_spec_version_toc
144+
145+
SPEC_DIR = "specification"
146+
make_spec_version_toc(SPEC_DIR)
Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
"""unc_website.source.make_spec_version_toc - module containing function to build TOC page for different specification versions"""
2-
3-
from os import listdir
4-
from os.path import isdir
2+
import os.path
3+
from os import listdir, makedirs
4+
from os.path import isdir, dirname, abspath
55
from os.path import join as pjoin
6-
6+
import subprocess
7+
import shutil
8+
from pathlib import Path
79

810
__author__ = "Sam Hunt <sam.hunt@npl.co.uk>"
911
__all__ = ["make_spec_version_toc"]
1012

13+
# Directories
14+
SOURCE_DIR = abspath(dirname(__file__))
1115

1216
# Spec TOC filename
1317
SPEC_FNAME = "spec_toc.rst"
1418

1519
# URL of folder where PDFs are stored
16-
PDF_URL = "https://comet-toolkit.github.io/unc_website/_static"
20+
PDF_PATH = "build/html/_static/spec_pdfs"
21+
PDF_URL = "https://comet-toolkit.github.io/unc_website/_static/spec_pdfs"
1722

1823
# Static page content elements
1924
HEADER = ("======================================\n"
@@ -36,7 +41,7 @@ def make_spec_version_toc(spec_dir: str):
3641
:param spec_dir: directory containing specification versions
3742
"""
3843

39-
toc_path = pjoin(spec_dir, SPEC_FNAME)
44+
toc_path = pjoin(SOURCE_DIR, spec_dir, SPEC_FNAME)
4045
page_content = ""
4146

4247
# add header
@@ -45,7 +50,7 @@ def make_spec_version_toc(spec_dir: str):
4550
# each version of the spec is a separate folder in the spec_dir
4651
spec_vers = [f for f in listdir(spec_dir) if isdir(pjoin(spec_dir, f))]
4752
spec_vers_toc_paths = [f"{f}/unc_specification" for f in spec_vers]
48-
spec_vers_urls = [f"{PDF_URL}/{f}/unc_specification.pdf" for f in spec_vers]
53+
spec_vers_urls = [f"{PDF_URL}/{f}/unc_specification_{f}.pdf" for f in spec_vers]
4954

5055
# add web version TOC
5156
page_content += WEB_VERS_SUBHEADER
@@ -64,5 +69,36 @@ def make_spec_version_toc(spec_dir: str):
6469
f.write(page_content)
6570

6671

72+
def build_spec_pdfs(spec_dir: str):
73+
74+
abs_spec_dir = pjoin(SOURCE_DIR, spec_dir)
75+
76+
spec_vers = [f for f in listdir(abs_spec_dir) if isdir(pjoin(abs_spec_dir, f))]
77+
spec_ver_dirs = [pjoin(abs_spec_dir, f) for f in spec_vers if isdir(pjoin(abs_spec_dir, f))]
78+
79+
conf_file_path = pjoin(SOURCE_DIR, "conf.py")
80+
81+
for spec_ver, spec_ver_dir in zip(spec_vers, spec_ver_dirs):
82+
83+
ver_conf_file_path = pjoin(spec_ver_dir, "conf.py")
84+
shutil.copyfile(conf_file_path, ver_conf_file_path)
85+
86+
tmp_index_path = pjoin(spec_ver_dir, "index.rst")
87+
88+
Path(tmp_index_path).touch()
89+
90+
with open(ver_conf_file_path, "a") as f:
91+
92+
f.write(f"version = '{spec_ver}'\n")
93+
f.write("pdf_documents = [('unc_specification', f'unc_specification_{version}', f'{project_title}', f'{author}'),]")
94+
95+
makedirs(pjoin(PDF_PATH, spec_ver), exist_ok=True)
96+
97+
subprocess.run(["sphinx-build", "-b", "pdf", spec_ver_dir, pjoin(PDF_PATH, spec_ver)])
98+
99+
os.remove(tmp_index_path)
100+
os.remove(ver_conf_file_path)
101+
102+
67103
if __name__ == "__main__":
68-
make_spec_version_toc("source/specification")
104+
build_spec_pdfs("specification")

0 commit comments

Comments
 (0)