diff --git a/src/snipper/snipper_main.py b/src/snipper/snipper_main.py index 1ee137cf8577d7ffb7adfdc0e4ad95e7fb13012e..091a2272f943b6409f6e3b6192fbd7c4b7f1a452 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