Skip to content

Use Jinja templating for batchspawner_singleuser_cmd  #262

Open
@leonkyneur

Description

@leonkyneur

Proposed change

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

c.Spawner.options_form = """
        <hr>
        <label for=""venv_path">Path to python venv</label>
        <input type="text" name="venv_path" />
"""

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())

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions