Skip to content

Commit

Permalink
Merge pull request #3408 from akhilender-bongirwar/enhancement/activa…
Browse files Browse the repository at this point in the history
…te-venv-dev-nox

fix: Implement Automatic Activation of Virtual Environment in the dev nox session
  • Loading branch information
Saransh-cpp authored Oct 18, 2023
2 parents 0a0117f + 7629414 commit ff8c998
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
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

0 comments on commit ff8c998

Please sign in to comment.