normpath/abspath problem
Hi all -- Corran Webster has discovered an annoying little problem: 'os.path.normpath()' is broken under Mac OS. (More precisely, 'macpath.normpath()' is broken.) He has an alternate version which sounds agreeable to the MacPython folks, so there's a good chance it'll be in Python 2.0, and possibly 1.6. To maintain full compatibility with 1.5.2, though, we'd have to include it in the Distutils and use it if necessary, eg. def mac_normpath (path): ... if mac and python < 1.6: normpath = mac_normpath else: normpath = os.path.normpath OK, that works. We have to search out all uses of os.path.normpath and change them to util.normpath (where util = distutils/util.py, where the above code would live), but that's not a big deal. It's certainly the clean way to do it. But then what about abspath(), which uses normpath()? macpath.abspath() -- like the other two abspath() implementations -- calls normpath(), but it would end up calling the version in macpath.py, which will still be broken. Options: * change the above code to if mac and python < 1.6: os.path.normpath = mac_normpath which was actually my original suggestion, but I changed my mind because it's *evil* * provide a Distutils version of abspath(), which (surprise) would be identical source to macpath.abspath()... but would of course refer to our normpath() * forget about Mac OS support under Python 1.5.2 I'm not really keen on any of these. Other ideas? ...Distutils, the alternative Python test suite... Greg -- Greg Ward - nerd gward@python.net http://starship.python.net/~gward/ God made machine language; all the rest is the work of man.
Greg Ward writes:
He has an alternate version which sounds agreeable to the MacPython folks, so there's a good chance it'll be in Python 2.0, and possibly 1.6. To maintain full compatibility with 1.5.2, though, we'd have to include it in the Distutils and use it if necessary, eg.
def mac_normpath (path): ...
So far so good.
if mac and python < 1.6: normpath = mac_normpath else: normpath = os.path.normpath
How about: import sys try: sys.version_info except AttributeError: import macpath macpath = mac_normpath Simple, and doesn't require any platform tests. (sys.version_info is new starting in version 1.6.)
But then what about abspath(), which uses normpath()? macpath.abspath() -- like the other two abspath() implementations -- calls normpath(), but it would end up calling the version in macpath.py, which will still be broken.
This solution fixes all callers of macpath.normpath without additional magic. Keep It Simple. ;) -Fred -- Fred L. Drake, Jr. <fdrake at beopen.com> BeOpen PythonLabs Team Member
On 03 August 2000, Fred L. Drake, Jr. said:
import sys try: sys.version_info except AttributeError: import macpath macpath = mac_normpath
I assume you meant "macpath.normpath = mac_normpath" there! That said, I've never been fond of using try/except when you mean if. If you mean "Python version >= 1.6" why not say so? How exactly does "sys.version_info does not raise an exception" convey "this is Python 1.6 or greater" to the average reader? Greg -- Greg Ward - Linux nerd gward@python.net http://starship.python.net/~gward/ The world's my oyster soup kitchen floor wax!
participants (2)
-
Fred L. Drake, Jr.
-
Greg Ward