Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f0507d

Browse files
committed
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.
1 parent ef0138f commit 5f0507d

5 files changed

Lines changed: 22 additions & 10 deletions

File tree

Doc/whatsnew/3.6.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ Previously, names of properties and slots which were not yet created on
251251
an instance were excluded. (Contributed by Martin Panter in :issue:`25590`.)
252252

253253

254+
site
255+
----
256+
257+
When specifying paths to add to :attr:`sys.path` in a `.pth` file,
258+
you may now specify file paths on top of directories (e.g. zip files).
259+
(Contributed by Wolfgang Langner in :issue:`26587`).
260+
261+
254262
telnetlib
255263
---------
256264

Lib/site.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ def removeduppaths():
131131

132132

133133
def _init_pathinfo():
134-
"""Return a set containing all existing directory entries from sys.path"""
134+
"""Return a set containing all existing file system items from sys.path."""
135135
d = set()
136-
for dir in sys.path:
136+
for item in sys.path:
137137
try:
138-
if os.path.isdir(dir):
139-
dir, dircase = makepath(dir)
140-
d.add(dircase)
138+
if os.path.exists(item):
139+
_, itemcase = makepath(item)
140+
d.add(itemcase)
141141
except TypeError:
142142
continue
143143
return d
@@ -150,9 +150,9 @@ def addpackage(sitedir, name, known_paths):
150150
"""
151151
if known_paths is None:
152152
known_paths = _init_pathinfo()
153-
reset = 1
153+
reset = True
154154
else:
155-
reset = 0
155+
reset = False
156156
fullname = os.path.join(sitedir, name)
157157
try:
158158
f = open(fullname, "r")
@@ -190,9 +190,9 @@ def addsitedir(sitedir, known_paths=None):
190190
'sitedir'"""
191191
if known_paths is None:
192192
known_paths = _init_pathinfo()
193-
reset = 1
193+
reset = True
194194
else:
195-
reset = 0
195+
reset = False
196196
sitedir, sitedircase = makepath(sitedir)
197197
if not sitedircase in known_paths:
198198
sys.path.append(sitedir) # Add path component

Lib/test/test_site.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_makepath(self):
7575
def test_init_pathinfo(self):
7676
dir_set = site._init_pathinfo()
7777
for entry in [site.makepath(path)[1] for path in sys.path
78-
if path and os.path.isdir(path)]:
78+
if path and os.path.exists(path)]:
7979
self.assertIn(entry, dir_set,
8080
"%s from sys.path not found in set returned "
8181
"by _init_pathinfo(): %s" % (entry, dir_set))

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ Torsten Landschoff
815815
Tino Lange
816816
Glenn Langford
817817
Andrew Langmead
818+
Wolfgang Langner
818819
Detlef Lannert
819820
Soren Larsen
820821
Amos Latteier

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ Core and Builtins
237237
Library
238238
-------
239239

240+
- Issue #26587: the site module now allows .pth files to specify files to be
241+
added to sys.path (e.g. zip files).
242+
240243
- Issue #25609: Introduce contextlib.AbstractContextManager and
241244
typing.ContextManager.
242245

0 commit comments

Comments
 (0)