jupyterhub / jupyterhub/batchspawner

Use Jinja templating for batchspawner_singleuser_cmd

Open
#262 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
207
Forks
136
PR merge metrics
No merged PRs in 30d

Description

### Proposed change
occationally it would be nice to be able parse values from an options_form into my batchspawner commands

```
c.Spawner.options_form = """



Path to python venv

"""

c.BatchSpawnerBase.batchspawner_singleuser_cmd = 'singularity run --nv {% if venv_path %} --env PYTHON_VENV_PATH={{venv_path}} -B {{venv_path}}:{{venv_path}}{% endif %} base.sif'

```

There doesn't seem to be any way for this kind of thing to be functional as `format_template` is never run for these values.

### Alternative options

Alternatively this could probably be achived using spawner args?

or not using batchspawner_singleuser_cmd and placing the command inside the batch script? (though not sure if this works when trying to convey the port back to jupyterhub).

### Who would use this feature?

Anyone trying to parse user options and arguments to their batchspawner commands.

### (Optional): Suggest a solution

This is what I have used to overcome this limitation.

```
def cmd_formatted_for_batch(self):
"""The command which is substituted inside of the batch script"""
subvars = self.get_req_subvars()
if hasattr(self, 'user_options'):
subvars.update(self.user_options)
return ' '.join([format_template(self.batchspawner_singleuser_cmd, **subvars)] + self.cmd + self.get_args())
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.