Issue #26587: Allow .pth files to specify file paths as well as
authorBrett Cannon <brett@python.org>
Fri, 8 Apr 2016 22:04:28 +0000 (15:04 -0700)
committerBrett Cannon <brett@python.org>
Fri, 8 Apr 2016 22:04:28 +0000 (15:04 -0700)
directories.

Thanks to Wolfgang Langner for the bug report and initial version of
the patch.

Doc/whatsnew/3.6.rst
Lib/site.py
Lib/test/test_site.py
Misc/ACKS
Misc/NEWS

index 555814e22029648b301c75254d11eeb20cc6d34e..d217c4d09a0e13972b5271f70fd938a7ebd66764 100644 (file)
@@ -251,6 +251,14 @@ Previously, names of properties and slots which were not yet created on
 an instance were excluded.  (Contributed by Martin Panter in :issue:`25590`.)
 
 
+site
+----
+
+When specifying paths to add to :attr:`sys.path` in a `.pth` file,
+you may now specify file paths on top of directories (e.g. zip files).
+(Contributed by Wolfgang Langner in :issue:`26587`).
+
+
 telnetlib
 ---------
 
index 56ba7091571f71dc5c03ed3ed422060c36e75e16..b66123fd16c12ace3a45ca10af9b08408b9d51b5 100644 (file)
@@ -131,13 +131,13 @@ def removeduppaths():
 
 
 def _init_pathinfo():
-    """Return a set containing all existing directory entries from sys.path"""
+    """Return a set containing all existing file system items from sys.path."""
     d = set()
-    for dir in sys.path:
+    for item in sys.path:
         try:
-            if os.path.isdir(dir):
-                dir, dircase = makepath(dir)
-                d.add(dircase)
+            if os.path.exists(item):
+                _, itemcase = makepath(item)
+                d.add(itemcase)
         except TypeError:
             continue
     return d
@@ -150,9 +150,9 @@ def addpackage(sitedir, name, known_paths):
     """
     if known_paths is None:
         known_paths = _init_pathinfo()
-        reset = 1
+        reset = True
     else:
-        reset = 0
+        reset = False
     fullname = os.path.join(sitedir, name)
     try:
         f = open(fullname, "r")
@@ -190,9 +190,9 @@ def addsitedir(sitedir, known_paths=None):
     'sitedir'"""
     if known_paths is None:
         known_paths = _init_pathinfo()
-        reset = 1
+        reset = True
     else:
-        reset = 0
+        reset = False
     sitedir, sitedircase = makepath(sitedir)
     if not sitedircase in known_paths:
         sys.path.append(sitedir)        # Add path component
index 21628a99ea4695aa0af6a7b24b022bd737cc2586..f698927f37c87a88d3aaff397109adf1968088a3 100644 (file)
@@ -75,7 +75,7 @@ class HelperFunctionsTests(unittest.TestCase):
     def test_init_pathinfo(self):
         dir_set = site._init_pathinfo()
         for entry in [site.makepath(path)[1] for path in sys.path
-                        if path and os.path.isdir(path)]:
+                        if path and os.path.exists(path)]:
             self.assertIn(entry, dir_set,
                           "%s from sys.path not found in set returned "
                           "by _init_pathinfo(): %s" % (entry, dir_set))
index 20e76f56aee521869d562941142b0a6966469612..6dd30f3675a8f71990d4955bc645eabc900ecae0 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -815,6 +815,7 @@ Torsten Landschoff
 Tino Lange
 Glenn Langford
 Andrew Langmead
+Wolfgang Langner
 Detlef Lannert
 Soren Larsen
 Amos Latteier
index 56b150170f7658b1d85459c61ecf5a1efd21f154..6fbbdb3ac37aa5ec5d231ac1b753d4cc28ce2bb0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -237,6 +237,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #26587: the site module now allows .pth files to specify files to be
+  added to sys.path (e.g. zip files).
+
 - Issue #25609: Introduce contextlib.AbstractContextManager and
   typing.ContextManager.