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

Modify the custom Python kernel #2049

Closed

Conversation

benz0li
Copy link
Contributor

@benz0li benz0li commented Dec 5, 2023

  • to activate the custom environment
  • for the respective Jupyter Notebook and Jupyter Console

Issue ticket if applicable

Properly fix #2047. Prevent #2047 (comment).

Checklist (especially for first-time contributors)

  • I have performed a self-review of my code
  • If it is a core feature, I have added thorough tests
  • I will try not to use force-push to make the review process easier for reviewers
  • I have updated the documentation for significant changes

- to activate the custom environment
- for the respective Jupyter Notebook and Jupyter Console
@benz0li
Copy link
Contributor Author

benz0li commented Dec 5, 2023

@mathbunnyru Please review.

@benz0li
Copy link
Contributor Author

benz0li commented Dec 5, 2023

env variables are identical for IPython (started from JupyterLab Terminal after executing conda activate python310) and Jupyter Notebook/Console for 'python310'.
👉 This is not the case for Terminal related env variables, though.

Cross reference: #2047 (comment)

# Uncomment this section to activate custom environment by default
# This changes the custom Python kernel so that the custom environment will
# be activated for the respective Jupyter Notebook and Jupyter Console
RUN sed -i.bak ":a;N;\$!ba;s| }\n}| },\n \"env\": {\n \"XML_CATALOG_FILES\": \"\",\n \"PATH\": \"${CONDA_DIR}/envs/${env_name}/bin:\$PATH\",\n \"CONDA_PREFIX\": \"${CONDA_DIR}/envs/${env_name}\",\n \"CONDA_PROMPT_MODIFIER\": \"\(${env_name}\) \",\n \"CONDA_SHLVL\": \"2\",\n \"CONDA_DEFAULT_ENV\": \"${env_name}\",\n \"CONDA_PREFIX_1\": \"${CONDA_DIR}\"\n }\n}|g" "/home/${NB_USER}/.local/share/jupyter/kernels/${env_name}/kernel.json"
Copy link
Member

Choose a reason for hiding this comment

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

May I ask you to rewrite this in Python?
It's so difficult to read and understand.
You can write inline multiline Python using heredoc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am no Python guy...

diff /home/${NB_USER}/.local/share/jupyter/kernels/python310/kernel.json.bak /home/${NB_USER}/.local/share/jupyter/kernels/python310/kernel.json
12a13,21
>  },
>  "env": {
>   "XML_CATALOG_FILES": "",
>   "PATH": "/opt/conda/envs/python310/bin:$PATH",
>   "CONDA_PREFIX": "/opt/conda/envs/python310",
>   "CONDA_PROMPT_MODIFIER": "(python310) ",
>   "CONDA_SHLVL": "2",
>   "CONDA_DEFAULT_ENV": "python310",
>   "CONDA_PREFIX_1": "/opt/conda"

Using ${CONDA_DIR} instead /opt/conda and ${env_name} instead of python310 with the sed command.

@mathbunnyru
Copy link
Member

👉 This is not the case for Terminal related env variables, though.

What is different?

@benz0li
Copy link
Contributor Author

benz0li commented Dec 5, 2023

👉 This is not the case for Terminal related env variables, though.

What is different?

<         'TERM': 'xterm-256color',
---
>         'TERM': 'xterm-color',
<         'SHLVL': '1',
---
>         'SHLVL': '0',
<         [unrelated]
---
>         'CLICOLOR': '1',
>         'FORCE_COLOR': '1',
>         'CLICOLOR_FORCE': '1',
>         'PAGER': 'cat',
>         'GIT_PAGER': 'cat',

among others.

@@ -3,3 +3,4 @@ ignored:
- DL3006
- DL3008
- DL3013
- DL3059
Copy link
Member

@mathbunnyru mathbunnyru Dec 5, 2023

Choose a reason for hiding this comment

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

@benz0li
Copy link
Contributor Author

benz0li commented Dec 5, 2023

It is better you create a new pull request on your own, then.

I.e. rewrite in Python and decide where to place the hadolint rule.

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