Skip to content

Commit 99c4c13

Browse files
authored
Merge pull request #76 from templateflow/fix/doi2bib
FIX: Drop ``doi2bib`` and query doi.org directly
2 parents 22869f4 + a2c05a0 commit 99c4c13

File tree

4 files changed

+59
-59
lines changed

4 files changed

+59
-59
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
source /tmp/venv/bin/activate
4646
pip install -U pip
4747
pip install -r /tmp/src/templateflow/requirements.txt
48-
pip install "datalad ~= 0.11.8" "doi2bib < 0.4"
48+
pip install "datalad ~= 0.11.8"
4949
pip install "setuptools>=45" "setuptools_scm >= 6.2" twine codecov
5050
5151
- run:

setup.cfg

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ exclude =
5353
*.tests.*
5454

5555
[options.extras_require]
56-
citations =
57-
doi2bib < 0.4.0
5856
datalad =
5957
datalad ~= 0.12.0
6058
doc =

templateflow/api.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,21 @@ def _s3_get(filepath):
238238

239239

240240
def _to_bibtex(doi, template, idx):
241-
try:
242-
from doi2bib.crossref import get_bib_from_doi
243-
except ImportError:
241+
if "doi.org" not in doi:
242+
return doi
243+
244+
# Is a DOI URL
245+
import requests
246+
247+
response = requests.post(
248+
doi,
249+
headers={"Accept": "application/x-bibtex; charset=utf-8"}
250+
)
251+
if not response.ok:
244252
print(
245-
"Cannot generate BibTeX citation, missing doi2bib dependency",
253+
f"Failed to convert DOI <{doi}> to bibtex, returning URL.",
246254
file=sys.stderr,
247255
)
248256
return doi
249257

250-
if "doi.org" not in doi:
251-
return doi
252-
bib = get_bib_from_doi(doi)[1]
253-
# replace identifier with template name
254-
m = re.search(r"([A-Z])\w+", bib)
255-
return bib.replace(m.group(), "%s%s" % (template.lower(), idx))
258+
return response.text

