Skip to content

Commit f03e5a8

Browse files
LuanEdCostaFabio Beranizo
and
Fabio Beranizo
authored
Feature - Update Extension Version (#28)
* Update dependencies and fix typescript and eslint errors * Change apputils and services to use local dependencies and update code to change the session context server settings * Replaces relative paths apputils/services by a link to tarball * Make the extension works with the new version of jupyterlab * Remove unnecessary jupyter notebook file * Clean code and fix some errors with promises * Try to reconnect if kernel change fails * Remove unnecessary jupyter notebook file * Set appendToken in the remote settings * Create /tmp/data directory to upload dataset * Use branch name instead of commit hash for the apputils and services dependencies * 0.2.0 * Remove unnecessary commented line from install_requires inside setup.py file * Recreate yarn.lock * Remove unnecessary createSession function Co-authored-by: Fabio Beranizo <[email protected]>
1 parent 6a5786a commit f03e5a8

15 files changed

+1507
-1598
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist
33
coverage
44
**/*.d.ts
55
tests
6+
lib

.eslintrc.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
module.exports = {
2+
env: {
3+
node: true,
4+
},
25
extends: [
36
'eslint:recommended',
47
'plugin:@typescript-eslint/eslint-recommended',
58
'plugin:@typescript-eslint/recommended',
6-
'plugin:prettier/recommended'
9+
'plugin:prettier/recommended',
710
],
811
parser: '@typescript-eslint/parser',
912
parserOptions: {
10-
project: 'tsconfig.json',
11-
sourceType: 'module'
13+
sourceType: 'module',
1214
},
1315
plugins: ['@typescript-eslint'],
1416
rules: {
15-
'@typescript-eslint/interface-name-prefix': [
16-
'error',
17-
{ prefixWithI: 'always' }
18-
],
17+
'@typescript-eslint/interface-name-prefix': 'off',
1918
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
2019
'@typescript-eslint/no-explicit-any': 'off',
2120
'@typescript-eslint/no-namespace': 'off',
2221
'@typescript-eslint/no-use-before-define': 'off',
2322
'@typescript-eslint/quotes': [
2423
'error',
2524
'single',
26-
{ avoidEscape: true, allowTemplateLiterals: false }
25+
{ avoidEscape: true, allowTemplateLiterals: false },
2726
],
2827
curly: ['error', 'all'],
2928
eqeqeq: 'error',
30-
'prefer-arrow-callback': 'error'
31-
}
29+
'prefer-arrow-callback': 'error',
30+
},
3231
};

jupyterlab_extension/services.py

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def generate_name(filename: str, attempt: int = 1, path: str = "/tmp/data") -> s
8282
name = f"{name}-{attempt}{extension}"
8383

8484
try:
85+
os.makedirs("/tmp/data", exist_ok=True)
8586
open(f"{path}/{name}")
8687
except FileNotFoundError:
8788
return name
@@ -103,6 +104,7 @@ def create_dataset_locally(file: bytes, filename: str = "file", name: str = "fil
103104
"""
104105

105106
try:
107+
os.makedirs("/tmp/data", exist_ok=True)
106108
with open(f"{path}/{name}", 'wb') as csv_file:
107109
csv_file.write(file)
108110

package.json

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@platiagro/jupyterlab-extension",
3-
"version": "0.0.1",
3+
"version": "0.2.0",
44
"description": "A JupyterLab extension that connects to PlatIAgro.",
55
"keywords": [
66
"jupyter",
@@ -39,28 +39,28 @@
3939
"watch": "tsc -w"
4040
},
4141
"dependencies": {
42-
"@jupyterlab/application": "^2.0.0",
43-
"@jupyterlab/apputils": "https://github.com/platiagro/jupyterlab/releases/download/v0.2.0platiagro-v2.1.2/jupyterlab-apputils-2.1.1.tgz",
44-
"@jupyterlab/coreutils": "^4.0.0",
45-
"@jupyterlab/docregistry": "^2.1.2",
46-
"@jupyterlab/mainmenu": "^2.1.1",
47-
"@jupyterlab/notebook": "^2.1.2",
48-
"@jupyterlab/services": "https://github.com/platiagro/jupyterlab/releases/download/v0.2.0platiagro-v2.1.2/jupyterlab-services-5.1.0.tgz",
49-
"@jupyterlab/ui-components": "^2.1.1",
50-
"@lumino/disposable": "^1.3.6",
51-
"@lumino/widgets": "^1.12.2"
42+
"@jupyterlab/application": "^3.0.11",
43+
"@jupyterlab/apputils": "https://github.com/platiagro/jupyterlab/raw/v0.2.0-jupyterlab-v3.0.16/packages/apputils/jupyterlab-apputils-v3.0.9.tgz",
44+
"@jupyterlab/coreutils": "^5.0.6",
45+
"@jupyterlab/docregistry": "^3.0.11",
46+
"@jupyterlab/mainmenu": "^3.0.9",
47+
"@jupyterlab/notebook": "^3.0.11",
48+
"@jupyterlab/services": "https://github.com/platiagro/jupyterlab/raw/v0.2.0-jupyterlab-v3.0.16/packages/services/jupyterlab-services-v6.0.9.tgz",
49+
"@jupyterlab/ui-components": "^3.0.7",
50+
"@lumino/disposable": "^1.7.0",
51+
"@lumino/widgets": "^1.23.0"
5252
},
5353
"devDependencies": {
54-
"@types/node": "^14.14.5",
55-
"@typescript-eslint/eslint-plugin": "^2.25.0",
56-
"@typescript-eslint/parser": "^2.25.0",
57-
"eslint": "^6.8.0",
58-
"eslint-config-prettier": "^6.10.1",
59-
"eslint-plugin-prettier": "^3.1.2",
60-
"mkdirp": "^1.0.3",
61-
"prettier": "1.16.4",
62-
"rimraf": "^2.6.1",
63-
"typescript": "~3.7.0"
54+
"@types/node": "^16.3.1",
55+
"@typescript-eslint/eslint-plugin": "^4.28.3",
56+
"@typescript-eslint/parser": "^4.28.3",
57+
"eslint": "^7.30.0",
58+
"eslint-config-prettier": "^8.3.0",
59+
"eslint-plugin-prettier": "^3.4.0",
60+
"mkdirp": "^1.0.4",
61+
"prettier": "2.3.2",
62+
"rimraf": "^3.0.2",
63+
"typescript": "~4.3.5"
6464
},
6565
"sideEffects": [
6666
"style/**/*"

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
cmdclass= cmdclass,
7272
packages=setuptools.find_packages(),
7373
install_requires=[
74-
"jupyterlab @ git+https://github.com/platiagro/jupyterlab.git@fix/packages#egg=jupyterlab",
7574
"requests~=2.0",
7675
],
7776
zip_safe=False,

src/add-widget.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class AddWidget extends Widget {
3838
height: '18px',
3939
width: '18px',
4040
marginLeft: '3px',
41-
marginRight: '-5px'
41+
marginRight: '-5px',
4242
});
4343
this.addClass('unapplied-tag');
4444
option.appendChild(iconContainer);

