MCPcopy Index your code
hub / github.com/python/cpython / addsitedir

Function addsitedir

Lib/site.py:232–255  ·  view source on GitHub ↗

Add 'sitedir' argument to sys.path if missing and handle .pth files in 'sitedir

(sitedir, known_paths=None)

Source from the content-addressed store, hash-verified

230
231
232def addsitedir(sitedir, known_paths=None):
233 """Add 'sitedir' argument to sys.path if missing and handle .pth files in
234 'sitedir'"""
235 _trace(f"Adding directory: {sitedir!r}")
236 if known_paths is None:
237 known_paths = _init_pathinfo()
238 reset = True
239 else:
240 reset = False
241 sitedir, sitedircase = makepath(sitedir)
242 if not sitedircase in known_paths:
243 sys.path.append(sitedir) # Add path component
244 known_paths.add(sitedircase)
245 try:
246 names = os.listdir(sitedir)
247 except OSError:
248 return
249 names = [name for name in names
250 if name.endswith(".pth") and not name.startswith(".")]
251 for name in sorted(names):
252 addpackage(sitedir, name, known_paths)
253 if reset:
254 known_paths = None
255 return known_paths
256
257
258def check_enableusersite():

Callers 2

addusersitepackagesFunction · 0.85
addsitepackagesFunction · 0.85

Calls 9

_traceFunction · 0.85
_init_pathinfoFunction · 0.85
makepathFunction · 0.85
addpackageFunction · 0.85
listdirMethod · 0.80
appendMethod · 0.45
addMethod · 0.45
endswithMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…