MCPcopy Index your code
hub / github.com/modelscope/modelscope / pushd

Function pushd

modelscope/utils/plugins.py:65–80  ·  view source on GitHub ↗

Changes the current directory to the given path and prepends it to `sys.path`. This method is intended to use with `with`, so after its usage, the current directory will be set to the previous value.

(new_dir: str, verbose: bool = False)

Source from the content-addressed store, hash-verified

63
64@contextmanager
65def pushd(new_dir: str, verbose: bool = False):
66 """
67 Changes the current directory to the given path and prepends it to `sys.path`.
68 This method is intended to use with `with`, so after its usage, the current
69 directory will be set to the previous value.
70 """
71 previous_dir = os.getcwd()
72 if verbose:
73 logger.info(f'Changing directory to {new_dir}') # type: ignore
74 os.chdir(new_dir)
75 try:
76 yield
77 finally:
78 if verbose:
79 logger.info(f'Changing directory back to {previous_dir}')
80 os.chdir(previous_dir)
81
82
83@contextmanager

Callers 3

test_file_pluginsMethod · 0.90
test_custom_pluginsMethod · 0.90
test_all_pluginsMethod · 0.90

Calls 1

infoMethod · 0.80

Tested by 3

test_file_pluginsMethod · 0.72
test_custom_pluginsMethod · 0.72
test_all_pluginsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…