List only micromamba environments with jupyter kernel(s)
This commit is contained in:
parent
c4c8fa33aa
commit
1a7f5f102f
8 changed files with 49 additions and 17 deletions
|
@ -7,7 +7,6 @@ from pathlib import Path
|
|||
MICROMAMBA_ROOT = Path('/micromamba') # default micromamba root location
|
||||
|
||||
GLOBAL_USER = 'operator'
|
||||
GLOBAL_EXCLUDED = 'glicid-jupyterhub'
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -19,15 +18,9 @@ class MicromambaEnv:
|
|||
path: str
|
||||
|
||||
|
||||
def _envs(folder, excluded=None) -> list:
|
||||
"""List micromamba environments."""
|
||||
# Convert excluded as as list
|
||||
if excluded is None:
|
||||
excluded = []
|
||||
elif isinstance(excluded, str):
|
||||
excluded = [excluded]
|
||||
|
||||
# Get micromamba envs as pathlib.Path
|
||||
def _envs(folder) -> list:
|
||||
"""List micromamba environments with jupyter kernel(s)."""
|
||||
# Get micromamba environments as pathlib.Path folders
|
||||
envs = MICROMAMBA_ROOT / folder / 'envs'
|
||||
|
||||
if not envs.exists():
|
||||
|
@ -37,7 +30,7 @@ def _envs(folder, excluded=None) -> list:
|
|||
[
|
||||
(env.name, str(env))
|
||||
for env in envs.iterdir()
|
||||
if env.is_dir() and env.name not in excluded
|
||||
if env.is_dir() and any(env.glob('share/jupyter/kernels/*/kernel.json'))
|
||||
],
|
||||
key=itemgetter(0),
|
||||
)
|
||||
|
@ -64,10 +57,7 @@ def _envs_team(username: str) -> list:
|
|||
|
||||
def _envs_global() -> list:
|
||||
"""Micromamba environment(s) available globally."""
|
||||
return [
|
||||
MicromambaEnv('GLOBAL', name, path)
|
||||
for name, path in _envs(GLOBAL_USER, excluded=GLOBAL_EXCLUDED)
|
||||
]
|
||||
return [MicromambaEnv('GLOBAL', name, path) for name, path in _envs(GLOBAL_USER)]
|
||||
|
||||
|
||||
def get_envs(username: str) -> list:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue