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

Custom python environment support #317

Merged
merged 20 commits into from Nov 14, 2021

Conversation

mbektas
Copy link
Member

@mbektas mbektas commented Oct 29, 2021

Adding basic support for custom Python environment installed on user machine

  • Python environment info is shown on status bar
  • conda and venv are both supported
    • Status bar item has the label as follows: conda: env_name (for conda), venv: env_name (for virtualenv), system: python (for other cases)
    • Hovering on status bar item shows env type and name, python path, python & jupyterlab versions
  • Clicking status bar item launches the environment select dialog
  • Setting is persisted as part of application state
  • At launch time, compatibility of selected python path is checked (including bundled environment, since user can modify it) and if found incompatible, Python path selector dialog is shown with the incompatibility error message.

Status bar item
env-status-bar

Changing environment
change-env

Failed launch due to incompatible environment
python-incompatible

src/main/app.ts Outdated Show resolved Hide resolved
@@ -258,6 +259,7 @@
"@types/semver": "^7.3.4",
"@types/yargs": "^16.0.0",
"bottlejs": "^2.0.0",
"ejs": "^3.1.6",
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking more renderToString style from react-dom (which already is a dependency), but I guess that would work too. I don't think yarn.lock was updated, how much does inclusion of ejs costs us in terms of extra dependencies?

Copy link
Member Author

Choose a reason for hiding this comment

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

ejs was already included through another dependency. I will also check out react-dom renderToString you mentioned.

Copy link
Member Author

Choose a reason for hiding this comment

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

@krassowski I looked into ReactDOMServer.renderToString. it doesn't look like an easy integration for our use case. we generate the HTML of the dialogs on the app backend using node.js. Dialog front-ends are quite basic HTML and JS. We would need to use react for dialog front-ends which would be significant overhead just for sanitize purposes. Also, sanitization would happen on the front-end which may not be as secure as intended.

Please let me know if I missed something and if you see an easier integration of ReactDOMServer.renderToString.

@bollwyvl
Copy link
Contributor

bollwyvl commented Nov 7, 2021

Hm, it looks like my reply was swallowed by the aether (happens), here's a paraphrase:

Strictly from a conda perspective: if the canonical conda activate (or shell-appropriate analog) is not applied, the eventual environment will be inconsistent, creating weird problems.... known offenders include java/clojure, or anything that has a pre-activate script.

Some approaches:

  • dynamically make a shell-appropriate (.sh or .bat) wrapper script that activates and then launches
    • gross, slow...
      • ...but works every time
  • use conda run
    • clean, relatively fast
      • but doesn't work so well with mamba...
        • ...unless the "heavyweight" shell initialization is in place, which has its own problems
        • ...much less venv

At any rate, perhaps an appropriate play is to handle the two incumbent providers explicitly, implemented as the former, and then a Customize Template... which would allow someone to further tweak them, or replace entirely with e.g. nix, vagrant, some docker abomination, etc. (many of which conda would be sufficient to provision, a la as discussed jupyterlab-contrib/jupyterlab-contrib.github.io#23 (comment)

@mbektas
Copy link
Member Author

mbektas commented Nov 8, 2021

At any rate, perhaps an appropriate play is to handle the two incumbent providers explicitly, implemented as the former, and then a Customize Template... which would allow someone to further tweak them, or replace entirely with e.g. nix, vagrant, some docker abomination, etc. (many of which conda would be sufficient to provision, a la as discussed jupyterlab-contrib/jupyterlab-contrib.github.io#23 (comment)

@bollwyvl thanks for bringing this up. conda run looks pretty nice but venv requires a separate solution too. We should go for creating launch scripts that take care of env activation and then launching jlab as you suggested. As far as I could see, our packages in the bundled environment don't have pre-activate/activate scripts and this case seems to be rare. So, I think we can implement launch script generation in another PR.

src/main/app.ts Outdated Show resolved Hide resolved
src/main/app.ts Outdated Show resolved Hide resolved
Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

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.

None yet

3 participants