Use write_file_if_changed() in changelog.py

Speeds up incremental builds significantly
develop
lethosor 2022-08-04 02:07:52 -04:00
parent 89a88e94a9
commit e47c681e9c
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
3 changed files with 26 additions and 23 deletions

@ -14,9 +14,7 @@ serve to show the default.
# pylint:disable=redefined-builtin
import contextlib
import datetime
import io
import os
import re
import shlex # pylint:disable=unused-import
@ -46,6 +44,10 @@ if os.environ.get('DFHACK_DOCS_BUILD_OFFLINE'):
from docutils import nodes
from docutils.parsers.rst import roles
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'docs', 'sphinx_extensions'))
from dfhack.util import write_file_if_changed
def get_keybinds(root, files, keybindings):
"""Add keybindings in the specified files to the
given keybindings dict.
@ -145,23 +147,6 @@ def get_tags():
return tags
@contextlib.contextmanager
def write_file_if_changed(path):
with io.StringIO() as buffer:
yield buffer
new_contents = buffer.getvalue()
try:
with open(path, 'r') as infile:
old_contents = infile.read()
except IOError:
old_contents = None
if old_contents != new_contents:
with open(path, 'w') as outfile:
outfile.write(new_contents)
def generate_tag_indices():
os.makedirs('docs/tags', mode=0o755, exist_ok=True)
with write_file_if_changed('docs/tags/index.rst') as topidx:
@ -225,8 +210,6 @@ generate_tag_indices()
# -- General configuration ------------------------------------------------
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'docs', 'sphinx_extensions'))
# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = '1.8'

@ -6,7 +6,7 @@ import sys
from sphinx.errors import ExtensionError, SphinxError, SphinxWarning
from dfhack.util import DFHACK_ROOT, DOCS_ROOT
from dfhack.util import DFHACK_ROOT, DOCS_ROOT, write_file_if_changed
CHANGELOG_PATHS = (
'docs/changelog.txt',
@ -172,7 +172,7 @@ def consolidate_changelog(all_entries):
def print_changelog(versions, all_entries, path, replace=True, prefix=''):
# all_entries: version -> section -> entry
with open(path, 'w') as f:
with write_file_if_changed(path) as f:
def write(line):
if replace:
line = replace_text(line, REPLACEMENTS)

@ -1,3 +1,5 @@
import contextlib
import io
import os
DFHACK_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
@ -6,6 +8,24 @@ DOCS_ROOT = os.path.join(DFHACK_ROOT, 'docs')
if not os.path.isdir(DOCS_ROOT):
raise ReferenceError('docs root not found: %s' % DOCS_ROOT)
@contextlib.contextmanager
def write_file_if_changed(path):
with io.StringIO() as buffer:
yield buffer
new_contents = buffer.getvalue()
try:
with open(path, 'r') as infile:
old_contents = infile.read()
except IOError:
old_contents = None
if old_contents != new_contents:
with open(path, 'w') as outfile:
outfile.write(new_contents)
# directive argument helpers (supplementing docutils.parsers.rst.directives)
def directive_arg_str_list(argument):
"""