Mailing List Archive

Imperfections in ihooks.py?
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
Imperfections in ihooks.py? [ In reply to ]
> 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.

Forget about ihooks.py. Greg Stein's imputil.py module
is much easier to use, and much more powerful.

It's in the "small distribution" kit, available from:

http://www.lyra.org/greg/small/

</F>
Imperfections in ihooks.py? [ In reply to ]
"Fredrik Lundh" <fredrik@pythonware.com> writes:
> > 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.
>
> Forget about ihooks.py. Greg Stein's imputil.py module
> is much easier to use, and much more powerful.
>
> It's in the "small distribution" kit, available from:
>
> http://www.lyra.org/greg/small/
>
> </F>

Ah! Fantastic!

Usual case; I start to think about a problem, ask about it and find
someone else has solved the problem already.

Not perfection yet though - imputil.py contains these lines:

def _reload_hook(self, module):
raise SystemError, "reload not yet implemented"

which was one of the things I was moaning about in my post.

Thanks!

Michael
Imperfections in ihooks.py? [ In reply to ]
[.Michael Hudson messes with ihooks and /F points him to Greg's
imputil.py at http://www.lyra.org/greg/small/ ]:

> Ah! Fantastic!
>
> Usual case; I start to think about a problem, ask about it and find
> someone else has solved the problem already.
>
> Not perfection yet though - imputil.py contains these lines:
>
> def _reload_hook(self, module):
> raise SystemError, "reload not yet implemented"
>
> which was one of the things I was moaning about in my post.

Greg is being bad. First, that page hasn't been updated with the link
to my installer (www.mcmillan-inc.com/install.html), and his
imputil.py doesn't have my patch. Said patch doesn't implement
reload, but it does at least determine whether the reload request is
for a module under the hook's control. If not, it passes the request
on.

I looked at what it would take to implement reload. It didn't look
_that_ bad. However, for my purposes (serving modules from an
archive) it just didn't make much sense. I mean, we're talking about
an alternative to freeze after all...

Nits aside, imputil.py is a truly outstanding piece of code.

- Gordon