Skip to content

Commit 8ea3c05

Browse files
committed
ENH: remove all prior existing citation files first
- makes it friendly to the cases where all output is under git-annex. .write_text() just opens a file in "w" mode so it would fail on annex protected file. - if previous run did succeed generating e.g. .html file, if subsequent run fails, updated version of .html would not be generated and provided CITATION files could get out of sync. Removing all CITATION* files prior generation resolves both of the issues.
1 parent 07ee316 commit 8ea3c05

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

fmriprep/cli/run.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,18 @@ def build_workflow(opts, retval):
786786
boilerplate = retval['workflow'].visit_desc()
787787

788788
if boilerplate:
789-
(logs_path / 'CITATION.md').write_text(boilerplate)
789+
# To please git-annex users and also to guarantee consistency
790+
# among different renderings of the same file, first remove any
791+
# existing one
792+
citation_files = {
793+
ext: str(logs_path / 'CITATION.' + ext)
794+
for ext in ('bib', 'tex', 'md', 'html')
795+
}
796+
for citation_file in citation_files.values():
797+
if op.lexists(citation_file):
798+
citation_file.unlink()
799+
800+
Path(citation_files['md']).write_text(boilerplate)
790801
logger.log(25, 'Works derived from this fMRIPrep execution should '
791802
'include the following boilerplate:\n\n%s', boilerplate)
792803

@@ -795,8 +806,8 @@ def build_workflow(opts, retval):
795806
pkgrf('fmriprep', 'data/boilerplate.bib'),
796807
'--filter', 'pandoc-citeproc',
797808
'--metadata', 'pagetitle="fMRIPrep citation boilerplate"',
798-
str(logs_path / 'CITATION.md'),
799-
'-o', str(logs_path / 'CITATION.html')]
809+
citation_files['md'],
810+
'-o', citation_files['html']]
800811
try:
801812
check_call(cmd, timeout=10)
802813
except (FileNotFoundError, CalledProcessError, TimeoutExpired):
@@ -806,16 +817,16 @@ def build_workflow(opts, retval):
806817
# Generate LaTex file resolving citations
807818
cmd = ['pandoc', '-s', '--bibliography',
808819
pkgrf('fmriprep', 'data/boilerplate.bib'),
809-
'--natbib', str(logs_path / 'CITATION.md'),
810-
'-o', str(logs_path / 'CITATION.tex')]
820+
'--natbib', citation_files['md'],
821+
'-o', citation_files['tex']]
811822
try:
812823
check_call(cmd, timeout=10)
813824
except (FileNotFoundError, CalledProcessError, TimeoutExpired):
814825
logger.warning('Could not generate CITATION.tex file:\n%s',
815826
' '.join(cmd))
816827
else:
817828
copyfile(pkgrf('fmriprep', 'data/boilerplate.bib'),
818-
(logs_path / 'CITATION.bib'))
829+
citation_files['bib'])
819830

820831
return retval
821832

0 commit comments

Comments
 (0)