-
Notifications
You must be signed in to change notification settings - Fork 5
PR: Add jupyter-server extension for remote development support #35
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bfab1ea
feat: add jupyter server extension app
hlouzada 9681ac4
fix: typing error on ManagerActions
hlouzada 89e3e7b
feat: add default jupyter config and configure jupyter-server dependency
hlouzada ad7aa3e
fix: use enum instead of typing list
hlouzada 6b51f22
fix: get handler actions from enum
hlouzada 13c5abe
fix: get default configuration from proper section
hlouzada cfad81b
feat: add error handling
hlouzada eb2b30e
fix: add jupyter server missing extensions point
hlouzada 0b91ea5
feat: set jupyter-server as optional dependency
hlouzada 9d9f195
fix: add missing module header
hlouzada 21ed253
feat: add action to create kernels specs
hlouzada 406c915
refac: apply formatter
hlouzada 7a47724
refac: remove unnecessary comment
hlouzada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| # SPDX-FileCopyrightText: 2022-present Spyder Development Team and envs-manager contributors | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
|
|
||
| def _jupyter_server_extension_points(): | ||
| """ | ||
| Returns a list of dictionaries with metadata describing | ||
| where to find the `_load_jupyter_server_extension` function. | ||
| """ | ||
| from envs_manager.jupyter import EnvManagerApp | ||
|
|
||
| return [{"module": "envs_manager.jupyter", "app": EnvManagerApp}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # SPDX-FileCopyrightText: 2022-present Spyder Development Team and envs-manager contributors | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| from __future__ import annotations | ||
| import json | ||
| import typing as t | ||
|
|
||
| from traitlets import Unicode | ||
| from tornado import web | ||
| from jupyter_server.auth.decorator import authorized | ||
| from jupyter_server.extension.application import ExtensionApp | ||
| from jupyter_server.base.handlers import JupyterHandler | ||
|
|
||
| from envs_manager.manager import ( | ||
| DEFAULT_BACKENDS_ROOT_PATH, | ||
| DEFAULT_BACKEND, | ||
| Manager, | ||
| ManagerActions, | ||
| ) | ||
|
|
||
|
|
||
| class EnvManagerHandler(JupyterHandler): | ||
| """Handler to list available environments.""" | ||
|
|
||
| _handler_action_regex = ( | ||
| rf"(?P<action>{'|'.join(action.value for action in ManagerActions)})" | ||
| ) | ||
|
|
||
| auth_resource = "envs_manager" | ||
|
|
||
| def get_manager(self) -> Manager: | ||
| """Get the environment manager instance.""" | ||
| return Manager( | ||
| backend=self.get_argument("backend", None) | ||
| or self.settings["envs_manager_config"]["default_backend"], | ||
| root_path=self.settings["envs_manager_config"]["root_path"], | ||
| env_name=self.get_argument("env_name", None), | ||
| env_directory=self.get_argument("env_directory", None), | ||
| ) | ||
|
|
||
| def get_options(self) -> dict[str, t.Any]: | ||
| return self.get_json_body() or {} | ||
|
|
||
| def write_json(self, data, status=200): | ||
| self.set_status(status) | ||
| self.set_header("Content-Type", "application/json") | ||
| self.finish(json.dumps(data)) | ||
|
|
||
| @authorized | ||
| @web.authenticated | ||
| def post(self, action: str): | ||
| try: | ||
| manager = self.get_manager() | ||
| action_options = self.get_options() | ||
| self.write_json( | ||
| manager.run_action(ManagerActions(action), action_options), | ||
| status=200, | ||
| ) | ||
| except Exception as e: | ||
| self.set_status(501) | ||
| self.finish(str(e)) | ||
| self.log_exception(type(e), e, e.__traceback__) | ||
|
|
||
|
|
||
| class EnvManagerApp(ExtensionApp): | ||
| """Jupyter extension for managing environments.""" | ||
|
|
||
| name = "envs_manager" | ||
| extension_url = "/envs_manager" | ||
| open_browser = False | ||
|
|
||
| root_path = Unicode( | ||
| str(DEFAULT_BACKENDS_ROOT_PATH), | ||
| config=True, | ||
| help="Root path for the extension. Defaults to the Jupyter server root path.", | ||
| ) | ||
|
|
||
| default_backend = Unicode( | ||
| DEFAULT_BACKEND, | ||
| config=True, | ||
| help="Default backend to use for managing environments.", | ||
| ) | ||
|
|
||
| handlers = [ | ||
| ( | ||
| rf"{extension_url}/{EnvManagerHandler._handler_action_regex}", | ||
| EnvManagerHandler, | ||
| ), | ||
| ] # type: ignore[list-item] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "ServerApp": { | ||
| "jpserver_extensions": { | ||
| "envs_manager": true | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.