Skip to content

Commit 08db559

Browse files
Merge pull request #2547 from Saransh-cpp/fix-colab-again
Fix citations on Colab + bump v22.11.1
2 parents efd426c + 070d62d commit 08db559

File tree

11 files changed

+59
-32
lines changed

11 files changed

+59
-32
lines changed

.github/workflows/periodic_benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
with:
2626
python-version: 3.8
2727
- name: Install tox and asv
28-
run: pip install -U pip tox asv
28+
run: pip install -U pip "tox<4" asv
2929
- name: Run benchmarks
3030
run: |
3131
asv machine --machine "GitHubRunner"

.github/workflows/run_benchmarks_over_history.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
with:
2929
python-version: 3.8
3030
- name: Install tox and asv
31-
run: pip install -U pip tox asv
31+
run: pip install -U pip "tox<4" asv
3232
- name: Fetch develop branch
3333
# Not required when worklow trigerred
3434
# on develop, but useful when

.github/workflows/test_on_push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636

3737
- name: Check style
3838
run: |
39-
python -m pip install tox
39+
python -m pip install "tox<4"
4040
tox -e flake8
4141
4242
build:
@@ -80,7 +80,7 @@ jobs:
8080
- name: Install standard python dependencies
8181
run: |
8282
python -m pip install --upgrade pip wheel setuptools
83-
python -m pip install tox
83+
python -m pip install "tox<4"
8484
8585
- name: Install SuiteSparse and Sundials
8686
if: matrix.os == 'ubuntu-latest'

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)
22

3+
# [v22.11.1](https://github.com/pybamm-team/PyBaMM/tree/v22.11.1) - 2022-12-13
4+
5+
## Bug fixes
6+
7+
- Fixed installation on Google Colab (`pybtex` issues) ([#2547](https://github.com/pybamm-team/PyBaMM/pull/2547/files))
8+
39
# [v22.11](https://github.com/pybamm-team/PyBaMM/tree/v22.11) - 2022-11-30
410

511
## Features

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ keywords:
2424
- "expression tree"
2525
- "python"
2626
- "symbolic differentiation"
27-
version: "22.11"
27+
version: "22.11.1"
2828
repository-code: "https://github.com/pybamm-team/PyBaMM"
2929
title: "Python Battery Mathematical Modelling (PyBaMM)"

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
author = "The PyBaMM Team"
2828

2929
# The short X.Y version
30-
version = "22.11"
30+
version = "22.11.1"
3131
# The full version, including alpha/beta/rc tags
3232
release = version
3333

docs/install/install-from-source.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ You can install it with
5050

5151
.. code:: bash
5252
53-
python3.X -m pip install --user tox
53+
python3.X -m pip install --user "tox<4"
5454
5555
Depending on your operating system, you may or may not have ``pip`` installed along python.
5656
If ``pip`` is not found, you probably want to install the ``python3-pip`` package.

pybamm/citations.py

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ def __init__(self):
3535
# Dict mapping citations keys to BibTex entries
3636
self._all_citations: dict[str, str] = dict()
3737

38-
self.read_citations()
39-
self._reset()
38+
# store citation error
39+
self._citation_err_msg = None
40+
41+
try:
42+
self.read_citations()
43+
self._reset()
44+
except Exception as e: # pragma: no cover
45+
self._citation_err_msg = e
4046

4147
def _reset(self):
4248
"""Reset citations to default only (only for testing purposes)"""
@@ -91,27 +97,27 @@ def register(self, key):
9197
- The citation key for an entry in `pybamm/CITATIONS.txt` or
9298
- One or more BibTex formatted citations
9399
"""
94-
95-
# Check if citation is a known key
96-
if key in self._all_citations:
97-
self._papers_to_cite.add(key)
98-
return
99-
100-
# Try to parse the citation using pybtex
101-
try:
102-
# Parse string as a bibtex citation, and check that a citation was found
103-
bib_data = parse_string(key, bib_format="bibtex")
104-
if not bib_data.entries:
105-
raise PybtexError("no entries found")
106-
107-
# Add and register all citations
108-
for key, entry in bib_data.entries.items():
109-
self._add_citation(key, entry)
110-
self.register(key)
100+
if self._citation_err_msg is None:
101+
# Check if citation is a known key
102+
if key in self._all_citations:
103+
self._papers_to_cite.add(key)
111104
return
112-
except PybtexError:
113-
# Unable to parse / unknown key
114-
raise KeyError(f"Not a bibtex citation or known citation: {key}")
105+
106+
# Try to parse the citation using pybtex
107+
try:
108+
# Parse string as a bibtex citation, and check that a citation was found
109+
bib_data = parse_string(key, bib_format="bibtex")
110+
if not bib_data.entries:
111+
raise PybtexError("no entries found")
112+
113+
# Add and register all citations
114+
for key, entry in bib_data.entries.items():
115+
self._add_citation(key, entry)
116+
self.register(key)
117+
return
118+
except PybtexError:
119+
# Unable to parse / unknown key
120+
raise KeyError(f"Not a bibtex citation or known citation: {key}")
115121

116122
def print(self, filename=None, output_format="text"):
117123
"""Print all citations that were used for running simulations.
@@ -143,7 +149,17 @@ def print(self, filename=None, output_format="text"):
143149

144150
def print_citations(filename=None, output_format="text"):
145151
"""See :meth:`Citations.print`"""
146-
pybamm.citations.print(filename, output_format)
152+
if citations._citation_err_msg is not None:
153+
raise ImportError(
154+
f"Citations could not be registered. If you are on Google Colab - "
155+
"pybtex does not work with Google Colab due to a known bug - "
156+
"https://bitbucket.org/pybtex-devs/pybtex/issues/148/. "
157+
"Please manually cite all the references."
158+
"\nError encountered -\n"
159+
f"{citations._citation_err_msg}"
160+
)
161+
else:
162+
pybamm.citations.print(filename, output_format)
147163

148164

149165
citations = Citations()

pybamm/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "22.11"
1+
__version__ = "22.11.1"

tests/unit/test_citations.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ def test_print_citations(self):
6464
with self.assertRaisesRegex(pybamm.OptionError, "'text' or 'bibtex'"):
6565
pybamm.print_citations("test_citations.txt", "bad format")
6666

67+
pybamm.citations._citation_err_msg = "Error"
68+
with self.assertRaisesRegex(ImportError, "Error"):
69+
pybamm.print_citations()
70+
pybamm.citations._citation_err_msg = None
71+
6772
def test_overwrite_citation(self):
6873
# Unknown citation
6974
fake_citation = r"@article{NotACitation, title = {This Doesn't Exist}}"

0 commit comments

Comments
 (0)