ESMCI / cime

Common Infrastructure for Modeling the Earth
http://esmci.github.io/cime
Other
161 stars 206 forks source link

avoid breaking Python environment by prepending CIME paths to PYTHONPATH #4683

Closed lexming closed 1 week ago

lexming commented 1 week ago

CIME currently carries out a full reset of the PYTHONPATH environment variable. This is bad practice as other software in the user's session might rely on their paths being present in PYTHONPATH to be usable.

For instance, in HPC clusters it's very common to use modules to load software packages on-demand and those modules will add the paths of the loaded Python software to PYTHONPATH. In our case, we provide lxml as a module, which is one of the dependencies of CIME. Therefore, CIME is breaking itself by resetting PYTHONPATH .

This PR changes how CIME handles PYTHONPATH by prepending cime_root and tools_path to PYTHONPATH instead of fully replacing it. This achieves the same goal of ensuring that external python can correctly import the CIME module, without breaking the rest of the Python ecosystem in the user's session.

Test suite: n/a Test baseline: n/a Test namelist changes: n/a Test status: n/a

Fixes: no open issue, but I can make a new one if you wish

User interface changes?: N

Update gh-pages html (Y/N)?: N

lexming commented 1 week ago

Thanks for the quick merge!