[Python-Dev] guidance sought: merging port related changes to Library modules

Mark Hammond mhammond@skippinet.com.au
Wed, 16 Jan 2002 16:40:03 +1100


Fred writes:
> Guido van Rossum writes:
>  > The various modules ntpath, posixpath, macpath etc. are not just their
>  > to support their own platform on itself.  They are also there to
>
> Note that ntpath.abspath() relies on nt._getfullpathname().  It is not
> unreasonable for this particular function to require that it actually
> be running on NT, so I'm not going to suggest changing this.  On the
> other hand, it means the portable portions of the module are (mostly)
> not tested when the regression test is run on a platform other than
> Windows; the ntpath.abspath() test raises an ImportError since
> ntpath.abspath() imports the "nt" module within the function, and the
> resulting ImportError causes the rest of the unit test to be skipped
> and regrtest.py reports that the test is skipped.
>
> I'd like to change the test so that the abspath() test is only run
> if the "nt" module is available:

Sigh - this too would be my fault :(

Before _getfullpathname() was added to the 'nt' module, there was an attempt
to import 'win32api', and if OK, use the equivilent function from that.
When I added the new function to 'nt', I removed that import check, in the
belief it would now always succeed.  This was obviously a bad call ;)  (FYI,
that was rev 1.35 of ntpath.py)

A patch that reinstates the code would be:

Index: ntpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ntpath.py,v
retrieving revision 1.44
diff -u -r1.44 ntpath.py
--- ntpath.py	2001/11/05 21:25:02	1.44
+++ ntpath.py	2002/01/16 05:35:19
@@ -457,8 +457,18 @@
 # Return an absolute path.
 def abspath(path):
     """Return the absolute version of a path"""
-    if path: # Empty path must return current working directory.
+    try:
         from nt import _getfullpathname
+    except ImportError: # Not running on Windows - mock up something
sensible.
+        global abspath
+        def _abspath(path):
+            if not isabs(path):
+                path = join(os.getcwd(), path)
+            return normpath(path)
+        abspath = _abspath
+        return _abspath(path)
+
+    if path: # Empty path must return current working directory.
         try:
             path = _getfullpathname(path)
         except WindowsError:

This should also solve the test case problem.

Thoughts?

Mark.