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
| 224 | |
| 225 | |
| 226 | class 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 | |
| 251 | def modules_setup(): |
no outgoing calls