I am trying to find all missing import statements and errors for each module and its sub modules.
Is there a dedicated tool for what I am trying to do?
The code that I wrote, but seems really terrible and maybe something like this exists already?:
import os
def find_missing_imports(walk):
for items in walk:
d = items[0]
f_list = items[1]
for f in f_list:
module = f[:-3]
# posix_path
module_path = d.lstrip('.').replace('/','.').lstrip('.')
try:
__import__(module_path, fromlist=[module])
except IndentationError, e:
#print(f,e)
pass
except NameError, e:
print(d,f,e)
pass
except Exception, e:
print(f,e)
pass
walk = [[root,files] for root,dirs,files in os.walk('.') for fn in files if fn.endswith('.py')]
find_missing_imports(walk)
Outputs:
.[snip]
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ImageSelectionFrame.py', NameError("name 'wx' is not defined",))
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ItemSpecificsDialog.py', NameError("name 'wx' is not defined",))
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ReturnCorrectWatchTitle.py', NameError("name 'wx' is not defined",))
.[snip]
My project before refactoring was a mess but sort of useful, now its broken after refactoring.
After reading 'The Pragmatic Programmer' based on suggestions from my initial post on codereview:
I have been digging around in the source code of:
/usr/local/lib/python2.7/dist-packages/rope
Documentation for ROPE seems a little sparse. I have also been using Ninja-IDE, but haven't been able to find a solution for the problem that I am facing.
Overall I think I missed the boat on what refactoring is all about.
The current parent directory layout can be seen here.
In comparison to what it was before.
Any help, on filling in missing terminology, or on what I am even asking would be great.
Solution:
pylint -E /path/to/module