Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #265 from jtpio/settings
Browse files Browse the repository at this point in the history
Ensure `@retrolab` settings
  • Loading branch information
jtpio authored Nov 1, 2021
2 parents 93ce13c + e74bb03 commit 45f879d
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ junit.xml
retrolab/static/*
!retrolab/static/favicons
retrolab/labextension
retrolab/schemas

# playwright
app/test-results
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ conda activate retrolab
# Install package in development mode
pip install -e .

# Link the RetroLab JupyterLab extension
jupyter labextension develop . --overwrite
# Link the RetroLab JupyterLab extension and RetroLab schemas
jlpm develop

# Enable the server extension
jupyter server extension enable retrolab
Expand Down
5 changes: 1 addition & 4 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ async function main() {
),
require('@jupyterlab/docprovider-extension'),
require('@jupyterlab/filebrowser-extension').default.filter(({ id }) =>
[
'@jupyterlab/filebrowser-extension:factory',
'@jupyterlab/filebrowser-extension:download'
].includes(id)
['@jupyterlab/filebrowser-extension:factory'].includes(id)
),
require('@jupyterlab/fileeditor-extension').default.filter(({ id }) =>
['@jupyterlab/fileeditor-extension:plugin'].includes(id)
Expand Down
3 changes: 2 additions & 1 deletion app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ fs.copySync(cssImports, path.resolve(buildDir, 'extraStyle.js'));

const extras = Build.ensureAssets({
packageNames: names,
output: buildDir
output: buildDir,
schemaOutput: path.resolve(__dirname, '..', 'retrolab')
});

/**
Expand Down
4 changes: 2 additions & 2 deletions binder/postBuild
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ set -euo pipefail

jlpm && jlpm run build
python -m pip install -e .
jupyter labextension develop . --overwrite
jlpm run develop
jupyter server extension enable retrolab
jupyter serverextension enable retrolab
jupyter serverextension enable retrolab
51 changes: 51 additions & 0 deletions buildutils/src/develop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* -----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

import commander from 'commander';

import fs from 'fs-extra';

import path from 'path';

import process from 'process';

import { run } from '@jupyterlab/buildutils';

commander
.description('Setup the repository for develop mode')
.option('--overwrite', 'Force linking the RetroLab schemas')
.option('--source', 'The path to the retrolab package')
.action((options: any) => {
const { overwrite } = options;
const prefix = run(
'python -c "import sys; print(sys.prefix)"',
{
stdio: 'pipe'
},
true
);
const source = path.resolve(options.source ?? process.cwd());
const sourceDir = path.join(source, 'retrolab', 'schemas', '@retrolab');
const destDir = path.join(
prefix,
'share',
'jupyter',
'lab',
'schemas',
'@retrolab'
);
if (overwrite) {
try {
fs.unlinkSync(destDir);
console.log('Removed previous symlink:', destDir);
} catch (e) {
console.info('Skip unlinkink', destDir);
}
}
console.log('Symlinking:', sourceDir, destDir);
fs.symlinkSync(sourceDir, destDir, 'dir');
});

commander.parse(process.argv);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"clean": "lerna run clean",
"eslint": "eslint . --ext .ts,.tsx --fix",
"eslint:check": "eslint . --ext .ts,.tsx",
"develop": "jupyter labextension develop . --overwrite && node ./buildutils/lib/develop.js --overwrite",
"install": "lerna bootstrap",
"integrity": "node buildutils/lib/ensure-repo.js",
"prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
Expand Down
3 changes: 2 additions & 1 deletion packages/application-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"access": "public"
},
"jupyterlab": {
"extension": true
"extension": true,
"schemaDir": "schema"
},
"styleModule": "style/index.js"
}
16 changes: 16 additions & 0 deletions packages/application-extension/schema/top.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"jupyter.lab.setting-icon": "retro-ui-components:retroSun",
"jupyter.lab.setting-icon-label": "RetroLab Top Area",
"title": "RetroLab Top Area",
"description": "RetroLab Top Area settings",
"properties": {
"visible": {
"type": "boolean",
"title": "Top Bar Visibility",
"description": "Whether to show the top bar or not",
"default": true
}
},
"additionalProperties": false,
"type": "object"
}
29 changes: 27 additions & 2 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { PromiseDelegate } from '@lumino/coreutils';
import { DisposableDelegate, DisposableSet } from '@lumino/disposable';

import { Widget } from '@lumino/widgets';
import { ISettingRegistry } from '@jupyterlab/settingregistry';

/**
* The default notebook factory.
Expand Down Expand Up @@ -451,20 +452,25 @@ const title: JupyterFrontEndPlugin<void> = {
const topVisibility: JupyterFrontEndPlugin<void> = {
id: '@retrolab/application-extension:top',
requires: [IRetroShell, ITranslator],
optional: [IMainMenu],
optional: [IMainMenu, ISettingRegistry],
activate: (
app: JupyterFrontEnd<JupyterFrontEnd.IShell>,
retroShell: IRetroShell,
translator: ITranslator,
menu: IMainMenu | null
menu: IMainMenu | null,
settingRegistry: ISettingRegistry | null
) => {
const trans = translator.load('retrolab');
const top = retroShell.top;
const pluginId = topVisibility.id;

app.commands.addCommand(CommandIDs.toggleTop, {
label: trans.__('Show Header'),
execute: () => {
top.setHidden(top.isVisible);
if (settingRegistry) {
void settingRegistry.set(pluginId, 'visible', top.isVisible);
}
},
isToggled: () => top.isVisible
});
Expand All @@ -473,6 +479,25 @@ const topVisibility: JupyterFrontEndPlugin<void> = {
menu.viewMenu.addGroup([{ command: CommandIDs.toggleTop }], 2);
}

if (settingRegistry) {
const loadSettings = settingRegistry.load(pluginId);
const updateSettings = (settings: ISettingRegistry.ISettings): void => {
const visible = settings.get('visible').composite as boolean;
top.setHidden(!visible);
};

Promise.all([loadSettings, app.restored])
.then(([settings]) => {
updateSettings(settings);
settings.changed.connect(settings => {
updateSettings(settings);
});
})
.catch((reason: Error) => {
console.error(reason.message);
});
}

const onChanged = (): void => {
if (app.format === 'desktop') {
retroShell.expandTop();
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["jupyter_packaging~=0.10", "jupyterlab>=3.2.0rc0,==3.*"]
requires = ["jupyter_packaging~=0.10", "jupyterlab~=3.2"]
build-backend = "jupyter_packaging.build_api"

[license]
Expand All @@ -17,4 +17,4 @@ build_cmd = "build:prod"
npm = ["jlpm"]

[tool.check-manifest]
ignore = ["app/**", "binder/**", "buildutils/**", "packages/**", "*.json", "yarn.lock", "readthedocs.yml", ".bumpversion.cfg", ".*", "lint-staged.config.js", "logo.*", "retrolab/labextension/**", "retrolab/static/**", "retrolab/template/**"]
ignore = ["app/**", "binder/**", "buildutils/**", "packages/**", "*.json", "yarn.lock", "readthedocs.yml", ".bumpversion.cfg", ".*", "lint-staged.config.js", "logo.*", "retrolab/labextension/**", "retrolab/schemas/**", "retrolab/static/**", "retrolab/template/**"]
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ include_package_data = True
packages = find:
python_requires = >=3.6
install_requires =
jupyterlab>=3.2.0rc0,==3.*
jupyterlab~=3.2
jupyterlab_server~=2.3
jupyter_server~=1.4
nbclassic~=0.2
Expand Down
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
ensured_targets = [
str(lab_extension_dest / "static" / "style.js"),
str(main_bundle_dest / "bundle.js"),
str(HERE / NAME / "schemas/@retrolab/application-extension/package.json.orig"),
]

data_files_spec = [
("share/jupyter/labextensions/%s" % labext_name, str(lab_extension_dest), "**"),
("share/jupyter/labextensions/%s" % labext_name, str(HERE), "install.json"),
("share/jupyter/lab/schemas", f"{NAME}/schemas", "@retrolab/**/*"),
(
"etc/jupyter/jupyter_server_config.d",
"jupyter-config/jupyter_server_config.d",
Expand All @@ -39,13 +41,10 @@
from jupyter_packaging import wrap_installers, npm_builder, get_data_files

# In develop mode, just run yarn
builder = npm_builder(build_cmd='build', npm='jlpm', force=True)
builder = npm_builder(build_cmd="build", npm="jlpm", force=True)
cmdclass = wrap_installers(post_develop=builder, ensured_targets=ensured_targets)

setup_args = dict(
cmdclass=cmdclass,
data_files=get_data_files(data_files_spec)
)
setup_args = dict(cmdclass=cmdclass, data_files=get_data_files(data_files_spec))
except ImportError:
setup_args = dict()

Expand Down

0 comments on commit 45f879d

Please sign in to comment.