templateflow/tests/test_api.py

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Test citations."""
12
import pytest
23

34
from .. import api
@@ -11,57 +12,54 @@
1112
"https://doi.org/10.1007/3-540-48714-X_16",
1213
]
1314

14-
mni2009_fbib = (
15-
"@article{mni152nlin2009casym1,\n"
16-
"\tdoi = {10.1016/j.neuroimage.2010.07.033},\n"
17-
"\turl = {https://doi.org/10.1016%2Fj.neuroimage.2010.07.033},\n"
18-
"\tyear = 2011,\n"
19-
"\tmonth = {jan},\n"
20-
"\tpublisher = {Elsevier {BV}},\n"
21-
"\tvolume = {54},\n"
22-
"\tnumber = {1},\n"
23-
"\tpages = {313--327},\n"
24-
"\tauthor = {Vladimir Fonov and Alan C. Evans and Kelly Botteron and C. "
25-
"Robert Almli and Robert C. McKinstry and D. Louis Collins},\n"
26-
"\ttitle = {Unbiased average age-appropriate atlases for pediatric studies},\n"
27-
"\tjournal = {{NeuroImage}}\n}"
28-
)
15+
mni2009_fbib = """\
16+
@article{Fonov_2011,
17+
\tdoi = {10.1016/j.neuroimage.2010.07.033},
18+
\turl = {https://doi.org/10.1016%2Fj.neuroimage.2010.07.033},
19+
\tyear = 2011,
20+
\tmonth = {jan},
21+
\tpublisher = {Elsevier {BV}},
22+
\tvolume = {54},
23+
\tnumber = {1},
24+
\tpages = {313--327},
25+
\tauthor = {Vladimir Fonov and Alan C. Evans and Kelly Botteron and C. Robert \
26+
Almli and Robert C. McKinstry and D. Louis Collins},
27+
\ttitle = {Unbiased average age-appropriate atlases for pediatric studies},
28+
\tjournal = {{NeuroImage}}
29+
}"""
2930

30-
mni2009_lbib = (
31-
"@incollection{mni152nlin2009casym4,\n"
32-
"\tdoi = {10.1007/3-540-48714-x_16},\n"
33-
"\turl = {https://doi.org/10.1007%2F3-540-48714-x_16},\n"
34-
"\tyear = 1999,\n"
35-
"\tpublisher = {Springer Berlin Heidelberg},\n"
36-
"\tpages = {210--223},\n"
37-
"\tauthor = {D. Louis Collins and Alex P. Zijdenbos and Wim F. C. "
38-
"Baar{\\'{e}} and Alan C. Evans},\n"
39-
"\ttitle = {{ANIMAL}$\\mathplus${INSECT}: Improved Cortical Structure "
40-
"Segmentation},\n"
41-
"\tbooktitle = {Lecture Notes in Computer Science}\n}"
42-
)
31+
mni2009_lbib = """\
32+
@incollection{Collins_1999,
33+
\tdoi = {10.1007/3-540-48714-x_16},
34+
\turl = {https://doi.org/10.1007%2F3-540-48714-x_16},
35+
\tyear = 1999,
36+
\tpublisher = {Springer Berlin Heidelberg},
37+
\tpages = {210--223},
38+
\tauthor = {D. Louis Collins and Alex P. Zijdenbos and Wim F. C. Baar{\\'{e}} and Alan C. Evans},
39+
\ttitle = {{ANIMAL}$\\mathplus${INSECT}: Improved Cortical Structure Segmentation},
40+
\tbooktitle = {Lecture Notes in Computer Science}
41+
}"""
4342

4443
fslr_urls = [
4544
"https://doi.org/10.1093/cercor/bhr291",
4645
"https://github.com/Washington-University/HCPpipelines/tree/master/global/templates",
4746
]
4847

49-
fslr_fbib = (
50-
"@article{fslr1,\n"
51-
"\tdoi = {10.1093/cercor/bhr291},\n"
52-
"\turl = {https://doi.org/10.1093%2Fcercor%2Fbhr291},\n"
53-
"\tyear = 2011,\n"
54-
"\tmonth = {nov},\n"
55-
"\tpublisher = {Oxford University Press ({OUP})},\n"
56-
"\tvolume = {22},\n"
57-
"\tnumber = {10},\n"
58-
"\tpages = {2241--2262},\n"
59-
"\tauthor = {D. C. Van Essen and M. F. Glasser and D. L. Dierker and J. "
60-
"Harwell and T. Coalson},\n"
61-
"\ttitle = {Parcellations and Hemispheric Asymmetries of Human Cerebral "
62-
"Cortex Analyzed on Surface-Based Atlases},\n"
63-
"\tjournal = {Cerebral Cortex}\n}"
64-
)
48+
fslr_fbib = """\
49+
@article{Van_Essen_2011,
50+
\tdoi = {10.1093/cercor/bhr291},
51+
\turl = {https://doi.org/10.1093%2Fcercor%2Fbhr291},
52+
\tyear = 2011,
53+
\tmonth = {nov},
54+
\tpublisher = {Oxford University Press ({OUP})},
55+
\tvolume = {22},
56+
\tnumber = {10},
57+
\tpages = {2241--2262},
58+
\tauthor = {D. C. Van Essen and M. F. Glasser and D. L. Dierker and J. Harwell and T. Coalson},
59+
\ttitle = {Parcellations and Hemispheric Asymmetries of Human Cerebral Cortex Analyzed on \
60+
Surface-Based Atlases},
61+
\tjournal = {Cerebral Cortex}
62+
}"""
6563

6664
fslr_lbib = (
6765
"https://github.com/Washington-University/HCPpipelines/tree/master/global/templates"
@@ -77,11 +75,12 @@
7775
],
7876
)
7977
def test_citations(tmp_path, template, urls, fbib, lbib):
78+
"""Check the correct composition of citations."""
8079
assert api.get_citations(template) == urls
8180
bibs = api.get_citations(template, bibtex=True)
8281
if bibs:
83-
assert bibs[0] == fbib
84-
assert bibs[-1] == lbib
82+
assert "".join(bibs[0]) == fbib
83+
assert "".join(bibs[-1]) == lbib
8584
else:
8685
# no citations currently
8786
assert template == "fsaverage"

0 commit comments

Comments
 (0)