Last active
October 14, 2022 13:20
-
-
Save bmorris3/fecb8b6bda475ddcdf34df7b337f2c75 to your computer and use it in GitHub Desktop.
Voila template help for @rosteen, related issue: spacetelescope/jdaviz#1729
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
from glob import glob | |
prefix_targets = [ | |
"nbconvert/templates", | |
"voila/templates", | |
] | |
def user_dir(): | |
homedir = os.path.expanduser('~') | |
# Next line will make things work even when /home/ is a symlink to | |
# /usr/home as it is on FreeBSD, for example | |
homedir = os.path.realpath(homedir) | |
if sys.platform == 'darwin': | |
return os.path.join(homedir, 'Library', 'Jupyter') | |
elif os.name == 'nt': | |
appdata = os.environ.get('APPDATA', None) | |
if appdata: | |
return os.path.join(appdata, 'jupyter') | |
else: | |
return os.path.join(jupyter_config_dir(), 'data') | |
else: | |
# Linux, non-OS X Unix, AIX, etc. | |
import pathlib | |
env = os.environ | |
home = pathlib.Path.home().as_posix() | |
xdg = env.get("XDG_DATA_HOME", None) | |
if not xdg: | |
xdg = os.path.join(home, '.local', 'share') | |
return os.path.join(xdg, 'jupyter') | |
target_dir = os.path.join(sys.prefix, 'share', 'jupyter') | |
for name, target_dir in [ | |
("user dir", user_dir()), | |
("env-specific jupyter dir", os.path.join(target_dir)) | |
]: | |
for prefix_target in prefix_targets: | |
source = os.path.join('share', 'jupyter', prefix_target) | |
target = os.path.join(target_dir, prefix_target) | |
target_subdir = os.path.dirname(target) | |
available_subdirs = glob(os.path.join(target_subdir, '*', '*')) | |
print(f"templates available within {name} '{target}':\n{[os.path.basename(p) for p in available_subdirs if os.path.isdir(p)]}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment