Friday, February 10, 2006

Packages, smackages!

I had never created a package before working on pywinauto. I just made scripts and if they required other python files that I wrote then I just stuck them in the same directory and imported them from there
import myotherscipt
Then I decided for pywinauto to try and move things around and be better organized - so I created some packages pywinauto.controls and pywinauto.tests.

What feels strange to me is that these packages are not self contained, I don't mind having to rely on class capabilities defined in other packages (e.g. when testing - that the controls passed in have a Rectangle() method) but I don't like having to import pywinauto.win32defines or other modules from pywinauto. It seems to me that packages should be more self contained then that?

Should I just do away with these packages and have everything as a flat structure? Should I re-structure so that the parts of pywinauto that I do have to import are in a package of their own (that does not need anything from pywinauto)?

Well it looks like __path__ is what I need. I guess my pywinauto.controls is not really a package - and I want a directory just for organization. I think pywinauto.tests is a package - as I need to initialize it, and I expect it to always be imported by using import tests (or import pywinauto.tests)

hmm - a little more analysis needed I guess to resolve those dependencies.

1 comment:

  1. your packages dont have to self-contained on the implementation level; it is very common for them to inter-depend. your packages should, however, be independant on the conceptual level. might depend on foo.baz, but they should still handle understandable seperate areas of the problem set.