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

Class DirsOnSysPath

Lib/test/support/import_helper.py:238–260  ·  view source on GitHub ↗

Context manager to temporarily add directories to sys.path. This makes a copy of sys.path, appends any directories given as positional arguments, then reverts sys.path to the copied settings when the context ends. Note that *all* sys.path modifications in the body of the contex

Source from the content-addressed store, hash-verified

236
237
238class DirsOnSysPath(object):
239 """Context manager to temporarily add directories to sys.path.
240
241 This makes a copy of sys.path, appends any directories given
242 as positional arguments, then reverts sys.path to the copied
243 settings when the context ends.
244
245 Note that *all* sys.path modifications in the body of the
246 context manager, including replacement of the object,
247 will be reverted at the end of the block.
248 """
249
250 def __init__(self, *paths):
251 self.original_value = sys.path[:]
252 self.original_object = sys.path
253 sys.path.extend(paths)
254
255 def __enter__(self):
256 return self
257
258 def __exit__(self, *ignore_exc):
259 sys.path = self.original_object
260 sys.path[:] = self.original_value
261
262
263def modules_setup():

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…