summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2016-04-08 22:04:28 (GMT)
committerBrett Cannon <brett@python.org>2016-04-08 22:04:28 (GMT)
commit5f0507d8ab2fee70139ff147c5f7d472e8f4ba2b (patch)
tree1c786d5ca8a1d515b9396998f55ad535f26acc19
parentef0138f42153d467edf8b0429c531f5204fe45dc (diff)
downloadcpython-5f0507d8ab2fee70139ff147c5f7d472e8f4ba2b.zip
cpython-5f0507d8ab2fee70139ff147c5f7d472e8f4ba2b.tar.gz
cpython-5f0507d8ab2fee70139ff147c5f7d472e8f4ba2b.tar.bz2
Issue #26587: Allow .pth files to specify file paths as well as
directories. Thanks to Wolfgang Langner for the bug report and initial version of the patch.
-rw-r--r--Doc/whatsnew/3.6.rst8
-rw-r--r--Lib/site.py18
-rw-r--r--Lib/test/test_site.py2
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
5 files changed, 22 insertions, 10 deletions
diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst
index 555814e..d217c4d 100644
--- a/Doc/whatsnew/3.6.rst
+++ b/Doc/whatsnew/3.6.rst
@@ -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
---------
diff --git a/Lib/site.py b/Lib/site.py
index 56ba709..b66123f 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -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
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 21628a9..f698927 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -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))
diff --git a/Misc/ACKS b/Misc/ACKS
index 20e76f5..6dd30f3 100644
--- 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
diff --git a/Misc/NEWS b/Misc/NEWS
index 56b1501..6fbbdb3 100644
--- 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.