european-xfel / envmodules Goto Github PK
View Code? Open in Web Editor NEWPython wrapper around environment modules ("module load")
License: BSD 3-Clause "New" or "Revised" License
Python wrapper around environment modules ("module load")
License: BSD 3-Clause "New" or "Revised" License
Currently we have a few python modules which have their own modulefile, e.g. to make use of the foo python module, one would need to issue the commands
module load python
module load foo
python
import foo
This however, does not work using envmodules; e.g.
module load python
python
import envmodules
envmodules.load('foo')
import foo
will fail. This is understandable as generally a modulefile like for foo will only update the PYTHONPATH environmental variable (and there is no mechanism within env modulefiles to modify python data structures directly, as modulefiles are interpreter neutral), and the PYTHONPATH variable is only used by python when the interpreter first starts, which is too late see modules loaded by envmodules.
I would like to propose that envmodules detect any changes to PYTHONPATH, and make comparable changes to sys.path. This would allow the paths added to PYTHONPATH when
envmodules.load('foo')
is run to be able available in the current python session, so a subsequent import foo
will work.
I will submit a pull request to do this in a somewhat crude manner. It defines three new routines:
get_auto_fix_sys_path(), set_auto_fix_sys_path(): accessor/mutator for auto_fix_sys_path boolean data member. If set, the _modulecmd() routine will automatically invoke fix_sys_path().
The default is currently false (which means the existing behavior is default).
fix_sys_path(): This compares PYTHONPATH before and after the modulecmd calls, and attempts to update sys.path accordingly. This is somewhat crude for now; if simply notes paths which were in PYTHONPATH and no longer are, and deletes them from sys.path, and notes paths that were added to PYTHONPATH and adds them to sys.path. It is crude in that added paths are simply prepended to the front of sys.path --- more properly it should try to replicate the sys.path that would have been generated if python was invoked with the given PYTHONPATH, which means it should do a better job of keeping the system paths first, and maintaining the same order among all of the PYTHONPATH paths. But I figure this crude approach works for many cases, and is an improvement on the existing behavior (no modification of sys.path), and refinements can come later.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.