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
| 236 | |
| 237 | |
| 238 | class 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 | |
| 263 | def modules_setup(): |
no outgoing calls
searching dependent graphs…