Coder Social home page Coder Social logo

envmodules's People

Contributors

takluyver avatar

Watchers

 avatar  avatar  avatar

Forkers

payerle

envmodules's Issues

envmodules load, etc. only affects PYTHONPATH, not sys.path

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.