To make things clearer for this email I'll use "Python-module" to refer to a Python script defining functions/classes that you `import` in Python code and "environment-module" to refer to a TCL environment module that you `module load`/`module unload`/etc.
I was looking at how to use environment-modules within a Python script and found that the current documentation for Python (https://modules.readthedocs.io/en/latest/module.html#examples-of-initialization) has
```
import os
exec(open("/usr/share/Modules/init/python.py").read(), globals())
module("load", "modulefile", "modulefile", "...")
```
A more Pythonic approach would be to `import` this `module` function somehow. Currently, you _can_ do that with as follows
```
import sys
sys.path.append("/usr/share/Modules/init")
from python import module
module("load", "modulefile", "moduelfile", "...")
```
The issues with this are that you have to modify the `sys.path` inside the script and since the Python-module `import`-ed is called "python". The name makes it look like `module` is a function from some core Python-module from the Python project.
I'm proposing to write a pull request to
1. rename the Python initialization file to something like `env_module_python.py` (this is what lmod named theirs by the way) and
2. to have the shell initialization scripts add the folder of initilization scripts to the PYTHONPATH environment variable. These changes would change Python initialization to
```
from env_module_python import module
module("load", "modulefile", "moduelfile", "...")
```
which cleans up the way the Python script imports the `module` function and communicates more clearly that it comes from a 3rd-party Python-module related to environment modules.
Byron Boulton
|