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

Class DirsOnSysPath

Lib/test/support/import_helper.py:226–248  ·  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

224
225
226class DirsOnSysPath(object):
227 """Context manager to temporarily add directories to sys.path.
228
229 This makes a copy of sys.path, appends any directories given
230 as positional arguments, then reverts sys.path to the copied
231 settings when the context ends.
232
233 Note that *all* sys.path modifications in the body of the
234 context manager, including replacement of the object,
235 will be reverted at the end of the block.
236 """
237
238 def __init__(self, *paths):
239 self.original_value = sys.path[:]
240 self.original_object = sys.path
241 sys.path.extend(paths)
242
243 def __enter__(self):
244 return self
245
246 def __exit__(self, *ignore_exc):
247 sys.path = self.original_object
248 sys.path[:] = self.original_value
249
250
251def modules_setup():

Calls

no outgoing calls