Add explicit path to spawner and singleuser commands

This commit is contained in:
Benoît Seignovert 2024-03-18 17:57:20 +01:00
parent 7792d567f5
commit 6af885f148
Signed by: Benoît Seignovert
GPG key ID: F5D8895227D18A0B
2 changed files with 28 additions and 1 deletions

View file

@ -2,6 +2,8 @@
import asyncio
import re
import sys
from pathlib import Path
from batchspawner import JobStatus, SlurmSpawner
from traitlets import Bool, Integer, Unicode, default
@ -11,6 +13,8 @@ from .micromamba import MAMBA_EXE, MAMBA_ROOT_PREFIX
from .progress import ElapseTime, get_progress
from .templates import get_template_src
SPAWNER_BIN = Path(sys.exec_prefix) / 'bin'
class GlicidSpawner(SlurmSpawner):
"""Glicid SLURM Spawner."""
@ -60,6 +64,20 @@ class GlicidSpawner(SlurmSpawner):
"""The URL the single-user server should start in."""
return '/lab/tree' + self.user_options.get('workdir', '/home/{username}') + '?reset'
def cmd_formatted_for_batch(self):
"""The command which is substituted inside of the batch script.
Here we need the absolute path to the spawner and singleuser commands.
"""
return ' '.join(
[
str(SPAWNER_BIN / self.batchspawner_singleuser_cmd),
str(SPAWNER_BIN / self.cmd[0]),
*self.get_args(),
]
)
slurm_job_id_re = Unicode(r'(\d+)(?:;(\w+))?').tag(config=True)
def parse_job_id(self, output):

View file

@ -1,5 +1,6 @@
"""Test GLiCID spawner module."""
import re
from collections import namedtuple
from itertools import repeat
@ -22,6 +23,10 @@ def test_spawner_config():
assert spawner.batchspawner_singleuser_cmd == 'glicid-spawner-singleuser'
cmd = spawner.cmd_formatted_for_batch()
assert 'bin/glicid-spawner-singleuser' in cmd
assert 'bin/jupyterhub-singleuser' in cmd
assert spawner.req_mamba_root_prefix == '/micromamba/operator'
assert spawner.req_mamba_exe == '/micromamba/operator/bin/micromamba'
assert spawner.req_job_name == 'jupyterhub_glicid'
@ -49,7 +54,9 @@ def test_spawner_batch_script(monkeypatch):
)
script = format_template(
spawner.batch_script, **(spawner.get_req_subvars() | spawner.user_options)
spawner.batch_script,
cmd=spawner.cmd_formatted_for_batch(),
**(spawner.get_req_subvars() | spawner.user_options),
)
assert '#SBATCH --job-name=jupyterhub_glicid' in script
@ -65,6 +72,8 @@ def test_spawner_batch_script(monkeypatch):
assert 'export MAMBA_ROOT_PREFIX=/micromamba/operator;' in script
assert 'micromamba activate /micromamba/john-doe/envs/foo;' in script
assert re.search(r'.*/bin/glicid-spawner-singleuser .*/bin/jupyterhub-singleuser', script)
def test_spawner_parse_job_id():
"""Test spawner job id parser."""