Skip to content

Commit

Permalink
Merge pull request #1620 from chuckliu1979/develop
Browse files Browse the repository at this point in the history
make sure citations file closed after read
  • Loading branch information
valentinsulzer committed Aug 26, 2021
2 parents ff734d7 + 1e617db commit 01ec443
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ example notebook ([#1602](https://github.com/pybamm-team/PyBaMM/pull/1602))

## Bug fixes

- Fixed reading citation file without closing ([#1620](https://github.com/pybamm-team/PyBaMM/pull/1620))
- Porosity variation for SEI and plating models is calculated from the film thickness rather than from a separate ODE ([#1617](https://github.com/pybamm-team/PyBaMM/pull/1617))
- Fixed a bug where the order of the indexing for the entries of variables discretised using FEM was incorrect ([#1556](https://github.com/pybamm-team/PyBaMM/pull/1556))
- Fix broken module import for spyder when running a script twice ([#1555](https://github.com/pybamm-team/PyBaMM/pull/1555))
Expand Down
39 changes: 20 additions & 19 deletions pybamm/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,26 @@ def read_citations(self):
citation = ""
start = True

for line in open(citations_file):
# if start is true, we need to find the key
if start is True:
# match everything between { and , in the first line to get the key
brace_idx = line.find("{")
comma_idx = line.find(",")
key = line[brace_idx + 1 : comma_idx]
# turn off start as we now have the right key
start = False
citation += line
# blank line means next block, add citation to dictionary and
# reset everything
if line == "\n":
self._all_citations[key] = citation
citation = ""
start = True

# add the final citation
self._all_citations[key] = citation
with open(citations_file) as f:
for line in f:
# if start is true, we need to find the key
if start is True:
# match everything between { and , in the first line to get the key
brace_idx = line.find("{")
comma_idx = line.find(",")
key = line[brace_idx + 1 : comma_idx]
# turn off start as we now have the right key
start = False
citation += line
# blank line means next block, add citation to dictionary and
# reset everything
if line == "\n":
self._all_citations[key] = citation
citation = ""
start = True

# add the final citation
self._all_citations[key] = citation

def register(self, key):
"""Register a paper to be cited. The intended use is that :meth:`register`
Expand Down

0 comments on commit 01ec443

Please sign in to comment.