[vtk-developers] New vtk packages; suggestions reqd. for other modules

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Tue Oct 9 00:26:05 EDT 2001


hi,

Thanks for the feedback!

>>>>> "DG" == David Gobbi <dgobbi at irus.rri.ca> writes:

<snip>
    >>>> import vtk.common

    DG> the result is identical to if I do

    >>>> import vtk

    DG> because both cause vtk/__init__.py to be loaded.  The only way
    DG> to import just the 'common' module is with "from vtk import
    DG> common".

    DG> The only work-around I can think of is to move the contents of
    DG> vtk/__init__.py into another file called e.g. vtk/all.py, so
    DG> that a simple "import vtk" doesn't cause any modules to be
    DG> loaded.

Yes, I know of this and mentioned it in one of my several mails and it
bothered me too.  :) The only reason I did this was because it works
and even though it is a little funny at first - this approach does
give you the convenience of using just import vtk and also give you
specific set of classes via vtk.common and friends.  Actually there
are a couple of alternatives to using all.py.

  (1) We change __import__ - dirty, forget it. :)

  (2) We change the base directory of the package to some other name
  like vtkpkg (or vtkpy) and stick vtk.py inside it or outside it.
  The result.

    import vtkpkg.common 
    # gives you *just* common
    import vtkpkg.vtk
    # gives you everything
    # Alternatively if vtk.py is outside the package structure.
    import vtk 
    # will do what we expect - give us everything.

What do you folks say?

    DG> Also, (also because vtk/__init__.py is being called) when I do

    >>>> import vtk.parallel

    DG> no error is generated even though I don't have "parallel"
    DG> compiled.

Ahhh I didnt check that case - I kept trying to handle link errors.
This is easily fixed by doing a del sys.modules['vtk.pkg'] for all
failed 'pkg's - that way you should see the error.  All it needs is a
couple of lines in __helper.py.  Can commit it if it will make a
difference.  Let me know.
    
    DG> It might, in the end, be easier not use a directory structure,
    DG> and to instead just have a "vtk.py", a "vtkcommon.py", etc.
    DG> but only if the directory-structure approach doesn't work out.

Which is why I wanted folks to comment.  Any approach is a compromise.
Either you have to type more, or deal with some issue or the other
etc.  So its up to us to see what is the best compromise. :) I know
this is a pain since lots of us are busy, but I see no choice. :)

Thanks again for the feedback!

prabhu



More information about the vtk-developers mailing list