jupyterhub / batchspawner

Custom Spawner for Jupyterhub to start servers in batch scheduled systems
BSD 3-Clause "New" or "Revised" License
182 stars 131 forks source link

Use Jinja templating for batchspawner_singleuser_cmd #262

Open leonkyneur opened 1 year ago

leonkyneur commented 1 year ago

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())
welcome[bot] commented 1 year ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada: