Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit bf7cf85

Browse files
committed
Settings: Update settings docs and format
1 parent 5b73193 commit bf7cf85

File tree

6 files changed

+101
-92
lines changed

6 files changed

+101
-92
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nbgather",
3-
"version": "0.5.1-beta.0",
3+
"version": "0.5.1-beta.1",
44
"keywords": [
55
"jupyter",
66
"jupyterlab"

schema/plugin.json

+21-36
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,32 @@
11
{
2-
"jupyter.lab.setting-icon-label": "Code Gathering Tools",
3-
"title": "Gather",
4-
"description": "Settings for \"nbgather\" plugin.",
2+
"jupyter.lab.setting-icon-label": "nbgather",
3+
"title": "ngbather",
4+
"description": "Settings for nbgather.",
55
"properties": {
6-
"loggingEnabled": {
7-
"title": "Share Interaction Logging Data",
8-
"description": "Whether to report interaction logging data. If this is set to true, interaction telemetry data from your notebook will be uploaded to a research server. Log data does not include any of your code or data, though it does include summary data about your notebook (e.g., the number of cells and their execution counts). Should be off by default.",
6+
"enableLogging": {
7+
"title": "Logging: Enable Optional Logging (OFF by default, opt-in only)",
8+
"description": "Whether this plugin should log your interactions. Logs include only anonymized notebook interaction events, and do not include code or data.",
99
"type": ["boolean"],
1010
"default": false
1111
},
12-
"loggingId": {
13-
"title": "Unique Logging ID",
14-
"description": "Only used if you set 'Share Interaction Logging Data' to true. Then this ID is associated with all events logged from your notebook, so that all of events from the same user can be associated together.",
12+
"loggingTag": {
13+
"title": "Logging: Tag (NULL by default)",
14+
"description": "If logging is enabled, all log events will be uploaded with this tag.",
1515
"type": ["string", "null"],
1616
"default": null
1717
},
18-
"analysis": {
19-
"title": "Analysis options",
20-
"description": "Rules for fine-tuning data-flow analysis. This is most useful for making gather more precise for external APIs. To define specs for how analyze external APIs, define the \"analysis.symbolTable.moduleMap\" property, following instructions at https://github.com/andrewhead/python-program-analysis#api-specs",
21-
"type": "object",
22-
"properties": {
23-
"symbolTable": {
24-
"description": "Options for initializing the symbol table.",
25-
"properties": {
26-
"loadDefaultModuleMap": {
27-
"description": "Whether to load the default module map for the dataflow analyzer. Includes functions from\ncommon data analysis modules like 'matplotlib' and 'pandas'.",
28-
"type": "boolean"
29-
},
30-
"moduleMap": {
31-
"$ref": "#/definitions/JsonSpecs",
32-
"description": "Extend the module map with this variable if you want to specify rules for the how functions\nfrom certain modules affect their arguments, to help the slicer be more precise. If\n'loadDefaultModuleMap' is true, then this module map will be merged with the default module\nmap using the lodash 'merge' function."
33-
}
34-
},
35-
"type": "object"
36-
}
37-
},
38-
"additionalProperties": false,
39-
"default": {
40-
"symbolTable": {
41-
"loadDefaultModuleMap": true,
42-
"moduleMap": {}
43-
}
44-
}
18+
"loadDefaultModuleMap": {
19+
"title": "Load Default Module Map",
20+
"description": "If a 'moduleMap' is defined, merge the 'moduleMap' from user settings with the default module map from the 'python-program-analysis' npm module. If 'false', overwrite defaults.",
21+
"type": "boolean",
22+
"default": true
23+
},
24+
"moduleMap": {
25+
"title": "Module Map for Program Slicing",
26+
"description": "Define rules to help nbgather decide how to gather code in cases where it can't infer whether lines should be gathered or not. Valid values for this property are described at https://github.com/andrewhead/python-program-analysis#api-specs. If you change this option, you will need to refresh this browser tab before nbgather loads the new settings.",
27+
"$ref": "#/definitions/JsonSpecs",
28+
"default": {},
29+
"additionalProperties": false
4530
}
4631
},
4732
"additionalProperties": false,

src/main/main.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
DataflowAnalyzer,
33
DataflowAnalyzerOptions,
4-
ExecutionLogSlicer
4+
ExecutionLogSlicer,
5+
JsonSpecs
56
} from "@andrewhead/python-program-analysis";
67
import { JupyterFrontEndPlugin, JupyterLab } from "@jupyterlab/application";
78
import { ICommandPalette } from "@jupyterlab/apputils";
@@ -68,12 +69,23 @@ export class CodeGatheringExtension
6869
this._documentManager = documentManager;
6970
this._notebooks = notebooks;
7071
this._gatherModelRegistry = gatherModelRegistry;
71-
settingRegistry.get("nbgather:plugin", "analysis").then(data => {
72-
if (JSONExt.isObject(data.composite)) {
73-
let dataCompositeObject = data.composite as unknown;
74-
this._analysisOptions = dataCompositeObject as DataflowAnalyzerOptions;
75-
}
76-
});
72+
settingRegistry
73+
.get("nbgather:plugin", "loadDefaultModuleMap")
74+
.then(data => {
75+
if (JSONExt.isPrimitive(data.composite)) {
76+
let loadDefaultModuleMap = data.composite as boolean;
77+
settingRegistry.get("nbgather:plugin", "moduleMap").then(data => {
78+
if (JSONExt.isObject(data)) {
79+
this._analysisOptions = {
80+
symbolTable: {
81+
loadDefaultModuleMap,
82+
moduleMap: data.composite as JsonSpecs
83+
}
84+
};
85+
}
86+
});
87+
}
88+
});
7789
}
7890

7991
createNew(

src/overlay/revision-browser.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { PanelLayout, Widget } from "@phosphor/widgets";
22
import { GatherModel, GatherState } from "../model";
33
import { log } from "../util/log";
4-
import { buildHistoryModel, HistoryViewer } from "../widgets/history";
4+
import {
5+
buildHistoryModel,
6+
HistoryViewer,
7+
HISTORY_VIEWER_ICON_CLASS
8+
} from "../widgets/history";
59

610
/**
711
* Class for the revision browser widget.
@@ -18,8 +22,8 @@ export class RevisionBrowser extends Widget {
1822
constructor(gatherModel: GatherModel) {
1923
super();
2024
this.id = "revision-browser";
21-
this.title.label = "Revision browser";
22-
this.title.icon = "jp-HistoryIcon";
25+
this.title.label = "Version Browser";
26+
this.title.icon = HISTORY_VIEWER_ICON_CLASS;
2327
this.title.closable = true;
2428
this.addClass(REVISION_BROWSER_CLASS);
2529

@@ -38,7 +42,9 @@ export class RevisionBrowser extends Widget {
3842
} else if (outputSelections.length > 0) {
3943
selectedCell = outputSelections[0].cell;
4044
}
41-
let slices = model.executionLog.sliceAllExecutions(selectedCell.persistentId);
45+
let slices = model.executionLog.sliceAllExecutions(
46+
selectedCell.persistentId
47+
);
4248
log("Bringing up the revision browser for selection", {
4349
cellExecutionEventId: selectedCell.executionEventId,
4450
slices,
@@ -50,7 +56,12 @@ export class RevisionBrowser extends Widget {
5056
* Only show output if the selection was output.
5157
*/
5258
let includeOutput = model.selectedOutputs.length >= 1;
53-
let historyModel = buildHistoryModel(model, selectedCell.persistentId, slices, includeOutput);
59+
let historyModel = buildHistoryModel(
60+
model,
61+
selectedCell.persistentId,
62+
slices,
63+
includeOutput
64+
);
5465
let historyViewer = new HistoryViewer({
5566
model: historyModel
5667
});

src/util/log.ts

+34-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ISettingRegistry } from '@jupyterlab/coreutils';
2-
import * as $ from 'jquery';
1+
import { ISettingRegistry } from "@jupyterlab/coreutils";
2+
// import * as $ from "jquery";
33

44
let _settingRegistry: ISettingRegistry;
55

@@ -38,56 +38,57 @@ export function registerPollers(...pollers: IStatePoller[]) {
3838
export function log(eventName: string, data?: any) {
3939
data = data || {};
4040

41-
let LOG_ENDPOINT = 'https://clarence.eecs.berkeley.edu';
41+
// let LOG_ENDPOINT = "https://clarence.eecs.berkeley.edu";
4242

4343
// Prepare log data.
4444
let postData: any = {
4545
timestamp: new Date().toISOString(),
4646
event: eventName,
4747
data: data,
48-
loggingId: undefined,
48+
tag: undefined
4949
};
5050

5151
if (_settingRegistry != undefined || _settingRegistry != null) {
5252
_settingRegistry
53-
.get('nbgather:plugin', 'loggingEnabled')
53+
.get("nbgather:plugin", "enableLogging")
5454
.then(loggingEnabled => {
5555
if (
56-
typeof loggingEnabled.composite === 'boolean' &&
56+
typeof loggingEnabled.composite === "boolean" &&
5757
loggingEnabled.composite
5858
) {
59-
_settingRegistry
60-
.get('nbgather:plugin', 'loggingId')
61-
.then(loggingId => {
62-
if (typeof loggingId.composite === 'string') {
63-
postData.loggingId = loggingId.composite as string;
59+
_settingRegistry.get("nbgather:plugin", "loggingTag").then(tag => {
60+
if (typeof tag.composite === "string") {
61+
postData.tag = tag.composite as string;
6462

65-
// Poll for additional data from each state poller.
66-
for (let poller of _statePollers) {
67-
let pollData = poller.poll();
68-
for (let k in pollData) {
69-
if (pollData.hasOwnProperty(k)) {
70-
postData[k] = pollData[k];
71-
}
63+
// Poll for additional data from each state poller.
64+
for (let poller of _statePollers) {
65+
let pollData = poller.poll();
66+
for (let k in pollData) {
67+
if (pollData.hasOwnProperty(k)) {
68+
postData[k] = pollData[k];
7269
}
7370
}
71+
}
7472

75-
// If there is any sensitive data to be logged, it should first be cleaned through a
76-
// `toJSON` method defined on a class, or manually before passing it into this method.
77-
// Earlier, we used the replacer argument to JSON.stringify, but it takes too much time
78-
// to apply replacers to every value in the resulting JSON.
79-
postData.data = JSON.stringify(postData.data);
73+
// If there is any sensitive data to be logged, it should first be cleaned through a
74+
// `toJSON` method defined on a class, or manually before passing it into this method.
75+
// Earlier, we used the replacer argument to JSON.stringify, but it takes too much time
76+
// to apply replacers to every value in the resulting JSON.
77+
postData.data = JSON.stringify(postData.data);
8078

81-
// Submit data to logger endpoint.
82-
$.ajax(LOG_ENDPOINT + '/log', {
83-
data: postData,
84-
method: 'POST',
85-
error: (_: any, textStatus: string, errorThrown: string) => {
86-
console.error('Failed to log', textStatus, errorThrown);
87-
},
88-
});
89-
}
90-
});
79+
// Submit data to logger endpoint.
80+
// Disabled in the near term, until a new server is launched.
81+
/*
82+
$.ajax(LOG_ENDPOINT + "/log", {
83+
data: postData,
84+
method: "POST",
85+
error: (_: any, textStatus: string, errorThrown: string) => {
86+
console.error("Failed to log", textStatus, errorThrown);
87+
}
88+
});
89+
*/
90+
}
91+
});
9192
}
9293
});
9394
}

src/widgets/history/widget.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { PanelLayout, Widget } from '@phosphor/widgets';
2-
import { Revision } from '../revision';
3-
import { IHistoryModel } from './model';
1+
import { PanelLayout, Widget } from "@phosphor/widgets";
2+
import { Revision } from "../revision";
3+
import { IHistoryModel } from "./model";
44

55
/**
66
* The class name added to history viewer widgets
77
*/
8-
const HISTORY_VIEWER_CLASS = 'jp-HistoryViewer';
8+
const HISTORY_VIEWER_CLASS = "jp-HistoryViewer";
99

10-
const HISTORY_VIEWER_ICON_CLASS = 'jp-HistoryViewerIcon';
10+
export const HISTORY_VIEWER_ICON_CLASS = "jp-HistoryViewerIcon";
1111

12-
const REFERENCE_VERSION_CLASS = 'jp-HistoryViewer-referenceversion';
12+
const REFERENCE_VERSION_CLASS = "jp-HistoryViewer-referenceversion";
1313

1414
/**
1515
* A widget for showing the history of a result and how it was produced.
@@ -22,8 +22,8 @@ export class HistoryViewer extends Widget {
2222
super();
2323

2424
this.addClass(HISTORY_VIEWER_CLASS);
25-
this.id = 'livecells-revision-browser';
26-
this.title.label = 'Revision Browser';
25+
this.id = "livecells-revision-browser";
26+
this.title.label = "Version Browser";
2727
this.title.icon = HISTORY_VIEWER_ICON_CLASS;
2828
this.title.closable = true;
2929

@@ -36,7 +36,7 @@ export class HistoryViewer extends Widget {
3636
const now = new Date();
3737
let referenceVersion = new Revision({
3838
model: this._model.revisions[this._model.revisions.length - 1],
39-
now: now,
39+
now: now
4040
});
4141
referenceVersion.addClass(REFERENCE_VERSION_CLASS);
4242
layout.addWidget(referenceVersion);
@@ -48,7 +48,7 @@ export class HistoryViewer extends Widget {
4848
layout.addWidget(
4949
new Revision({
5050
model: revisionModel,
51-
now: now,
51+
now: now
5252
})
5353
);
5454
}

0 commit comments

Comments
 (0)