MCPcopy Create free account
hub / github.com/ipython/ipython / prepended_to_syspath

Class prepended_to_syspath

IPython/utils/syspathcontext.py:42–62  ·  view source on GitHub ↗

A context for prepending a directory to sys.path for a second.

Source from the content-addressed store, hash-verified

40 return False
41
42class prepended_to_syspath(object):
43 """A context for prepending a directory to sys.path for a second."""
44
45 def __init__(self, dir):
46 self.dir = dir
47
48 def __enter__(self):
49 if self.dir not in sys.path:
50 sys.path.insert(0,self.dir)
51 self.added = True
52 else:
53 self.added = False
54
55 def __exit__(self, type, value, traceback):
56 if self.added:
57 try:
58 sys.path.remove(self.dir)
59 except ValueError:
60 pass
61 # Returning False causes any exceptions to be re-raised.
62 return False

Callers 10

load_extensionMethod · 0.90
reload_extensionMethod · 0.90
safe_execfileMethod · 0.90
safe_execfile_ipyMethod · 0.90
test_extension_loadingFunction · 0.90
test_extension_builtinsFunction · 0.90
test_changing_py_fileMethod · 0.90
test_nonascii_pathMethod · 0.90
test_iso8859_5Method · 0.90
test_deepreloadFunction · 0.90

Calls

no outgoing calls

Tested by 6

test_extension_loadingFunction · 0.72
test_extension_builtinsFunction · 0.72
test_changing_py_fileMethod · 0.72
test_nonascii_pathMethod · 0.72
test_iso8859_5Method · 0.72
test_deepreloadFunction · 0.72