-
Notifications
You must be signed in to change notification settings - Fork 109
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
Integrating with language-native installation practises #483
Comments
Thanks for your report. Regarding locations in documentation, this is set when building Modules. Public documentation describes a commonly used location ( Would it be possible to copy the Python initialization script of Modules in a 'Python path' location and make the |
Thanks, if I import os
exec(open('/usr/local/modules/5.2.0/init/python.py').read())
module('load', 'modulefile', 'modulefile', '...') This is helpful, although I think my arguments above still apply in that it would be nice to use each language's native import process.
Are you asking if I could do it? Probably, yes, if I edited the script and put it into the PYTHONPATH then I could set it up for my own user. But I think it would be helpful if this was configured as part of the standard environtment modules installation, so all users could get easy module initialisation. |
I agree that what you suggest would be nice to have. Are you willing to provide a pull request for such enhancement? (maybe not for all languages but some of them) |
Sure, I can look into it. I guess I would appreciate some guidance though. There are several ways I can envisage this working:
|
I would go for 1 with an installation option added to the |
So you think it should be installed into the system's Python, and so install it into |
So it could be two installation options:
|
I'd like to add here; the Python integration (at least for me) indeed feels "unPythonic", and it seems to not work (at least in a unit-test scenario). I have not looked further into detail yet, but this for example breaks: $ cat test_module_command.py def test_module_command():
module_python_init = "/usr/share/Modules/init/python.py"
try:
exec(open(module_python_init).read())
result = module("list")
except NameError:
assert False, "module function not correctly defined!"
try:
assert result
except AssertionError:
assert False, "module list did not work" $ pytest test_module_command.py
===================================================== test session starts =====================================================
platform linux -- Python 3.8.16, pytest-7.2.2, pluggy-1.0.0
rootdir: /albedo/work/user/pgierz/SciComp/User-Support/fabagh001/OpenCV_Issue
collected 1 item
test_module_command.py F [100%]
========================================================== FAILURES ===========================================================
_____________________________________________________ test_module_command _____________________________________________________
def test_module_command():
module_python_init = "/usr/share/Modules/init/python.py"
try:
exec(open(module_python_init).read())
> result = module("list")
E NameError: name 'module' is not defined
test_module_command.py:5: NameError
During handling of the above exception, another exception occurred:
def test_module_command():
module_python_init = "/usr/share/Modules/init/python.py"
try:
exec(open(module_python_init).read())
result = module("list")
except NameError:
> assert False, "module function not correctly defined!"
E AssertionError: module function not correctly defined!
E assert False
test_module_command.py:7: AssertionError
=================================================== short test summary info ===================================================
FAILED test_module_command.py::test_module_command - AssertionError: module function not correctly defined!
====================================================== 1 failed in 0.06s ====================================================== If there is indeed ever a push towards making the scripting language integration feel more intuitive, I can happily offer for writing unit tests (for Python at least) |
And interestingly, this works fine:
|
@pgierz You need to make the module def defined in the global scope when calling def test_module_command():
module_python_init = "/usr/share/Modules/init/python.py"
try:
exec(open(module_python_init).read(), globals())
result = module("list")
except NameError:
assert False, "module function not correctly defined!"
try:
assert result
except AssertionError:
assert False, "module list did not work" More explanation available here for instance: https://stackoverflow.com/questions/24733831/using-a-function-defined-in-an-execed-string-in-python-3 |
Update Python initialization example to precise that the init script should be exec-ed in the global scope. This is important when init script is executed from a function. This change helps to clarify a question asked on #483.
Thank you @xdelaruelle! Another little trick to keep written in my book. |
Is your feature request related to a problem? Please describe.
Currently the programming language (python, R) wrapper scripts are awkward to run, and often require
eval
ing the wrapper script, which is often considered bad or dangerous so users may not feel comfortable doing this. This is also confusingly very different to the native "load a library" syntax that most languages have. In addition, loading them often requires a knowledge of the precise location of the wrapper script on the filesystem. For example, on my HPC system we have modules installed at/usr/local/modules/5.2.0
which differs from the documentation which tells us to use/usr/share/Modules
. I will use Python as a motivating example. In the docs we are told to do this to enablemodules
in Python:As noted, this won't even actually work with my modules installation path.
Describe the solution you'd like
A nice solution would be to compile actual native language packages as part of the build process. For example, this would be possible in Python if we built a Python package that contained roughly the function function output by
modulecmd python autoinit
, and published it into a given (configurable) Python path, and then exportedPYTHONPATH=/path/to/module/script:$PYTHONPATH
so that Python can find it.With this done, a user could simply
import modules
or perhapsimport env_modules
to distinguish this package from Python's own modules system. This would avoid the issues mentioned above. Similar arguments apply to R and other languages that I understand less well.Describe alternatives you've considered
The current system of
eval
ing specific files does work, but has disadvantages as described above.The text was updated successfully, but these errors were encountered: