Skip to content

Commit 18d3bc5

Browse files
Merge pull request pybamm-team#2559 from pybamm-team/main-into-develop
Main into develop
2 parents 0afb069 + 06ae08d commit 18d3bc5

File tree

7 files changed

+46
-36
lines changed

7 files changed

+46
-36
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
- Trying to use a solver to solve multiple models results in a RuntimeError exception ([#2481](https://github.com/pybamm-team/PyBaMM/pull/2481))
1919
- Inputs for the `ElectrodeSOH` solver are now (i) "Q_Li", the total cyclable capacity of lithium in the electrodes (previously "n_Li", the total number of moles, n_Li = 3600/F \* Q_Li) (ii) "Q_n", the capacity of the negative electrode (previously "C_n"), and "Q_p", the capacity of the positive electrode (previously "C_p") ([#2508](https://github.com/pybamm-team/PyBaMM/pull/2508))
2020

21+
# [v22.11.1](https://github.com/pybamm-team/PyBaMM/tree/v22.11.1) - 2022-12-13
22+
23+
## Bug fixes
24+
25+
- Fixed installation on Google Colab (`pybtex` issues) ([#2547](https://github.com/pybamm-team/PyBaMM/pull/2547/files))
26+
2127
# [v22.11](https://github.com/pybamm-team/PyBaMM/tree/v22.11) - 2022-11-30
2228

2329
## Features

CITATION.cff

+1-1
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

+1-1
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

pybamm/citations.py

+33-26
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#
66
import pybamm
77
import os
8-
import sys
98
import warnings
109
import pybtex
1110
from pybtex.database import parse_file, parse_string, Entry
@@ -36,9 +35,14 @@ def __init__(self):
3635
# Dict mapping citations keys to BibTex entries
3736
self._all_citations: dict[str, str] = dict()
3837

39-
if "google.colab" not in sys.modules:
38+
# store citation error
39+
self._citation_err_msg = None
40+
41+
try:
4042
self.read_citations()
4143
self._reset()
44+
except Exception as e: # pragma: no cover
45+
self._citation_err_msg = e
4246

4347
def _reset(self):
4448
"""Reset citations to default only (only for testing purposes)"""
@@ -93,27 +97,27 @@ def register(self, key):
9397
- The citation key for an entry in `pybamm/CITATIONS.txt` or
9498
- One or more BibTex formatted citations
9599
"""
96-
97-
# Check if citation is a known key
98-
if key in self._all_citations:
99-
self._papers_to_cite.add(key)
100-
return
101-
102-
# Try to parse the citation using pybtex
103-
try:
104-
# Parse string as a bibtex citation, and check that a citation was found
105-
bib_data = parse_string(key, bib_format="bibtex")
106-
if not bib_data.entries:
107-
raise PybtexError("no entries found")
108-
109-
# Add and register all citations
110-
for key, entry in bib_data.entries.items():
111-
self._add_citation(key, entry)
112-
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)
113104
return
114-
except PybtexError:
115-
# Unable to parse / unknown key
116-
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}")
117121

118122
def print(self, filename=None, output_format="text"):
119123
"""Print all citations that were used for running simulations.
@@ -145,11 +149,14 @@ def print(self, filename=None, output_format="text"):
145149

146150
def print_citations(filename=None, output_format="text"):
147151
"""See :meth:`Citations.print`"""
148-
if "google.colab" in sys.modules:
149-
raise ImportWarning(
150-
"pybtex does not work with Google Colab due to a known bug -"
151-
"https://bitbucket.org/pybtex-devs/pybtex/issues/148/."
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/. "
152157
"Please manually cite all the references."
158+
"\nError encountered -\n"
159+
f"{citations._citation_err_msg}"
153160
)
154161
else:
155162
pybamm.citations.print(filename, output_format)

pybamm/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "22.11"
1+
__version__ = "22.11.1"

tests/unit/test_citations.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ def test_citations(self):
3939
citations.register("not a citation")
4040

4141
def test_print_citations(self):
42-
import sys
43-
4442
pybamm.citations._reset()
4543

4644
# Text Style
@@ -66,11 +64,10 @@ def test_print_citations(self):
6664
with self.assertRaisesRegex(pybamm.OptionError, "'text' or 'bibtex'"):
6765
pybamm.print_citations("test_citations.txt", "bad format")
6866

69-
# google colab issue - https://github.com/pybamm-team/PyBaMM/issues/2524
70-
sys.modules["google.colab"] = "mock"
71-
with self.assertRaisesRegex(ImportWarning, "pybtex does not work"):
67+
pybamm.citations._citation_err_msg = "Error"
68+
with self.assertRaisesRegex(ImportError, "Error"):
7269
pybamm.print_citations()
73-
sys.modules.pop("google.colab")
70+
pybamm.citations._citation_err_msg = None
7471

7572
def test_overwrite_citation(self):
7673
# Unknown citation

vcpkg.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pybamm",
3-
"version-string": "22.11",
3+
"version-string": "22.11.1",
44
"dependencies": [
55
"casadi",
66
{

0 commit comments

Comments
 (0)