Skip to content

Add code to update sys.path when PYTHONPATH changes#2

Open
payerle wants to merge 2 commits into
European-XFEL:masterfrom
payerle:master
Open

Add code to update sys.path when PYTHONPATH changes#2
payerle wants to merge 2 commits into
European-XFEL:masterfrom
payerle:master

Conversation

@payerle

@payerle payerle commented Apr 19, 2021

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant