Skip to content

Commit

Permalink
Fix dependencies for docs, using a Sphinx extension to generate a dep…
Browse files Browse the repository at this point in the history
… file, as suggested by @eli-schwart in #15169 (comment)

Actually, the depfile (sphinx.d) is removed by nija after generating
it as shown by a trace.  I do not know why, but touching an .rts
file has the correct behaviour. So I suspoect it is an optimization.
  • Loading branch information
omoerbeek committed Feb 18, 2025
1 parent 1fb0df5 commit 1314b45
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 7 deletions.
69 changes: 69 additions & 0 deletions docs/depfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# coding=utf-8

Check warning on line 1 in docs/depfile.py

View workflow job for this annotation

GitHub Actions / Spell checking

`depfile` is not a recognized word. (check-file-path)
#
# QEMU depfile generation extension

Check warning on line 3 in docs/depfile.py

View workflow job for this annotation

GitHub Actions / Spell checking

`depfile` is not a recognized word. (unrecognized-spelling)
#
# Copyright (c) 2020 Red Hat, Inc.
#
# This work is licensed under the terms of the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.

"""depfile is a Sphinx extension that writes a dependency file for

Check warning on line 10 in docs/depfile.py

View workflow job for this annotation

GitHub Actions / Spell checking

`depfile` is not a recognized word. (unrecognized-spelling)
an external build system"""

import os
import sphinx
import sys
from pathlib import Path

__version__ = '1.0'

def get_infiles(env):
for x in env.found_docs:
yield str(env.doc2path(x))
yield from ((os.path.join(env.srcdir, dep)
for dep in env.dependencies[x]))
for mod in sys.modules.values():
if hasattr(mod, '__file__'):
if mod.__file__:
yield mod.__file__
# this is perhaps going to include unused files:
for static_path in env.config.html_static_path + env.config.templates_path:
for path in Path(static_path).rglob('*'):
yield str(path)

# also include kdoc script

Check warning on line 34 in docs/depfile.py

View workflow job for this annotation

GitHub Actions / Spell checking

`kdoc` is not a recognized word. (unrecognized-spelling)
#yield str(env.config.kerneldoc_bin[1])

Check warning on line 35 in docs/depfile.py

View workflow job for this annotation

GitHub Actions / Spell checking

`kerneldoc` is not a recognized word. (unrecognized-spelling)


def write_depfile(app, exception):

Check warning on line 38 in docs/depfile.py

View workflow job for this annotation

GitHub Actions / Spell checking

`depfile` is not a recognized word. (unrecognized-spelling)
if exception:
return

env = app.env
if not env.config.depfile:

Check warning on line 43 in docs/depfile.py

View workflow job for this annotation

GitHub Actions / Spell checking

`depfile` is not a recognized word. (unrecognized-spelling)
return

# Using a directory as the output file does not work great because
# its timestamp does not necessarily change when the contents change.
# So create a timestamp file.
if env.config.depfile_stamp:

Check warning on line 49 in docs/depfile.py

View workflow job for this annotation

GitHub Actions / Spell checking

`depfile` is not a recognized word. (unrecognized-spelling)
with open(env.config.depfile_stamp, 'w') as f:
print('depfile.py: Writing ' + env.config.depfile_stamp)

with open(env.config.depfile, 'w') as f:
print('depfile.py: Writing ' + env.config.depfile)
print((env.config.depfile_stamp or app.outdir) + ": \\", file=f)

Check warning on line 55 in docs/depfile.py

View workflow job for this annotation

GitHub Actions / Spell checking

`outdir` is not a recognized word. (unrecognized-spelling)
print(*get_infiles(env), file=f)
for x in get_infiles(env):
print(x + ":", file=f)

def setup(app):
app.add_config_value('depfile', None, 'env')
app.add_config_value('depfile_stamp', None, 'env')
app.connect('build-finished', write_depfile)

return dict(
version = __version__,
parallel_read_safe = True,
parallel_write_safe = True
)
11 changes: 8 additions & 3 deletions pdns/recursordist/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import sys
from pathlib import Path
import guzzle_sphinx_theme
import datetime

Expand All @@ -29,13 +29,15 @@
#
# needs_sphinx = '1.0'

sys.path.append(str(Path('.').resolve()))

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
#extensions = []
#extensions = ['redjack.sphinx.lua', 'sphinxcontrib.httpdomain', 'sphinxjsondomain']
extensions = ['redjack.sphinx.lua', 'sphinxcontrib.httpdomain', 'sphinxjsondomain',
'sphinxcontrib.fulltoc', 'changelog']
'sphinxcontrib.fulltoc', 'changelog', 'depfile']
primary_domain = 'lua'

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -208,3 +210,6 @@

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']

depfile = 'sphinx.deps'
depfile_stamp = 'sphinx.stamp'
1 change: 1 addition & 0 deletions pdns/recursordist/docs/depfile.py
8 changes: 4 additions & 4 deletions pdns/recursordist/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,6 @@ dep_conf_distfile = custom_target(
)

if python.found()
find_rst_files = run_command(['find', docs_dir, '-name', '*.rst'])
rst_files = find_rst_files.stdout().strip().split('\n')

html_docs = custom_target(
'html-docs',
Expand All @@ -752,7 +750,8 @@ if python.found()
],
output: 'html-docs',
console: true,
depend_files: rst_files,
depfile: 'sphinx.deps',
depends: [ metricfiles, recrust ], # for generated .rst files
)

docs_tarball = custom_target(
Expand All @@ -775,7 +774,8 @@ if python.found()
],
output: 'PowerDNS-Recursor.pdf',
console: true,
depend_files: rst_files,
depfile: 'sphinx.deps',
depends: [ metricfiles, recrust ], # for generated .rst files
)

run_target(
Expand Down

0 comments on commit 1314b45

Please sign in to comment.