src/dataset.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
showDialog as showDialogBase,
55
Dialog,
66
showErrorMessage,
7-
Spinner
7+
Spinner,
88
} from '@jupyterlab/apputils';
99

1010
import { Notebook } from '@jupyterlab/notebook';
@@ -29,14 +29,14 @@ export namespace DatasetActions {
2929
export const showDialog = async (notebook: Notebook): Promise<void> => {
3030
// declare an object that will keep the inputted data
3131
const parameter: any = {
32-
file: null
32+
file: null,
3333
};
3434

3535
// Open a dialog that hosts a form to select a file
3636
const result = await showDialogBase({
3737
title: 'Upload File and Set Dataset Name',
3838
body: new DialogBody(parameter),
39-
buttons: [Dialog.cancelButton(), Dialog.okButton()]
39+
buttons: [Dialog.cancelButton(), Dialog.okButton()],
4040
});
4141

4242
if (result.button.accept) {
@@ -51,7 +51,7 @@ export namespace DatasetActions {
5151
name: 'dataset',
5252
value: parameterValue,
5353
variableType: 'string',
54-
fieldType: 'input'
54+
fieldType: 'input',
5555
};
5656
ParameterActions.setParameter(notebook, parameter);
5757
}
@@ -67,15 +67,15 @@ export namespace DatasetActions {
6767
spinnerDialogBody.node.appendChild(spinner.node);
6868
const spinnerDialog = new Dialog({
6969
body: spinnerDialogBody,
70-
buttons: []
70+
buttons: [],
7171
});
7272
spinnerDialog.launch();
7373
try {
7474
const formData = new FormData();
7575
formData.append('file', file);
7676
const response = await requestAPI<any>('datasets', {
7777
method: 'POST',
78-
body: formData
78+
body: formData,
7979
});
8080
spinnerDialog.dispose();
8181
return response;
@@ -141,5 +141,5 @@ class DialogBody extends Widget {
141141

142142
export const setDatasetIcon = new LabIcon({
143143
name: 'platiagro:set-dataset',
144-
svgstr: setDatasetSvgstr
144+
svgstr: setDatasetSvgstr,
145145
});

src/dropdown-options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class DropdownOptions extends Widget {
1111
/**
1212
* Construct a new widget.
1313
*/
14+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1415
constructor(parameter: any) {
1516
super();
1617
this.parameter = parameter;

src/index.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
IRouter,
33
JupyterFrontEnd,
4-
JupyterFrontEndPlugin
4+
JupyterFrontEndPlugin,
55
} from '@jupyterlab/application';
66

77
import { IMainMenu } from '@jupyterlab/mainmenu';
@@ -53,7 +53,7 @@ const extension: JupyterFrontEndPlugin<void> = {
5353
addContextMenuItems(app);
5454

5555
addRouteHandlers(router);
56-
}
56+
},
5757
};
5858

5959
/**
@@ -87,23 +87,23 @@ function addCommands(
8787
execute: () => {
8888
DatasetActions.showDialog(nbtracker.currentWidget.content);
8989
},
90-
isEnabled
90+
isEnabled,
9191
});
9292

9393
app.commands.addCommand(CommandIDs.setParameter, {
9494
label: 'Add Parameter',
9595
execute: () => {
9696
ParameterActions.showDialog(nbtracker.currentWidget.content);
9797
},
98-
isEnabled
98+
isEnabled,
9999
});
100100

101101
app.commands.addCommand(CommandIDs.openFiles, {
102102
label: 'Open Files…',
103103
execute: () => {
104104
UrlActions.openFiles(app, paths, router);
105105
},
106-
isEnabled
106+
isEnabled,
107107
});
108108
}
109109

@@ -115,11 +115,11 @@ function addMainMenuItems(mainMenu: IMainMenu | null): void {
115115
mainMenu.editMenu.addGroup(
116116
[
117117
{
118-
command: CommandIDs.setDataset
118+
command: CommandIDs.setDataset,
119119
},
120120
{
121-
command: CommandIDs.setParameter
122-
}
121+
command: CommandIDs.setParameter,
122+
},
123123
],
124124
20
125125
);
@@ -133,22 +133,22 @@ function addContextMenuItems(app: JupyterFrontEnd): void {
133133
app.contextMenu.addItem({
134134
type: 'separator',
135135
selector: '.jp-Notebook',
136-
rank: 20
136+
rank: 20,
137137
});
138138
app.contextMenu.addItem({
139139
command: CommandIDs.setDataset,
140140
selector: '.jp-Notebook',
141-
rank: 21
141+
rank: 21,
142142
});
143143
app.contextMenu.addItem({
144144
command: CommandIDs.setParameter,
145145
selector: '.jp-Notebook',
146-
rank: 22
146+
rank: 22,
147147
});
148148
app.contextMenu.addItem({
149149
type: 'separator',
150150
selector: '.jp-Notebook',
151-
rank: 23
151+
rank: 23,
152152
});
153153
}
154154

@@ -159,7 +159,7 @@ function addRouteHandlers(router: IRouter): void {
159159
router.register({
160160
command: CommandIDs.openFiles,
161161
pattern: /(\?open=.*?|&open=.*?)($|&)/,
162-
rank: 10 // High priority: 10:100.
162+
rank: 10, // High priority: 10:100.
163163
});
164164
}
165165

src/option-widget.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class OptionWidget extends Widget {
3535
height: '18px',
3636
width: '18px',
3737
marginLeft: '5px',
38-
marginRight: '-3px'
38+
marginRight: '-3px',
3939
});
4040
if (this.applied) {
4141
this.addClass('applied-tag');

src/parameter.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export namespace ParameterActions {
2929
options: [],
3030
multiple: false,
3131
label: '',
32-
description: ''
32+
description: '',
3333
}
3434
): Promise<void> => {
3535
// Open a dialog that hosts a form to set a parameter
3636
const result = await showDialogBase({
3737
title: 'Add Parameter',
3838
body: new DialogBody(parameter),
39-
buttons: [Dialog.cancelButton(), Dialog.okButton()]
39+
buttons: [Dialog.cancelButton(), Dialog.okButton()],
4040
});
4141

4242
if (result.button.accept) {
@@ -52,22 +52,23 @@ export namespace ParameterActions {
5252
*/
5353
export const setParameter = async (
5454
notebook: Notebook,
55+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
5556
parameter: any
5657
): Promise<void> => {
5758
// validate required fields
5859
if (!parameter.name || !parameter.fieldType || !parameter.variableType) {
5960
await showDialogBase({
6061
title: 'Cannot add parameter',
6162
body: 'Variable name, Variable type, and Form field type are required',
62-
buttons: [Dialog.okButton()]
63+
buttons: [Dialog.okButton()],
6364
});
6465

6566
void ParameterActions.showDialog(notebook, parameter);
6667
return;
6768
}
6869

6970
// get the index of first cell that has a tag 'parameters'
70-
const index = notebook.widgets.findIndex(cell => {
71+
const index = notebook.widgets.findIndex((cell) => {
7172
const tags = cell.model.metadata.get('tags') as string[];
7273
return tags === undefined ? false : tags.includes('parameters');
7374
});
@@ -233,9 +234,9 @@ class DialogBody extends Widget {
233234
'integer',
234235
'number',
235236
'boolean',
236-
'feature'
237+
'feature',
237238
];
238-
variableTypeOptions.forEach(item => {
239+
variableTypeOptions.forEach((item) => {
239240
const option = document.createElement('option');
240241
option.value = item;
241242
option.textContent = item;
@@ -251,7 +252,7 @@ class DialogBody extends Widget {
251252
this.fieldTypeSelect = document.createElement('select');
252253
this.fieldTypeSelect.name = 'fieldType';
253254
const fieldTypeOptions = ['', 'input', 'dropdown'];
254-
fieldTypeOptions.forEach(item => {
255+
fieldTypeOptions.forEach((item) => {
255256
const option = document.createElement('option');
256257
option.value = item;
257258
option.textContent = item;
@@ -329,5 +330,5 @@ class DialogBody extends Widget {
329330

330331
export const setParameterIcon = new LabIcon({
331332
name: 'platiagro:set-parameter',
332-
svgstr: setParameterSvgstr
333+
svgstr: setParameterSvgstr,
333334
});

0 commit comments

Comments
 (0)