From bd4037cbfab6c9a46f4e02dd18b01b55edf6a629 Mon Sep 17 00:00:00 2001 From: Akhilender Date: Wed, 4 Oct 2023 23:51:23 +0530 Subject: [PATCH 01/12] fix: Implement Automatic Activation of Virtual Environment in the 'dev' Nox Session - Implement automatic activation of the virtual environment in the 'dev' Nox session - Enhance the 'dev' Nox session defined in `noxfile.py` - Simplify the development setup process for contributors and developers This commit enhances the 'dev' Nox session to automatically activate the virtual environment when running 'nox -s dev'. Signed-off-by: Akhilender --- noxfile.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index c215c73ca5..469dbb60d6 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,6 +1,7 @@ import nox import os import sys +import pathlib # Options to modify nox behaviour @@ -117,7 +118,11 @@ 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) + venv_dir = pathlib.Path('./venv').resolve() + session.install("virtualenv") + session.run("virtualenv", os.fsdecode(venv_dir), silent=True) + python = os.fsdecode(venv_dir.joinpath("bin/python")) + session.run(python, "-m", "pip", "install", "-e", ".[all]", silent=False) session.install("cmake", silent=False) if sys.platform == "linux" or sys.platform == "darwin": session.run( From 42c6c556385db6e14cc9a37928443cd4ca4cf7bb Mon Sep 17 00:00:00 2001 From: Akhilender Date: Thu, 5 Oct 2023 23:55:16 +0530 Subject: [PATCH 02/12] refactor: Improve noxfile.py setup and install [jax,odes] - Imported `Path` directly from `pathlib` for better readability. - Moved the definition of `venv_dir` closer to `PYBAMM_ENV` and marked it as a constant. - Installed development dependencies using `-e .[dev]` to set up the developer environment and silenced the warning with `external=True`. - Added the installation of `[jax,odes]` extras for macOS and Linux platforms. Signed-off-by: Akhilender --- noxfile.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 469dbb60d6..ccbbc0d749 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,7 +1,7 @@ import nox import os import sys -import pathlib +from pathlib import Path # Options to modify nox behaviour @@ -17,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): @@ -118,12 +119,14 @@ def set_dev(session): """Install PyBaMM in editable mode.""" set_environment_variables(PYBAMM_ENV, session=session) envbindir = session.bin - venv_dir = pathlib.Path('./venv').resolve() session.install("virtualenv") - session.run("virtualenv", os.fsdecode(venv_dir), silent=True) - python = os.fsdecode(venv_dir.joinpath("bin/python")) + session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True) + python = os.fsdecode(VENV_DIR.joinpath("bin/python")) session.run(python, "-m", "pip", "install", "-e", ".[all]", silent=False) session.install("cmake", silent=False) + session.install("-e", ".[dev]", external=True) + if session.platform.startswith("macos") or session.platform.startswith("linux"): + session.run(python, "-m", "pip", "install", ".[jax,odes]", silent=False) if sys.platform == "linux" or sys.platform == "darwin": session.run( "echo", From 713da15376285851f11a89afb4ec33664bd80b3a Mon Sep 17 00:00:00 2001 From: Akhilender Date: Fri, 6 Oct 2023 15:20:58 +0530 Subject: [PATCH 03/12] refactor: Improve noxfile.py - Installed `virtualenv` and `cmake` before other dependencies. - Installed all and dev dependencies together using a single `pip` command to avoid redundant wheel building. - Corrected sys.platform to maintain consistency in the code Signed-off-by: Akhilender --- noxfile.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/noxfile.py b/noxfile.py index ccbbc0d749..df00bfadc2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -118,24 +118,13 @@ 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("virtualenv") + session.install("virtualenv","cmake") session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True) python = os.fsdecode(VENV_DIR.joinpath("bin/python")) - session.run(python, "-m", "pip", "install", "-e", ".[all]", silent=False) - session.install("cmake", silent=False) - session.install("-e", ".[dev]", external=True) - if session.platform.startswith("macos") or session.platform.startswith("linux"): + session.run(python, "-m", "pip", "install", "-e", ".[all,dev]", silent=False) + if sys.platform == "linux" or sys.platform == "macos": session.run(python, "-m", "pip", "install", ".[jax,odes]", 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 - ) + @nox.session(name="tests") From eae0bbb3bbcd974a1505404a1023b686d8f5b1ad Mon Sep 17 00:00:00 2001 From: Akhilender Bongirwar <112749383+akhilender-bongirwar@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:16:03 +0530 Subject: [PATCH 04/12] fix: Resolved indentaions - Corrected the space between virtualenv and cmake - Changed macos to darwin --- noxfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index df00bfadc2..736c5be6c2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -118,11 +118,11 @@ def run_scripts(session): def set_dev(session): """Install PyBaMM in editable mode.""" set_environment_variables(PYBAMM_ENV, session=session) - session.install("virtualenv","cmake") + session.install("virtualenv", "cmake") session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True) python = os.fsdecode(VENV_DIR.joinpath("bin/python")) session.run(python, "-m", "pip", "install", "-e", ".[all,dev]", silent=False) - if sys.platform == "linux" or sys.platform == "macos": + if sys.platform == "linux" or sys.platform == "darwin": session.run(python, "-m", "pip", "install", ".[jax,odes]", silent=False) From 570b96f7315ceb3ded9f3595c03ec8e2c996bc8d Mon Sep 17 00:00:00 2001 From: Akhilender Bongirwar <112749383+akhilender-bongirwar@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:21:52 +0530 Subject: [PATCH 05/12] Updated install-from-source.rst - Updated the docs regarding the virtual environment --- docs/source/user_guide/installation/install-from-source.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/user_guide/installation/install-from-source.rst b/docs/source/user_guide/installation/install-from-source.rst index 0aa50cf8a8..fb448950bf 100644 --- a/docs/source/user_guide/installation/install-from-source.rst +++ b/docs/source/user_guide/installation/install-from-source.rst @@ -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 `_ and `ruff `_. You can now activate the environment with @@ -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. From 94753958dd97888bc964e8b9d4d1066cfa098bd5 Mon Sep 17 00:00:00 2001 From: Akhilender Bongirwar <112749383+akhilender-bongirwar@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:27:54 +0530 Subject: [PATCH 06/12] fix: Changed few minor instances - Added external = True instead of silent = False as it is not required for session.run() --- noxfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index 736c5be6c2..9d13656894 100644 --- a/noxfile.py +++ b/noxfile.py @@ -121,9 +121,9 @@ def set_dev(session): session.install("virtualenv", "cmake") session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True) python = os.fsdecode(VENV_DIR.joinpath("bin/python")) - session.run(python, "-m", "pip", "install", "-e", ".[all,dev]", silent=False) + session.run(python, "-m", "pip", "install", "-e", ".[all,dev]", external=True) if sys.platform == "linux" or sys.platform == "darwin": - session.run(python, "-m", "pip", "install", ".[jax,odes]", silent=False) + session.run(python, "-m", "pip", "install", ".[jax,odes]", external=True) From eeb08564e4303a5289ec17edf96ebe945f7c971b Mon Sep 17 00:00:00 2001 From: Akhilender Bongirwar <112749383+akhilender-bongirwar@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:54:50 +0530 Subject: [PATCH 07/12] Updated noxfile.py - Removed redundant code Co-authored-by: Saransh Chopra --- noxfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 9d13656894..b9cc6366e2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -121,7 +121,6 @@ def set_dev(session): session.install("virtualenv", "cmake") session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True) python = os.fsdecode(VENV_DIR.joinpath("bin/python")) - session.run(python, "-m", "pip", "install", "-e", ".[all,dev]", external=True) if sys.platform == "linux" or sys.platform == "darwin": session.run(python, "-m", "pip", "install", ".[jax,odes]", external=True) From 3cdc937b6f02e9a117e9c8c729e89020ea8a645b Mon Sep 17 00:00:00 2001 From: Akhilender Bongirwar <112749383+akhilender-bongirwar@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:55:39 +0530 Subject: [PATCH 08/12] Updated noxfile.py - Added all the installation in a single line Co-authored-by: Saransh Chopra --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index b9cc6366e2..e338ecf7cf 100644 --- a/noxfile.py +++ b/noxfile.py @@ -122,7 +122,7 @@ def set_dev(session): session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True) python = os.fsdecode(VENV_DIR.joinpath("bin/python")) if sys.platform == "linux" or sys.platform == "darwin": - session.run(python, "-m", "pip", "install", ".[jax,odes]", external=True) + session.run(python, "-m", "pip", "install", ".[all,dev,jax,odes]", external=True) From 94e3fdc3f05a4c53ef225533efdbdfd1d48fe7f5 Mon Sep 17 00:00:00 2001 From: Akhilender Bongirwar <112749383+akhilender-bongirwar@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:56:25 +0530 Subject: [PATCH 09/12] Updated noxfile.py - Added else block for efficient running of the code Co-authored-by: Saransh Chopra --- noxfile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index e338ecf7cf..262af5892a 100644 --- a/noxfile.py +++ b/noxfile.py @@ -123,7 +123,8 @@ def set_dev(session): python = os.fsdecode(VENV_DIR.joinpath("bin/python")) if sys.platform == "linux" or sys.platform == "darwin": 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") From e8610dd3acabaed3185643a9424be9181c647146 Mon Sep 17 00:00:00 2001 From: Akhilender Bongirwar <112749383+akhilender-bongirwar@users.noreply.github.com> Date: Thu, 12 Oct 2023 00:30:57 +0530 Subject: [PATCH 10/12] Update noxfile.py - Altered and removed the darwin platform --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 262af5892a..3f14381886 100644 --- a/noxfile.py +++ b/noxfile.py @@ -121,7 +121,7 @@ def set_dev(session): 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" or sys.platform == "darwin": + 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) From f7e59ad0bcc8c2feebd409eb88d7f92f5746576d Mon Sep 17 00:00:00 2001 From: Akhilender Bongirwar <112749383+akhilender-bongirwar@users.noreply.github.com> Date: Fri, 13 Oct 2023 12:00:29 +0530 Subject: [PATCH 11/12] Updated styles - Made a single line of 89 characters into few smaller lines --- noxfile.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 3f14381886..615da67ef4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -122,7 +122,13 @@ def set_dev(session): 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) + session.run(python, + "-m", + "pip", + "install", + ".[all,dev,jax,odes]", + external=True, + ) else: session.run(python, "-m", "pip", "install", "-e", ".[all,dev]", external=True) From 762941481d96a74bd0807633dc3fafb10ee673ff Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Oct 2023 06:30:42 +0000 Subject: [PATCH 12/12] style: pre-commit fixes --- noxfile.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/noxfile.py b/noxfile.py index 615da67ef4..430ad59659 100644 --- a/noxfile.py +++ b/noxfile.py @@ -122,11 +122,11 @@ def set_dev(session): 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]", + session.run(python, + "-m", + "pip", + "install", + ".[all,dev,jax,odes]", external=True, ) else: