| 1 |
# (C) Copyright 2007-2025 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
""" Utilities for supporting Envisage's demo examples. |
| 11 |
""" |
| 12 |
|
| 13 |
import contextlib |
| 14 |
import os |
| 15 |
import sys |
| 16 |
|
| 17 |
|
| 18 |
@contextlib.contextmanager |
| 19 |
def demo_path(path): |
| 20 |
"""Context manager to temporarily insert the directory containing |
| 21 |
the demo script to sys.path such that demo examples can be run using |
| 22 |
local packages. |
| 23 |
|
| 24 |
This function should only be used by Envisage example files. |
| 25 |
|
| 26 |
Parameters |
| 27 |
---------- |
| 28 |
path : Path-like |
| 29 |
Path to the demo script to be run. |
| 30 |
""" |
| 31 |
path = os.path.dirname(os.fspath(path)) |
| 32 |
try: |
| 33 |
sys.path.insert(0, path) |
| 34 |
yield |
| 35 |
finally: |
| 36 |
sys.path.remove(path) |