viv/examples/sys_path.py

34 lines
779 B
Python
Raw Normal View History

2022-12-19 23:22:23 -06:00
#!/usr/bin/env python3
"""
Embed the viv.py on the sys.path at runtime rather than using PYTHONPATH
"""
2023-08-21 00:59:23 -05:00
import sys
old_sys_path = sys.path.copy() # noqa
2022-12-19 23:22:23 -06:00
__import__("sys").path.append(__import__("os").path.expanduser("~/.local/share/viv")) # noqa # isort: off
2023-08-21 00:59:23 -05:00
__import__("viv").use("rich") # noqa # isort: off
2022-12-19 23:22:23 -06:00
2023-08-21 00:59:23 -05:00
from difflib import unified_diff
2022-12-19 23:22:23 -06:00
2023-08-21 00:59:23 -05:00
from rich import print
from rich.syntax import Syntax
2022-12-19 23:22:23 -06:00
2023-08-21 00:59:23 -05:00
print("[bold italic yellow] Modified Sys.path")
print(
Syntax(
"\n".join(
unified_diff(
2023-08-21 12:21:35 -05:00
old_sys_path,
sys.path,
"pre-viv sys.path",
"post-viv sys.path",
n=max(map(len, (old_sys_path, sys.path))),
2023-08-21 00:59:23 -05:00
)
),
"diff",
theme="default",
)
)