This function removes any modules imported from below some given folder. So just pass it the top folder of the tool you’re developing.
Here, let me give you some usage examples.
First, I drop a file with clearPathSymbols
into my scripts folder, so it’s available to Maya’s python.
Then, when I’m developing anything, I just make a shelf button for “Reload this tool”.
For example, my shelf would contain something like:
from clearPathSymbols import clearPathSymbols
clearPathSymbols(['/path/to/moduleInDdevelopment'])
from moduleInDevelopment import someFunction
someFunction()
That way, without changing anything about the tool I’m writing, I can force a reload whenever I want without caring how the imports are structured.
The other thing that really comes in handy is having a shelf button that reloads the entire user scripts directory so any changes I make anywhere can be easily reloaded. I just have to make sure that clearPathSymbols
is in my keepers list because I’ve got it defined in my user scripts folder.
from clearPathSymbols import clearPathSymbols
clearPathSymbols(['/path/to/scripts'], keepers=['clearPathSymbols'])
We have something similar to this at work. Everybody in the company just has a shelf button that reloads the entire scripts directory, so any time a hotfix comes out, we just tell the users to hit a button, and relaunch the fixed tool. No restarts required.