mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.9] gh-113659: Skip hidden .pth files (GH-113660) (GH-114146)
(cherry picked from commit 74208ed0c4)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
dd068eaf48
commit
8fc8c45b67
3 changed files with 50 additions and 1 deletions
11
Lib/site.py
11
Lib/site.py
|
|
@ -74,6 +74,7 @@
|
|||
import builtins
|
||||
import _sitebuiltins
|
||||
import io
|
||||
import stat
|
||||
|
||||
# Prefixes for site-packages; add additional prefixes like /usr/local here
|
||||
PREFIXES = [sys.prefix, sys.exec_prefix]
|
||||
|
|
@ -156,6 +157,13 @@ def addpackage(sitedir, name, known_paths):
|
|||
else:
|
||||
reset = False
|
||||
fullname = os.path.join(sitedir, name)
|
||||
try:
|
||||
st = os.lstat(fullname)
|
||||
except OSError:
|
||||
return
|
||||
if ((getattr(st, 'st_flags', 0) & stat.UF_HIDDEN) or
|
||||
(getattr(st, 'st_file_attributes', 0) & stat.FILE_ATTRIBUTE_HIDDEN)):
|
||||
return
|
||||
try:
|
||||
f = io.TextIOWrapper(io.open_code(fullname))
|
||||
except OSError:
|
||||
|
|
@ -203,7 +211,8 @@ def addsitedir(sitedir, known_paths=None):
|
|||
names = os.listdir(sitedir)
|
||||
except OSError:
|
||||
return
|
||||
names = [name for name in names if name.endswith(".pth")]
|
||||
names = [name for name in names
|
||||
if name.endswith(".pth") and not name.startswith(".")]
|
||||
for name in sorted(names):
|
||||
addpackage(sitedir, name, known_paths)
|
||||
if reset:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue