Skip to content

Commit

Permalink
Set up virtual environment for cluster users
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Mar 4, 2024
1 parent 9dae0b5 commit df5c64b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ jobs:
- name: Install dependencies
run: |
module load ESPResSo/4.2.1-foss-2023a
python3 -m pip install --user -r requirements.txt
python3 -m venv --system-site-packages pymbe
source pymbe/bin/activate
python3 maintainer/configure_venv.py
python3 -m pip install -r requirements.txt
deactivate
- name: Run testsuite
run: |
module load ESPResSo/4.2.1-foss-2023a
export OLD_PYTHONPATH="${PYTHONPATH}"
export PYTHONPATH="$(realpath .)${PYTHONPATH:+:$PYTHONPATH}"
source pymbe/bin/activate
make testsuite
export PYTHONPATH="${OLD_PYTHONPATH}"
deactivate
shell: bash
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,30 @@ the path to the ESPResSo build folder:
```sh
python3 -m venv pymbe
source pymbe/bin/activate
python3 maintainer/configure_venv.py /home/user/Documents/espresso/build # adapt this
python3 maintainer/configure_venv.py --espresso_path=~/espresso/build # adapt path
python3 -m pip install -r requirements.txt
deactivate
```

We highlight that the path `/home/user/Documents/espresso/build` is just an example of a possible absolute path to the ESPResSo build folder. The user should change this path to match the local path were ESPResSo was installed.
We highlight that the path `~/espresso/build` is just an example of a possible
path to the ESPResSo build folder. The user should change this path to match
the local path were ESPResSo was installed.

Cluster users who rely on module files to load dependencies should opt for the
following alternative:

```sh
module load ESPResSo/4.2.1-foss-2022a # adapt module name
python3 -m venv --system-site-packages pymbe
source pymbe/bin/activate
python3 maintainer/configure_venv.py
python3 -m pip install -r requirements.txt
deactivate
module purge
```

We highlight that the module files need to be loaded before every activation
of the virtual environment.

Now you can use pyMBE and ESPResSo by activating the virtual environment:

Expand Down
11 changes: 9 additions & 2 deletions maintainer/configure_venv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import os
import argparse
import sysconfig
try:
import espressomd
espressomd_found = True
except ModuleNotFoundError:
espressomd_found = False


def make_pth(name, path):
Expand All @@ -12,11 +17,13 @@ def make_pth(name, path):


parser = argparse.ArgumentParser(description="Configure pyBME and ESPResSo module paths")
parser.add_argument("espresso_build_path", type=str, help="Path to the ESPResSo build folder")
parser.add_argument("--espresso_path", type=str, required=not espressomd_found,
help="Path to the ESPResSo build folder")
args = parser.parse_args()

if not os.environ.get("VIRTUAL_ENV"):
raise RuntimeError("This script should be run in a virtual environment")

if not espressomd_found:
make_pth("espresso", os.path.join(args.espresso_path, "src", "python"))
make_pth("pymbe", os.path.dirname(os.path.dirname(__file__)))
make_pth("espresso", os.path.join(args.espresso_build_path, "src", "python"))

0 comments on commit df5c64b

Please sign in to comment.