Skip to content

Commit 084a3da

Browse files
committed
Give more control to docs build [skip appveyor]
The documentation build can now selectively disable doing the APIdocs build (which is slow, and requires Sphinx and some extensions to be installed); and skip building pdf versions of docs (which requires fop or equivalent to be installed). Both can be disabled by using a csv: scons doc SKIP_DOCS=pdf,api TODO: pdf disabling is only partly working. It does not build the pdf version of the api docs, but does build pdf manpages and user guide. The latter are not "installed": there is no build/doc/PDF, but there are pdfs in the build directory, build/doc/man and build/doc/user. This is part two of the doc build change (begun in SCons#4492) Signed-off-by: Mats Wichmann <[email protected]>
1 parent 2c3983f commit 084a3da

File tree

4 files changed

+109
-53
lines changed

4 files changed

+109
-53
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
111111
Sphinx build.
112112
- Add locking around creation of CacheDir config file. Fixes #4489.
113113
- Clarify MergeFlags usage of a dict argument.
114+
- SCons documentation build can now be controlled through SKIP_DOC
115+
variable - rather than just true/false can now specifiy
116+
skip none, skip all, skip pdf docs, skip api docs.
114117

115118

116119
RELEASE 4.6.0 - Sun, 19 Nov 2023 17:22:20 -0700

RELEASE.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ PACKAGING
8888
---------
8989

9090
- Remove unecessary dependencies on pypi packages from setup.cfg
91+
- SCons documentation build can now be controlled through SKIP_DOC
92+
variable - rather than just true/false can now specifiy
93+
skip none, skip all, skip pdf docs, skip api docs.
9194

9295
DOCUMENTATION
9396
-------------

doc/SConscript

Lines changed: 100 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -35,43 +35,78 @@ import SCons.Util
3535

3636
Import('command_line', 'env', 'whereis', 'revaction')
3737

38+
# Check prerequisites and flags for building the documentation. There are
39+
# several combinations in play. Conceptually there are five builds:
40+
# - manpage and user guide output in html (and manpage in roff-style "source")
41+
# - manpage and user guide output in pdf
42+
# - API docs with Sphinx output in html
43+
# - API docs with Sphinx output in pdf
44+
# - Bundle up the built bits into the tarball for upload to the website.
3845
#
39-
# -- Check prerequisites for building the documentation ---
46+
# These are sometimes a bit in tension. For example, we shouldn't need any
47+
# doc bits to build the wheel for testing or uploading, except that the
48+
# manpages (.1 format) are built and dropped into the top directory for
49+
# use by distribution packagers - even though that's not really a suitable
50+
# place for them. And since we're often building the wheel to make a release,
51+
# we actually may end up wanting the docs anyway.
4052
#
41-
skip_doc = False
42-
43-
try:
44-
import SConsDoc
45-
import SConsExamples
46-
except ImportError as exc:
47-
print("doc: SConsDoc failed to import, the error was:")
48-
print(f" ImportError: {exc}")
49-
print(" Please make sure that python-lxml is installed.")
50-
skip_doc = True
51-
52-
fop = whereis('fop')
53-
xep = whereis('xep')
54-
55-
if not fop and not xep:
56-
print("doc: No PDF renderer found (fop|xep)!")
57-
skip_doc = True
58-
59-
skip_doc_arg = ARGUMENTS.get('SKIP_DOC')
60-
if skip_doc_arg is not None:
61-
skip_doc = skip_doc_arg in ['True', '1', 'true']
53+
# We want to be able to have some choice in combinations, so that for example
54+
# there's a command to build just the manpages for distros without having
55+
# to have the whole fop (for pdf) and Sphinx (for API docs) chains setup
56+
# just to do a successful build, since those won't be part of those
57+
# packages anyway.
58+
59+
skip_doc_build = False
60+
skip_pdf_build = False
61+
skip_api_build = False
62+
63+
# SKIP_DOC is a csv with various options. It doesn't seem necessary
64+
# to do a very sophisticated decode of it, but could add that later.
65+
skip_doc_args = ARGUMENTS.get('SKIP_DOC', 'none').split(',')
66+
if 'none' not in skip_doc_args:
67+
if 'all' in skip_doc_args:
68+
skip_doc_build = skip_pdf_build = skip_api_build = True
69+
if 'api' in skip_doc_args:
70+
skip_api_build = True
71+
if 'pdf' in skip_doc_args:
72+
skip_pdf_build = True
73+
74+
if not skip_doc_build:
75+
try:
76+
import SConsDoc
77+
import SConsExamples
78+
except ImportError as exc:
79+
print("doc: SConsDoc failed to import, the error was:")
80+
print(f" ImportError: {exc}")
81+
print(" Please make sure the Python lxml package is installed.")
82+
print(" Skipping documentation build.")
83+
skip_doc_build = skip_pdf_build = skip_api_build = True
84+
85+
if not skip_pdf_build:
86+
fop = whereis('fop')
87+
xep = whereis('xep')
88+
89+
if not fop and not xep:
90+
print("doc: No PDF renderer found (fop|xep)!")
91+
print(" Skipping PDF generation.")
92+
skip_pdf_build = True
93+
94+
if not skip_api_build:
95+
ctx = env.Configure()
96+
sphinx = ctx.CheckProg("sphinx-build")
97+
if sphinx is None:
98+
print("doc: Configure did not find sphinx-build")
99+
print(" Skipping API docs generation.")
100+
skip_api_build = True
101+
ctx.Finish()
62102

63103
#
64104
# --- Configure build
65105
#
66-
env = env.Clone()
67-
68106
build = os.path.join(command_line.build_dir, 'doc')
69-
70107
gs = whereis('gs')
71108
lynx = whereis('lynx')
72-
73109
dist_doc_tar_gz = '$DISTDIR/scons-doc-${VERSION}.tar.gz'
74-
75110
tar_deps = []
76111
tar_list = []
77112

@@ -105,7 +140,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT.
105140
man_page_list = ['scons.1', 'scons-time.1', 'sconsign.1']
106141

107142
# Template for the MAN page texts when we can't properly
108-
# create them because the skip_doc flag is set (required
143+
# create them because the skip_doc_build flag is set (required
109144
# modules/tools aren't installed in the current system)
110145
man_replace_tpl = r""".TH "%(uctitle)s" "1" "%(today)s" "SCons %(version)s" "SCons %(version)s"
111146
.ie \n(.g .ds Aq \(aq
@@ -121,7 +156,7 @@ update the system and try running the build again.
121156
#
122157
# --- Processing ---
123158
#
124-
if skip_doc:
159+
if skip_doc_build:
125160
print("doc: ...skipping building User Guide.")
126161
print(" ...creating fake MAN pages.")
127162

@@ -138,6 +173,7 @@ if skip_doc:
138173
version = env.subst('$VERSION')
139174
for m in man_page_list:
140175
man, _ = os.path.splitext(m)
176+
# TODO: add these to Alias?
141177
with open(os.path.join(scdir, m), "w") as fman:
142178
fman.write(
143179
man_replace_tpl
@@ -158,6 +194,7 @@ else:
158194
# Always create a version.xml file containing the version information
159195
# for this run. Ignore it for dependency purposes so we don't
160196
# rebuild all the docs every time just because the date changes.
197+
# TODO: couldn't we use Textfile + Ignore?
161198
date, ver, rev, copyright_years = env.Dictionary(
162199
'DATE', 'VERSION', 'REVISION', 'COPYRIGHT_YEARS'
163200
)
@@ -439,16 +476,18 @@ else:
439476
sctargets.append(
440477
env.File(os.path.join(scdir, f'scons-{doc}', 'index.html'))
441478
)
442-
if 'pdf' in targets:
479+
if 'pdf' in targets and not skip_pdf_build:
443480
sctargets.append(env.File(os.path.join(scdir, f'scons-{doc}.pdf')))
444481
if 'epub' in targets:
445482
sctargets.append(env.File(os.path.join(scdir, f'scons-{doc}.epub')))
446483

447484
if 'man' in targets:
448485
for m in man_page_list:
486+
# TODO: add targets to an alias?
449487
sctargets.append(os.path.join(scdir, m))
450488
man, _1 = os.path.splitext(m)
451-
sctargets.append(os.path.join(scdir, f'scons-{man}.pdf'))
489+
if not skip_pdf_build:
490+
sctargets.append(os.path.join(scdir, f'scons-{man}.pdf'))
452491
sctargets.append(os.path.join(scdir, f'scons-{man}.html'))
453492

454493
nodes.extend(
@@ -489,13 +528,13 @@ else:
489528
target=env.File(html),
490529
source=env.File(os.path.join(build, doc, 'index.html')),
491530
)
492-
tar_deps.extend([html])
493-
tar_list.extend([html])
531+
tar_deps.append(html)
532+
tar_list.append(html)
494533
Local(html)
495534
env.Ignore(html, version_xml)
496535
install_css = True
497536

498-
if 'pdf' in targets:
537+
if 'pdf' in targets and not skip_pdf_build:
499538
env.InstallAs(
500539
target=env.File(pdf),
501540
source=env.File(os.path.join(build, doc, f'scons-{doc}.pdf')),
@@ -546,17 +585,21 @@ else:
546585
pdf = os.path.join(build, 'PDF', f'{man}-man.pdf')
547586
html = os.path.join(build, 'HTML', f'{man}-man.html')
548587

549-
env.InstallAs(
550-
target=env.File(pdf),
551-
source=env.File(os.path.join(build, 'man', f'scons-{man}.pdf')),
552-
)
588+
if not skip_pdf_build:
589+
env.InstallAs(
590+
target=env.File(pdf),
591+
source=env.File(os.path.join(build, 'man', f'scons-{man}.pdf')),
592+
)
553593
env.InstallAs(
554594
target=env.File(html),
555595
source=env.File(os.path.join(build, 'man', f'scons-{man}.html')),
556596
)
557597

558-
tar_deps.extend([pdf, html])
559-
tar_list.extend([pdf, html])
598+
tar_deps.append(html)
599+
tar_list.append(html)
600+
if not skip_pdf_build:
601+
tar_deps.append(pdf)
602+
tar_list.append(pdf)
560603

561604
# Install CSS file, common to all single HTMLs
562605
if install_css:
@@ -565,22 +608,26 @@ else:
565608
target=env.File(css_file),
566609
source=env.File(os.path.join(build, 'user', 'scons.css')),
567610
)
568-
tar_deps.extend([css_file])
569-
tar_list.extend([css_file])
611+
tar_deps.append(css_file)
612+
tar_list.append(css_file)
570613
Local(css_file)
571614

572-
if not skip_doc:
615+
if skip_api_build:
616+
Alias("apidoc")
617+
else:
573618
# Build API DOCS
574619
# TODO: Better specify dependencies on source files
575-
pdf_file = env.Command(
576-
target='#/build/doc/api/scons-api.pdf',
577-
source=env.Glob('#/SCons/*'),
578-
action=[Delete("#/build/doc/api"), "cd doc && make pdf"],
579-
)
580-
pdf_install = os.path.join(build, 'PDF', 'scons-api.pdf')
581-
env.InstallAs(target=pdf_install, source=pdf_file)
582-
tar_deps.append(pdf_install)
583-
tar_list.append(pdf_install)
620+
if not skip_pdf_build:
621+
pdf_file = env.Command(
622+
target='#/build/doc/api/scons-api.pdf',
623+
source=env.Glob('#/SCons/*'),
624+
action=[Delete("#/build/doc/api"), "cd doc && make pdf"],
625+
)
626+
pdf_install = os.path.join(build, 'PDF', 'scons-api.pdf')
627+
env.InstallAs(target=pdf_install, source=pdf_file)
628+
tar_deps.append(pdf_install)
629+
tar_list.append(pdf_install)
630+
Alias('apidoc', pdf_file)
584631

585632
htmldir = os.path.join(build, 'HTML', 'scons-api')
586633
html_files = env.Command(
@@ -591,6 +638,7 @@ if not skip_doc:
591638
)
592639
tar_deps.append(htmldir)
593640
tar_list.append(htmldir)
641+
Alias('apidoc', html_files)
594642

595643
#
596644
# Now actually create the tar file of the documentation,

site_scons/BuildCommandLine.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def init_command_line_variables(self):
7777
),
7878
(
7979
"SKIP_DOC=",
80-
"Skip building all documents. The default is False (build docs)"
80+
"Skip building documents. The value can be 'pdf', 'api', "
81+
"''all' or 'none'. A comma-separated list is also allowed. "
82+
"The default is 'none' (build all docs)"
8183
),
8284
]
8385

0 commit comments

Comments
 (0)