Question

Spyder's UMD is usually great for me but periodically I trip myself when writing a module that I don't want to delete and reload. I know I can control the UMD via Tools > Preferences > Console > Advanced settings > User Module Deleter. But I would also like to be able to mark certain modules I write as non-UMD friendly in the code of the module itself.

In a perfect world I would just write something like

assert_no_umd()

which would throw an exception if the module is hit by the UMD. It would be fine if the code was tripped by any reloading of the module, whether by UMD or otherwise.

Note that this is different from Method that gets called on module deletion in Python because that question is about cleaning up a database connection which only needs to be done once, and therefore can be done with atexit.

Was it helpful?

Solution

(Spyder dev here) If I understand you correctly, this would be my assert_no_umd function:

import os

def assert_no_umd():
    mod = __file__
    if os.environ.get("UMD_ENABLED", "").lower() == "true":
        namelist = os.environ.get("UMD_NAMELIST", None)
        if namelist is not None:
            namelist = namelist.split(',')
            if mod not in namelist:
                 raise ValueError('UMD active!!')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top