Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Jinja templating for batchspawner_singleuser_cmd #262

Open
leonkyneur opened this issue Feb 16, 2023 · 1 comment
Open

Use Jinja templating for batchspawner_singleuser_cmd #262

leonkyneur opened this issue Feb 16, 2023 · 1 comment

Comments

@leonkyneur
Copy link

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
Copy link

welcome bot commented Feb 16, 2023

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

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! 👋

Welcome to the Jupyter community! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant