From 754d22bcb564b0dab6ff506a3eec86f3219b0764 Mon Sep 17 00:00:00 2001 From: Tue Herlau <tuhe@dtu.dk> Date: Tue, 29 Apr 2025 14:19:24 +0200 Subject: [PATCH] Minor fixes --- src/snipper/snipper_main.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/snipper/snipper_main.py b/src/snipper/snipper_main.py index 1ee137c..091a227 100644 --- a/src/snipper/snipper_main.py +++ b/src/snipper/snipper_main.py @@ -7,6 +7,7 @@ from snipper.fix_s import save_s from snipper.fix_cite import fix_citations from snipper.fix_bf import fix_f, fix_b from snipper.fix_o import run_o +from sphinx.ext.autodoc.preserve_defaults import update_defvalue def rem_nonprintable_ctrl_chars(txt): @@ -46,10 +47,15 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True, strict=True, references=None, license_head=None, - package_base_dir=None): + package_base_dir=None, + update_file=True # Update the file 'file' (i.e., write to it). + ): if str(file).endswith("rst"): assert not run_files and not cut_files and not censor_files + if censor_files: + assert update_file, "update_file must be true when censor_files is true (otherwise the file will not be censored!)" + if str(file).endswith(".md"): license_head=None @@ -108,8 +114,9 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True, if license_head is not None: s2 = fix_copyright(s2, license_head) - with open(file, 'w', encoding='utf-8') as f: - f.write(s2) + if update_file: + with open(file, 'w', encoding='utf-8') as f: + f.write(s2) return nB, cut -- GitLab