Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Implement Automatic Activation of Virtual Environment in the dev nox session #3408

Merged
6 changes: 3 additions & 3 deletions docs/source/user_guide/installation/install-from-source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Using Nox (recommended)
.. note::
It is recommended to use ``--verbose`` or ``-v`` to see outputs of all commands run.

This creates a virtual environment ``.nox/dev`` inside the ``PyBaMM/`` directory.
This creates a virtual environment ``venv/`` inside the ``PyBaMM/`` directory.
It comes ready with PyBaMM and some useful development tools like `pre-commit <https://pre-commit.com/>`_ and `ruff <https://beta.ruff.rs/docs/>`_.

You can now activate the environment with
Expand All @@ -125,13 +125,13 @@ You can now activate the environment with

.. code:: bash

source .nox/dev/bin/activate
source venv/bin/activate

.. tab:: Windows

.. code:: bash

.nox\dev\Scripts\activate.bat
venv\Scripts\activate.bat

and run the tests to check your installation.

Expand Down
25 changes: 14 additions & 11 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import nox
import os
import sys
from pathlib import Path


# Options to modify nox behaviour
Expand All @@ -16,6 +17,7 @@
"SUNDIALS_INST": f"{homedir}/.local",
"LD_LIBRARY_PATH": f"{homedir}/.local/lib:",
}
VENV_DIR = Path('./venv').resolve()


def set_environment_variables(env_dict, session):
Expand Down Expand Up @@ -116,18 +118,19 @@ def run_scripts(session):
def set_dev(session):
"""Install PyBaMM in editable mode."""
set_environment_variables(PYBAMM_ENV, session=session)
envbindir = session.bin
session.install("-e", ".[all]", silent=False)
session.install("cmake", silent=False)
if sys.platform == "linux" or sys.platform == "darwin":
session.run(
"echo",
"export",
f"LD_LIBRARY_PATH={PYBAMM_ENV['LD_LIBRARY_PATH']}",
">>",
f"{envbindir}/activate",
external=True, # silence warning about echo being an external command
session.install("virtualenv", "cmake")
session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True)
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
if sys.platform == "linux":
session.run(python,
"-m",
"pip",
"install",
".[all,dev,jax,odes]",
external=True,
)
else:
session.run(python, "-m", "pip", "install", "-e", ".[all,dev]", external=True)


@nox.session(name="tests")
Expand Down
Loading