From: mwh21 at cam.ac.uk (Michael Hudson)
Date: 16 Apr 1999 13:10:56 +0100
Subject: Imperfections in ihooks.py?
Message-ID: <m390bsoje7.fsf@atrus.jesus.cam.ac.uk>
Content-Length: 1865
X-UID: 927                                                  

I apologise for the lousy use of language in this post. It's a subject
I find a bit confusing to think about, and I'm clearly not much better
a writing about it.

Does anybody out there use ihooks? I'm having a couple of problems.

What I want to happen is to be able to import a file ending in some
random extension (I've chosen '.om') apply some simple preproccessing
to it, and then treat that preprocessing as a normal python module. 

I have a mostly working solution. I can import just fine, but
reloading doesn't happen (for any module, not just mine) after I've
installed a module importer. I've looked at the code, and this seems
inevitable. Should this be changed? I could have a stab at it.

On a related note, the import of '.pyc' files takes no notice of the
timestamp in the file, so if you import a module that has a stale .pyc
file, you get the stale version from the '.pyc' file, not the new
version from the '.py' file. This would seem to be harder to fix. I
can't see any consideration given to the possibility of rejecting a
file once it's been found.

These problems would cause no grief once a program is finished, but
they make a bit of a mess of development.

Turns out the first problem is easy to fix:

--- ihooks.py   1999/04/15 08:19:46     1.1.1.1
+++ ihooks.py   1999/04/16 12:08:41
@@ -489,6 +489,7 @@
     def reload(self, module):
         name = module.__name__
         if '.' not in name:
+            self.unload(module)
             return self.import_it(name, name, None)
         i = string.rfind(name, '.')
         pname = name[:i]

which does the trick for simple modules. Packages just make my head
hurt a bit at the moment.

Anybody have any ideas what I could do to improve my situation? If I
make some changes to fix them, would there be a chance of getting them
into the distribution?

Thanks for reading

Michael




