From 39cff38cc7c424285761101c3e046e0d04af5dff Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+prady0t@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:05:45 +0530 Subject: [PATCH] Removed Google colab error warning. (#3886) * Removed Google colab error warning Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> * removed temp fixes Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> * removed redundant code Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> * run CI om python 3.11 Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --------- Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Co-authored-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Co-authored-by: Eric G. Kratz --- .github/workflows/test_on_push.yml | 10 ++--- noxfile.py | 29 +------------ pybamm/citations.py | 69 +++++++++++------------------- tests/unit/test_citations.py | 5 --- 4 files changed, 32 insertions(+), 81 deletions(-) diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index 7a3a60fac4..8b5cdb2057 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -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 @@ -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 diff --git a/noxfile.py b/noxfile.py index 4e6f1df01b..19a1d5bd1c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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"] @@ -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) @@ -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) @@ -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") @@ -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) @@ -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) @@ -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) @@ -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: diff --git a/pybamm/citations.py b/pybamm/citations.py index 886437e6c2..ff1851bfaa 100644 --- a/pybamm/citations.py +++ b/pybamm/citations.py @@ -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)""" @@ -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): """ @@ -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() diff --git a/tests/unit/test_citations.py b/tests/unit/test_citations.py index d8c1de3718..61c93d3efe 100644 --- a/tests/unit/test_citations.py +++ b/tests/unit/test_citations.py @@ -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")