Vaguely off-topic, but I figured someone here might know... Anyway, I want to provide backported stdlib modules to older versions of Python. Most of these are trivial to backport, so it's just a matter of accumulating them in one place. So I'm wondering how best I should put this in place. One way would be to import the backported modules, then modify sys.modules. But this requires importing everything ahead of time, which is no good. At the same time, I'd rather have the process Instantly Seem Upgraded (assuming the program isn't using any language features not supported by the process). I could actually distribute something that included the top-level modules; this would work for something like optparse or subprocess, where the module simply didn't exist before. But this doesn't work when providing updated modules that existed before but have been enhanced, like doctest. I'm also not sure when I should monkeypatch the existing module, or provide a new one. For instance, tempfile added a couple functions in 2.4, and UserDict added a useful class (DictMixin). Thoughts? -- Ian Bicking / ianb@colorstudy.com / http://blog.ianbicking.org
[Ian Bicking wrote]
Vaguely off-topic, but I figured someone here might know...
Anyway, I want to provide backported stdlib modules to older versions of Python. Most of these are trivial to backport, so it's just a matter of accumulating them in one place.
Is it important in your use case to magically stick them in the same place as the standard locations? I remember a few people mentioning that they have their own "compat" (or "compat23", ...) modules kicking around. It might be nice to have a collective "compat" or "backported" package out there, then users could explicitly: try: from compat import tempfile except ImportError: import tempfile Dunno if that matches up with what you wanted to do.
Thoughts?
An import hook that does the magic? Trent -- Trent Mick TrentM@ActiveState.com
On Sep 1, 2005, at 5:26 PM, Trent Mick wrote:
[Ian Bicking wrote]
Vaguely off-topic, but I figured someone here might know...
Anyway, I want to provide backported stdlib modules to older versions of Python. Most of these are trivial to backport, so it's just a matter of accumulating them in one place.
Is it important in your use case to magically stick them in the same place as the standard locations? I remember a few people mentioning that they have their own "compat" (or "compat23", ...) modules kicking around. It might be nice to have a collective "compat" or "backported" package out there, then users could explicitly:
try: from compat import tempfile except ImportError: import tempfile
Dunno if that matches up with what you wanted to do.
Thoughts?
An import hook that does the magic?
You can also install a .pth file that looks like this, which is a little bit less magical than an import hook: import sys; sys.path.insert(0, 'modules-that-override-the-stdlib-are- here') Of course, you can't override anything that is imported before the site module is, but most of those are built-in or have baked-in references in the interpreter anyway. -bob
participants (3)
-
Bob Ippolito
-
Ian Bicking
-
Trent Mick