mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
fixing copybutton and maybe the integration bug
This commit is contained in:
@@ -17,7 +17,7 @@ def setup(app):
|
|||||||
app.add_javascript("https://cdn.jsdelivr.net/npm/clipboard@1/dist/clipboard.min.js")
|
app.add_javascript("https://cdn.jsdelivr.net/npm/clipboard@1/dist/clipboard.min.js")
|
||||||
|
|
||||||
# Enable MathJax for Math
|
# Enable MathJax for Math
|
||||||
extensions = ['sphinx.ext.mathjax', 'sphinx_copybutton']
|
extensions = ['sphinx.ext.mathjax', 'sphinx_copybutton.sphinx_copybutton']
|
||||||
|
|
||||||
# The master toctree document.
|
# The master toctree document.
|
||||||
master_doc = 'index'
|
master_doc = 'index'
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
|
from ruamel.yaml.comments import CommentedMap, CommentedSeq
|
||||||
yaml = YAML(typ='rt')
|
yaml = YAML(typ='rt')
|
||||||
|
|
||||||
|
|
||||||
@@ -50,13 +51,12 @@ def set_item_in_config(config, property_path, value):
|
|||||||
else:
|
else:
|
||||||
# If we are asked to create new non-leaf nodes, we will always make them dicts
|
# If we are asked to create new non-leaf nodes, we will always make them dicts
|
||||||
# This means setting is *destructive* - will replace whatever is down there!
|
# This means setting is *destructive* - will replace whatever is down there!
|
||||||
if cur_path not in cur_part or not isinstance(cur_part[cur_path], dict):
|
if cur_path not in cur_part or not _is_dict(cur_part[cur_path]):
|
||||||
cur_part[cur_path] = {}
|
cur_part[cur_path] = {}
|
||||||
cur_part = cur_part[cur_path]
|
cur_part = cur_part[cur_path]
|
||||||
|
|
||||||
return config_copy
|
return config_copy
|
||||||
|
|
||||||
|
|
||||||
def add_item_to_config(config, property_path, value):
|
def add_item_to_config(config, property_path, value):
|
||||||
"""
|
"""
|
||||||
Add an item to a list in config.
|
Add an item to a list in config.
|
||||||
@@ -68,7 +68,7 @@ def add_item_to_config(config, property_path, value):
|
|||||||
for i, cur_path in enumerate(path_components):
|
for i, cur_path in enumerate(path_components):
|
||||||
if i == len(path_components) - 1:
|
if i == len(path_components) - 1:
|
||||||
# Final component, it must be a list and we append to it
|
# Final component, it must be a list and we append to it
|
||||||
if cur_path not in cur_part or not isinstance(cur_part[cur_path], list):
|
if cur_path not in cur_part or not _is_list(cur_part[cur_path]):
|
||||||
cur_part[cur_path] = []
|
cur_part[cur_path] = []
|
||||||
cur_part = cur_part[cur_path]
|
cur_part = cur_part[cur_path]
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ def add_item_to_config(config, property_path, value):
|
|||||||
else:
|
else:
|
||||||
# If we are asked to create new non-leaf nodes, we will always make them dicts
|
# If we are asked to create new non-leaf nodes, we will always make them dicts
|
||||||
# This means setting is *destructive* - will replace whatever is down there!
|
# This means setting is *destructive* - will replace whatever is down there!
|
||||||
if cur_path not in cur_part or not isinstance(cur_part[cur_path], dict):
|
if cur_path not in cur_part or not _is_dict(cur_part[cur_path]):
|
||||||
cur_part[cur_path] = {}
|
cur_part[cur_path] = {}
|
||||||
cur_part = cur_part[cur_path]
|
cur_part = cur_part[cur_path]
|
||||||
|
|
||||||
@@ -94,12 +94,12 @@ def remove_item_from_config(config, property_path, value):
|
|||||||
for i, cur_path in enumerate(path_components):
|
for i, cur_path in enumerate(path_components):
|
||||||
if i == len(path_components) - 1:
|
if i == len(path_components) - 1:
|
||||||
# Final component, it must be a list and we append to it
|
# Final component, it must be a list and we append to it
|
||||||
if cur_path not in cur_part or not isinstance(cur_part[cur_path], list):
|
if cur_path not in cur_part or not _is_list(cur_part[cur_path]):
|
||||||
raise ValueError(f'{property_path} is not a list')
|
raise ValueError(f'{property_path} is not a list')
|
||||||
cur_part = cur_part[cur_path]
|
cur_part = cur_part[cur_path]
|
||||||
cur_part.remove(value)
|
cur_part.remove(value)
|
||||||
else:
|
else:
|
||||||
if cur_path not in cur_part or not isinstance(cur_part[cur_path], dict):
|
if cur_path not in cur_part or not _is_dict(cur_part[cur_path]):
|
||||||
raise ValueError(f'{property_path} does not exist in config!')
|
raise ValueError(f'{property_path} does not exist in config!')
|
||||||
cur_part = cur_part[cur_path]
|
cur_part = cur_part[cur_path]
|
||||||
|
|
||||||
@@ -209,6 +209,14 @@ def parse_value(value_str):
|
|||||||
return value_str
|
return value_str
|
||||||
|
|
||||||
|
|
||||||
|
def _is_dict(item):
|
||||||
|
return isinstance(item, (dict, CommentedMap))
|
||||||
|
|
||||||
|
|
||||||
|
def _is_list(item):
|
||||||
|
return isinstance(item, (list, CommentedSeq))
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
if argv is None:
|
if argv is None:
|
||||||
argv = sys.argv[1:]
|
argv = sys.argv[1:]
|
||||||
|
|||||||
Reference in New Issue
Block a user