MCPcopy Index your code
hub / github.com/RustPython/RustPython / addsitedir

Function addsitedir

Lib/site.py:234–257  ·  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

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

Callers 2

addusersitepackagesFunction · 0.85
addsitepackagesFunction · 0.85

Calls 10

_traceFunction · 0.85
_init_pathinfoFunction · 0.85
makepathFunction · 0.85
sortedFunction · 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