Hi All,
this is not (yet) and announcement, just a request for suggestions as I am struggling a bit to do The Right Thing ™. I am still coding a little tool Robin has christened as “Namespace Diff Tool”:
http://svn.wxwidgets.org/viewvc/wx/wxPython/Phoenix/trunk/TODO.txt?view=markup
One of the (many) issues I am having is related to how the import mechanism works in Python and where the code for a class/method/attribute actually is. These are the given, for the moment:
-
The tool is generic enough to be used on other libraries/packages. I have successfully used it to import and analyze more than 30 libraries[1];
-
I use the Python import builtin function at runtime to find out the package/module/class hierarchies, code, methods signatures, attributes, docstrings and so on.
Now, if you look at the first screenshot I am attaching (NDT_Import_1.png), and specifically at the agw.aui tree, you will see that this tree contains all the classes, methods and attributes for all the widgets in agw.aui. We can focus, for example, on the AuiCenterDockingGuide class in the center of the screeenshot. However, the AuiCenterDockingGuide class is defined in the framemanager module and, when I import the framemanager module itself, another AuiCenterDockingGuide class appears as a child of the framemanager node, as you can see in the second screenshot (NDT_Import_2.png).
The dichotomy here is that, although the code for this class actually lives in agw.aui.framemanager, the objects themselves, once imported, live in the agw.aui namespace because the init.py file for agw.aui contains the following statements:
from aui_constants import *
from aui_utilities import *
from auibar import *
from auibook import *
from tabart import *
from dockart import *
from framemanager import *
from tabmdi import *
Now, I would like to preserve the hierarchy package => module => class inside the NDT trees, which means that the framemanager module should be there as a separate node (and as a child of the agw.aui package), containing all its children (classes, methods, attributes, etc…), but I have no idea how to avoid duplication of tree children because of the Python import mechanism. This effect is even worse on other libraries (like numpy, for example) which do some heavy voodoo importing stuff in the init.py files for their sub-packages. You can actually see what happens with numpy when I filter the package tree for the “complex128” class in the third screenshot (NDT_numpy.png). This “complex128” class lives in the numpy namespace but I believe its declaration is inside the numpy.core package or the numpy.core.numerictypes module.
On the same note, if we consider core classes like wx.TextCtrl, they do live in the wx namespace but their definition is inside the _controls.py Python file. At the moment I am filtering out the import of modules which name starts with an underscore, but I am not sure this is a comprehensive and fault-free approach.
Any suggestion on how to handle this issues is most welcome. I can live with the class/method/attribute duplication but it would be nice if it didn’t happen…
Thank you in advance.
[1] In my test database I currently have successfully imported the following libraries/packages:
apptools-4.0.0, Bio-1.57, cloud-2.2.4, coverage-3.5, Crypto-2.3, Cython-0.14.1, dateutil-1.5, docutils-0.7, fwrap-1.0, html5lib-0.90, IPython-0.11, jinja2-2.5.5, lxml-2.0, matplotlib-1.0.1, mayavi-4.0.0, networkx-1.5, numpy-1.6.1, OpenSSL-0.12, paramiko-1.7.7.1, PySide-1.0.5, pytz-2011g, reportlab-3788, scipy-0.9.0, setuptools-0.6, sphinx-1.0.7, sqlalchemy-0.7.1, sympy-0.7.1, traits-4.0.0, vtk-5.0, wx-2.9.2.4, xlrd-0.7.1, xlwt-0.7.1, zope-1.0
Andrea.
“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/
import PyQt4.QtGui
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named PyQt4.QtGui
import pygtk
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named pygtk
···
import wx