Skip to content

Commit

Permalink
Merge pull request #127 from afshin/dynamic-to-federated
Browse files Browse the repository at this point in the history
dynamic => federated
  • Loading branch information
afshin authored Sep 21, 2020
2 parents 1dcf71f + 2b0c97b commit 1b999ac
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
26 changes: 13 additions & 13 deletions jupyterlab_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
DEFAULT_TEMPLATE_PATH = osp.join(osp.dirname(__file__), 'templates')


def get_dynamic_extensions(labextensions_path):
"""Get the metadata about dynamic extensions
def get_federated_extensions(labextensions_path):
"""Get the metadata about federated extensions
"""
dynamic_exts = dict()
federated_exts = dict()
for ext_dir in labextensions_path:
ext_pattern = ext_dir + '/**/package.json'
for ext_path in [path for path in glob(ext_pattern, recursive=True)]:
with open(ext_path) as fid:
data = json.load(fid)
if data['name'] not in dynamic_exts:
if data['name'] not in federated_exts:
data['ext_dir'] = ext_dir
data['ext_path'] = osp.dirname(ext_path)
data['is_local'] = False
dynamic_exts[data['name']] = data
return dynamic_exts
federated_exts[data['name']] = data
return federated_exts


def get_static_page_config(app_settings_dir=None, logger=None):
Expand Down Expand Up @@ -75,13 +75,13 @@ def get_page_config(labextensions_path, app_settings_dir=None, logger=None):
"""Get the page config for the application"""
page_config = get_static_page_config(app_settings_dir=app_settings_dir, logger=logger)

# Handle dynamic extensions
extensions = page_config['dynamic_extensions'] = []
# Handle federated extensions
extensions = page_config['federated_extensions'] = []
disabled_by_extensions_all = dict()

dynamic_exts = get_dynamic_extensions(labextensions_path)
federated_exts = get_federated_extensions(labextensions_path)

for (ext, ext_data) in dynamic_exts.items():
for (ext, ext_data) in federated_exts.items():
if not 'jupyterlab' in ext_data or not '_build' in ext_data['jupyterlab']:
logger.warn('%s is not a valid extension' % ext_data['name'])
continue
Expand Down Expand Up @@ -136,10 +136,10 @@ class LabConfig(HasTraits):
app_settings_dir = Unicode('', help='The application settings directory.')

extra_labextensions_path = List(Unicode(),
help="""Extra paths to look for dynamic JupyterLab extensions"""
help="""Extra paths to look for federated JupyterLab extensions"""
)

labextensions_path = List(Unicode(), help='The standard paths to look in for dynamic JupyterLab extensions')
labextensions_path = List(Unicode(), help='The standard paths to look in for federated JupyterLab extensions')

templates_dir = Unicode('', help='The application templates directory.')

Expand All @@ -149,7 +149,7 @@ class LabConfig(HasTraits):
'added.'))


labextensions_url = Unicode('', help='The url for dynamic JupyterLab extensions')
labextensions_url = Unicode('', help='The url for federated JupyterLab extensions')

settings_url = Unicode(help='The url path of the settings handler.')

Expand Down
2 changes: 1 addition & 1 deletion jupyterlab_server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def add_handlers(handlers, extension_app):
# Cache all or none of the files depending on the `cache_files` setting.
no_cache_paths = [] if extension_app.cache_files else ['/']

# Handle dynamic lab extensions.
# Handle federated lab extensions.
labextensions_path = extension_app.extra_labextensions_path + extension_app.labextensions_path
labextensions_url = ujoin(extension_app.labextensions_url, "(.*)")
handlers.append(
Expand Down
2 changes: 1 addition & 1 deletion jupyterlab_server/listings_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tornado handlers for dynamic listings loading."""
"""Tornado handlers for listing extensions."""

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
Expand Down
4 changes: 2 additions & 2 deletions jupyterlab_server/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def _make_labserver_extension_app(**kwargs):
shutil.rmtree(dst)
shutil.copytree(src, dst)

# Create the dynamic extensions
# Create the federated extensions
for name in ['apputils-extension', 'codemirror-extension']:
target_name = name + '-dynamic'
target_name = name + '-federated'
target = pjoin(str(labextensions_dir), '@jupyterlab', target_name)
src = pjoin(
os.path.abspath(os.path.dirname(__file__)),
Expand Down
12 changes: 6 additions & 6 deletions jupyterlab_server/settings_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _list_settings(schemas_dir, settings_dir, overrides, extension='.json', labe
"""

settings = {}
dynamic_settings = {}
federated_settings = {}
warnings = []

if not os.path.exists(schemas_dir):
Expand Down Expand Up @@ -191,8 +191,8 @@ def _list_settings(schemas_dir, settings_dir, overrides, extension='.json', labe
schema_base[:-len(extension)] # Remove file extension.
]).replace('\\', '/') # Normalize slashes.

# bail if we've already handled the highest dynamic setting
if id in dynamic_settings:
# bail if we've already handled the highest federated setting
if id in federated_settings:
continue

schema, version = _get_schema(schemas_dir, schema_name, overrides, labextensions_path=labextensions_path)
Expand All @@ -202,14 +202,14 @@ def _list_settings(schemas_dir, settings_dir, overrides, extension='.json', labe
warnings.append(user_settings.pop('warning'))

# Add the plugin to the list of settings.
dynamic_settings[id] = dict(
federated_settings[id] = dict(
id=id,
schema=schema,
version=version,
**user_settings
)

settings.update(dynamic_settings)
settings.update(federated_settings)
settings_list = [settings[key] for key in sorted(settings.keys(), reverse=True)]

return (settings_list, warnings)
Expand Down Expand Up @@ -293,7 +293,7 @@ def get_settings(app_settings_dir, schemas_dir, settings_dir, schema_name="", ov
Settings overrides. If not provided, the overrides will be loaded
from the `app_settings_dir`. Default is None.
labextensions_path: list, optional
List of paths to dynamic labextensions containing their own schema files.
List of paths to federated labextensions containing their own schema files.
Returns
-------
Expand Down
8 changes: 4 additions & 4 deletions jupyterlab_server/tests/test_settings_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ async def test_get(fetch, labserverapp):
assert 'raw' in res


async def test_get_dynamic(fetch, labserverapp):
id = '@jupyterlab/apputils-extension-dynamic:themes'
async def test_get_federated(fetch, labserverapp):
id = '@jupyterlab/apputils-extension-federated:themes'
r = await fetch('lab', 'api', 'settings', id)
assert r.code == 200
res = r.body.decode()
Expand All @@ -40,9 +40,9 @@ async def test_get_bad(fetch, labserverapp):
async def test_listing(fetch, labserverapp):
ids = [
'@jupyterlab/apputils-extension:themes',
'@jupyterlab/apputils-extension-dynamic:themes',
'@jupyterlab/apputils-extension-federated:themes',
'@jupyterlab/codemirror-extension:commands',
'@jupyterlab/codemirror-extension-dynamic:commands',
'@jupyterlab/codemirror-extension-federated:commands',
'@jupyterlab/shortcuts-extension:plugin',
'@jupyterlab/translation-extension:plugin',
'@jupyterlab/unicode-extension:plugin'
Expand Down

0 comments on commit 1b999ac

Please sign in to comment.