Skip to content

Commit 52f4cf9

Browse files
authored
Merge overrides settings if values are dicts (#188)
* Merge overrides settings if dicts * test * Pin sphinx version <4 and fix changelog username change * Add tests
1 parent 6ecc630 commit 52f4cf9

File tree

6 files changed

+54
-7
lines changed

6 files changed

+54
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ github_url: 'https://github.com/jupyterlab/jupyterlab_server/blob/master/CHANGEL
9090

9191
## 2.1.5
9292

93-
* Fix/cp949 encoding error [#158](https://github.com/jupyterlab/jupyterlab_server/pull/158) ([@takavfx](https://github.com/takavfx))
93+
* Fix/cp949 encoding error [#158](https://github.com/jupyterlab/jupyterlab_server/pull/158) ([@k-takanori](https://github.com/k-takanori))
9494

9595
## 2.1.4
9696

docs/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ channels:
44
- conda-forge
55
dependencies:
66
- python=3.8
7-
- sphinx>=1.8
7+
- sphinx<4.0
88
- sphinx-copybutton
99
- pip
1010
- myst-parser

jupyterlab_server/settings_handler.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
def _get_schema(schemas_dir, schema_name, overrides, labextensions_path):
2323
"""Returns a dict containing a parsed and validated JSON schema."""
24-
25-
2624
notfound_error = 'Schema not found: %s'
2725
parse_error = 'Failed parsing schema (%s): %s'
2826
validation_error = 'Failed validating schema (%s): %s'
@@ -215,12 +213,18 @@ def _list_settings(schemas_dir, settings_dir, overrides, extension='.json', labe
215213

216214
def _override(schema_name, schema, overrides):
217215
"""Override default values in the schema if necessary."""
218-
219216
if schema_name in overrides:
220217
defaults = overrides[schema_name]
221218
for key in defaults:
222219
if key in schema['properties']:
223-
schema['properties'][key]['default'] = defaults[key]
220+
new_defaults = schema['properties'][key]['default']
221+
# If values for defaults are dicts do a recursive update
222+
if isinstance(new_defaults, dict):
223+
recursive_update(new_defaults.copy(), defaults[key])
224+
else:
225+
new_defaults = defaults[key]
226+
227+
schema['properties'][key]['default'] = new_defaults
224228
else:
225229
schema['properties'][key] = dict(default=defaults[key])
226230

@@ -259,14 +263,17 @@ def _get_overrides(app_settings_dir):
259263
"""Get overrides settings from `app_settings_dir`."""
260264
overrides, error = {}, ""
261265
overrides_path = os.path.join(app_settings_dir, 'overrides.json')
266+
262267
if not os.path.exists(overrides_path):
263268
overrides_path = os.path.join(app_settings_dir, 'overrides.json5')
269+
264270
if os.path.exists(overrides_path):
265271
with open(overrides_path, encoding='utf-8') as fid:
266272
try:
267273
overrides = json5.load(fid)
268274
except Exception as e:
269275
error = e
276+
270277
# Allow `default_settings_overrides.json` files in <jupyter_config>/labconfig dirs
271278
# to allow layering of defaults
272279
cm = ConfigManager(config_dir_name="labconfig")

jupyterlab_server/tests/app-settings/overrides.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"@jupyterlab/apputils-extension:themes": {
3-
"theme": "JupyterLab Dark"
3+
"theme": "JupyterLab Dark",
4+
"codeCellConfig": {
5+
"lineNumbers": false
6+
}
47
},
58
"@jupyterlab/unicode-extension:plugin": {
69
"comment": "Here are some languages with unicode in their names: id: Bahasa Indonesia, ms: Bahasa Melayu, bs: Bosanski, ca: Català, cs: Čeština, da: Dansk, de: Deutsch, et: Eesti, en: English, es: Español, fil: Filipino, fr: Français, it: Italiano, hu: Magyar, nl: Nederlands, no: Norsk, pl: Polski, pt-br: Português (Brasil), pt: Português (Portugal), ro: Română, fi: Suomi, sv: Svenska, vi: Tiếng Việt, tr: Türkçe, el: Ελληνικά, ru: Русский, sr: Српски, uk: Українська, he: עברית, ar: العربية, th: ไทย, ko: 한국어, ja: 日本語, zh: 中文(中国), zh-tw: 中文(台灣)"

jupyterlab_server/tests/schemas/@jupyterlab/apputils-extension/themes.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
"properties": {
55
"theme": {
66
"type": "string", "title": "Selected Theme", "default": "JupyterLab Light"
7+
},
8+
"codeCellConfig": {
9+
"title": "Code Cell Configuration",
10+
"description": "The configuration for all code cells.",
11+
"$ref": "#/definitions/editorConfig",
12+
"default": {
13+
"autoClosingBrackets": true,
14+
"cursorBlinkRate": 530,
15+
"fontFamily": null,
16+
"fontSize": null,
17+
"lineHeight": null,
18+
"lineNumbers": false,
19+
"lineWrap": "off",
20+
"matchBrackets": true,
21+
"readOnly": false,
22+
"insertSpaces": true,
23+
"tabSize": 4,
24+
"wordWrapColumn": 80,
25+
"rulers": [],
26+
"codeFolding": false,
27+
"lineWiseCopyCut": true
28+
}
729
}
830
},
931
"type": "object"

jupyterlab_server/tests/test_settings_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313
from .utils import validate_request
1414

1515

16+
async def test_get_settings_overrides_dicts(jp_fetch, labserverapp):
17+
# Check that values that are dictionaries in overrides.json are
18+
# merged with the schema.
19+
id = '@jupyterlab/apputils-extension:themes'
20+
r = await jp_fetch('lab', 'api', 'settings', id)
21+
validate_request(r)
22+
res = r.body.decode()
23+
data = json.loads(res)
24+
assert data['id'] == id
25+
schema = data['schema']
26+
# Check that overrides.json file is respected.
27+
assert schema['properties']['codeCellConfig']['default']["lineNumbers"] is False
28+
assert len(schema['properties']['codeCellConfig']['default']) == 15
29+
30+
1631
async def test_get_settings(jp_fetch, labserverapp):
1732
id = '@jupyterlab/apputils-extension:themes'
1833
r = await jp_fetch('lab', 'api', 'settings', id)

0 commit comments

Comments
 (0)