-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from Zsailer/extension-loading
Add new extension manager API
- Loading branch information
Showing
23 changed files
with
882 additions
and
452 deletions.
There are no files selected for viewing
This file contains 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,3 @@ | ||
[build-system] | ||
requires = ["jupyter_packaging~=0.5.0", "setuptools>=40.8.0", "wheel"] | ||
build-backend = "setuptools.build_meta" |
This file contains 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 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 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 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,57 @@ | ||
|
||
from jupyter_server.services.config.manager import ConfigManager | ||
|
||
|
||
DEFAULT_SECTION_NAME = "jupyter_server_config" | ||
|
||
|
||
class ExtensionConfigManager(ConfigManager): | ||
"""A manager class to interface with Jupyter Server Extension config | ||
found in a `config.d` folder. It is assumed that all configuration | ||
files in this directory are JSON files. | ||
""" | ||
def get_jpserver_extensions( | ||
self, | ||
section_name=DEFAULT_SECTION_NAME | ||
): | ||
"""Return the jpserver_extensions field from all | ||
config files found.""" | ||
data = self.get(section_name) | ||
return ( | ||
data | ||
.get("ServerApp", {}) | ||
.get("jpserver_extensions", {}) | ||
) | ||
|
||
def enabled( | ||
self, | ||
name, | ||
section_name=DEFAULT_SECTION_NAME, | ||
include_root=True | ||
): | ||
"""Is the extension enabled?""" | ||
extensions = self.get_jpserver_extensions(section_name) | ||
try: | ||
return extensions[name] | ||
except KeyError: | ||
return False | ||
|
||
def enable(self, name): | ||
data = { | ||
"ServerApp": { | ||
"jpserver_extensions": { | ||
name: True | ||
} | ||
} | ||
} | ||
self.update(name, data) | ||
|
||
def disable(self, name): | ||
data = { | ||
"ServerApp": { | ||
"jpserver_extensions": { | ||
name: False | ||
} | ||
} | ||
} | ||
self.update(name, data) |
Oops, something went wrong.