Skip to content

Commit

Permalink
Merge branch 'develop' into pybamm-team#3879-aarch64-broken-docker-im…
Browse files Browse the repository at this point in the history
…ages
  • Loading branch information
arjxn-py committed Mar 18, 2024
2 parents 97c48ac + 39cff38 commit dc7f4c9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 81 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
name: Doctests (ubuntu-latest / Python 3.12)
name: Doctests (ubuntu-latest / Python 3.11)

steps:
- name: Check out PyBaMM repository
Expand All @@ -301,20 +301,20 @@ jobs:
sudo dot -c
sudo apt-get install texlive-latex-extra dvipng
- name: Set up Python 3.12
- name: Set up Python 3.11
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.12
python-version: 3.11
cache: 'pip'

- name: Install nox
run: python -m pip install nox

- name: Install docs dependencies and run doctests for GNU/Linux with Python 3.12
- name: Install docs dependencies and run doctests for GNU/Linux with Python 3.11
run: python -m nox -s doctests

- name: Check if the documentation can be built for GNU/Linux with Python 3.12
- name: Check if the documentation can be built for GNU/Linux with Python 3.11
run: python -m nox -s docs

# Runs only on Ubuntu with Python 3.12
Expand Down
29 changes: 1 addition & 28 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


# Options to modify nox behaviour
nox.options.default_venv_backend = "virtualenv"
nox.options.reuse_existing_virtualenvs = True
if sys.platform != "win32":
nox.options.sessions = ["pre-commit", "pybamm-requires", "unit"]
Expand Down Expand Up @@ -61,10 +62,6 @@ def run_coverage(session):
"""Run the coverage tests and generate an XML report."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("coverage", silent=False)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
if sys.platform != "win32":
if sys.version_info > (3, 12):
session.install("-e", ".[all,dev,jax]", silent=False)
Expand Down Expand Up @@ -93,10 +90,6 @@ def run_coverage(session):
def run_integration(session):
"""Run the integration tests."""
set_environment_variables(PYBAMM_ENV, session=session)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
if sys.platform != "win32":
if sys.version_info > (3, 12):
session.install("-e", ".[all,dev,jax]", silent=False)
Expand All @@ -122,10 +115,6 @@ def run_integration(session):
@nox.session(name="doctests")
def run_doctests(session):
"""Run the doctests and generate the output(s) in the docs/build/ directory."""
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
session.install("-e", ".[all,docs]", silent=False)
session.run("python", "run-tests.py", "--doctest")

Expand All @@ -134,10 +123,6 @@ def run_doctests(session):
def run_unit(session):
"""Run the unit tests."""
set_environment_variables(PYBAMM_ENV, session=session)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
if sys.platform != "win32":
if sys.version_info > (3, 12):
session.install("-e", ".[all,dev,jax]", silent=False)
Expand All @@ -164,10 +149,6 @@ def run_unit(session):
def run_examples(session):
"""Run the examples tests for Jupyter notebooks."""
set_environment_variables(PYBAMM_ENV, session=session)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev]", silent=False)
notebooks_to_test = session.posargs if session.posargs else []
session.run("pytest", "--nbmake", *notebooks_to_test, external=True)
Expand Down Expand Up @@ -253,10 +234,6 @@ def set_dev(session):
def run_tests(session):
"""Run the unit tests and integration tests sequentially."""
set_environment_variables(PYBAMM_ENV, session=session)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
if sys.platform != "win32":
if sys.version_info > (3, 12):
session.install("-e", ".[all,dev,jax]", silent=False)
Expand Down Expand Up @@ -284,10 +261,6 @@ def build_docs(session):
"""Build the documentation and load it in a browser tab, rebuilding on changes."""
envbindir = session.bin
session.install("-e", ".[all,docs]", silent=False)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
session.chdir("docs")
# Local development
if session.interactive:
Expand Down
69 changes: 26 additions & 43 deletions pybamm/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ def __init__(self):
# Dict mapping citation tags for use when registering citations
self._citation_tags = dict()

# store citation error
self._citation_err_msg = None

try:
self.read_citations()
self._reset()
except Exception as e: # pragma: no cover
self._citation_err_msg = e
self.read_citations()
self._reset()

def _reset(self):
"""Reset citations to default only (only for testing purposes)"""
Expand Down Expand Up @@ -122,23 +116,22 @@ def register(self, key):
- The citation key for an entry in `pybamm/CITATIONS.bib` or
- A BibTeX formatted citation
"""
if self._citation_err_msg is None:
# Check if citation is a known key
if key in self._all_citations:
self._papers_to_cite.add(key)
# Add citation tags for the key for verbose output, but
# don't if they already exist in _citation_tags dict
if key not in self._citation_tags:
try:
caller = Citations._caller_name()
self._add_citation_tag(key, entry=caller)
# Don't add citation tags if the citation is registered manually
except KeyError: # pragma: no cover
pass
else:
# If citation is unknown, parse it later with pybtex
self._unknown_citations.add(key)
return
# Check if citation is a known key
if key in self._all_citations:
self._papers_to_cite.add(key)
# Add citation tags for the key for verbose output, but
# don't if they already exist in _citation_tags dict
if key not in self._citation_tags:
try:
caller = Citations._caller_name()
self._add_citation_tag(key, entry=caller)
# Don't add citation tags if the citation is registered manually
except KeyError: # pragma: no cover
pass
else:
# If citation is unknown, parse it later with pybtex
self._unknown_citations.add(key)
return

def _parse_citation(self, key):
"""
Expand Down Expand Up @@ -254,25 +247,15 @@ def print(self, filename=None, output_format="text", verbose=False):

def print_citations(filename=None, output_format="text", verbose=False):
"""See :meth:`Citations.print`"""
if citations._citation_err_msg is not None:
raise ImportError(
f"Citations could not be registered. If you are on Google Colab - "
"pybtex does not work with Google Colab due to a known bug - "
"https://bitbucket.org/pybtex-devs/pybtex/issues/148/. "
"Please manually cite all the references."
"\nError encountered -\n"
f"{citations._citation_err_msg}"
)
else:
if verbose: # pragma: no cover
if filename is not None: # pragma: no cover
raise Exception(
"Verbose output is available only for the terminal and not for printing to files",
)
else:
citations.print(filename, output_format, verbose=True)
if verbose: # pragma: no cover
if filename is not None: # pragma: no cover
raise Exception(
"Verbose output is available only for the terminal and not for printing to files",
)
else:
pybamm.citations.print(filename, output_format)
citations.print(filename, output_format, verbose=True)
else:
pybamm.citations.print(filename, output_format)


citations = Citations()
5 changes: 0 additions & 5 deletions tests/unit/test_citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ def test_print_citations(self):
with self.assertRaisesRegex(pybamm.OptionError, "'text' or 'bibtex'"):
pybamm.print_citations("test_citations.txt", "bad format")

pybamm.citations._citation_err_msg = "Error"
with self.assertRaisesRegex(ImportError, "Error"):
pybamm.print_citations()
pybamm.citations._citation_err_msg = None

# Test that unknown citation raises warning message on printing
pybamm.citations._reset()
pybamm.citations.register("not a citation")
Expand Down

0 comments on commit dc7f4c9

Please sign in to comment.