]> granicus.if.org Git - python/commitdiff
Issue #7328: don't corrupt sys.path when running pydoc with the -m switch
authorNick Coghlan <ncoghlan@gmail.com>
Sun, 15 Nov 2009 22:36:47 +0000 (22:36 +0000)
committerNick Coghlan <ncoghlan@gmail.com>
Sun, 15 Nov 2009 22:36:47 +0000 (22:36 +0000)
Lib/pydoc.py
Misc/NEWS

index 57071a15066c2a17d797e9122a22def8936806fe..7da75b65bf0fb95f5d6dd659c92a94cc5736ed20 100755 (executable)
@@ -2254,11 +2254,13 @@ def cli():
     import getopt
     class BadUsage: pass
 
-    # Scripts don't get the current directory in their path by default.
-    scriptdir = os.path.dirname(sys.argv[0])
-    if scriptdir in sys.path:
-        sys.path.remove(scriptdir)
-    sys.path.insert(0, '.')
+    # Scripts don't get the current directory in their path by default
+    # unless they are run with the '-m' switch
+    if '' not in sys.path:
+        scriptdir = os.path.dirname(sys.argv[0])
+        if scriptdir in sys.path:
+            sys.path.remove(scriptdir)
+        sys.path.insert(0, '.')
 
     try:
         opts, args = getopt.getopt(sys.argv[1:], 'gk:p:w')
index 2f55a6786d8950daf1a266051723c6e6bf1873f1..041f2a77236dce22f69b578b523482c6c7367e1d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -429,6 +429,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #7328: pydoc no longer corrupts sys.path when run with the '-m' switch
+
 - Issue #2054: ftplib now provides an FTP_TLS class to do secure FTP using
   TLS or SSL.  Patch by Giampaolo Rodola'.