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

Add support for templated env entries #472

Merged
merged 2 commits into from
Sep 5, 2019

Conversation

kevin-bates
Copy link
Member

I've encountered a number of people (including myself) that would like templated environment variable entries in kernelspecs, so I thought I'd implement it add see if this is something useful to the community.

With this change, kernelspec env entries (or even those clients that set extra_env on the KernelManager instance (along with kernel_cmd)) can reference existing env variables using ${ENV_VAR} within various env entries and expect those substitutions to be performed prior to the kernel's launch.

Here's an example kernelspec env entry:

"env": { 
    "PYTHONPATH": "my_special_python_path:${PYTHONPATH}", 
    "FOO": "BAR", 
    "MY_APP_PATH": "my_bin:${PATH}"
}

Following the kernel's invocation, it's environment will include the following variable/values:

PYTHONPATH=my_special_python_path:<notebook server's PYTHONPATH>
FOO=BAR
MY_APP_PATH=my_bin:<notebook server's PATH>

If the templated env variable is not in the launching environment, the templated value will remain in place - just as it shows in the kernelspec's kernel.json file.

Kernelspec administrators should be cognizant of potential to share environments. However, given that's case currently, this shouldn't introduce any new issues.

This change tolerates the existence of templated entries where the
templated value corresponds to an existing environment variable.
In such cases, those templated values will be substituted prior to
the kernel's launch.
@blink1073
Copy link
Contributor

👍 for this idea, thanks for proposing it!

@blink1073
Copy link
Contributor

I think a note and warning to admins here would do the trick.

@kevin-bates kevin-bates changed the title Add support for templated env entries [WIP] Add support for templated env entries Aug 31, 2019
@kevin-bates
Copy link
Member Author

Excellent idea Steven - thank you. I've placed this PR into WIP status since it might be a couple days before I get back to this. Doc updates slipped my mind - thanks again.

@kevin-bates kevin-bates changed the title [WIP] Add support for templated env entries Add support for templated env entries Sep 3, 2019
Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll leave this open for another day in case anyone has objections.

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

Successfully merging this pull request may close these issues.

2 participants