Add code to update sys.path when PYTHONPATH changes#2
Open
payerle wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See #1
This patch attempts to cause updates to PYTHONPATH when modules loaded/unloaded via
envmodules to cause corresponding updates to sys.path, so that one can in theory use envmodules to load a modulefile for a python module and then import the python module in the same python session.
It adds a routine
fix_sys_path() which compares PYTHONPATH before and after calls to modulecmd, and if they
differ see what paths were added/removed, and add/remove them from sys.path. It is a bit crude in that it currently only checks for presence/absence of a path in PYTHONPATH; a more proper approach should detect changes in ordering of paths, and do more to preserve the correct order.
The _modulecmd() method was modified to optionally invoke fix_sys_path() after each call depending on the value of a private boolean data member _auto_fix_sys_path. An accessor and mutator (get_auto_fix_sys_path() and set_auto_fix_sys_path()) for this data member also provided.