Skip to content

Commit 2aabfae

Browse files
authored
Ds/greazer/fix gather webpack (#11109)
* Support custom gather spec locations * Adjust gather->script generation * Interactive Window Gather * Created GatherToScript command and made the interactive window always use that when gathering. * Don't show gather if cell is error * No gathering markdown * Add a new folder to Gather spec path
1 parent 2d0fef2 commit 2aabfae

File tree

20 files changed

+196
-171
lines changed

20 files changed

+196
-171
lines changed

build/webpack/webpack.extension.config.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,18 @@ const config = {
6767
externals: ['vscode', 'commonjs', ...ppaPackageList, ...existingModulesInOutDir],
6868
plugins: [
6969
...common.getDefaultPlugins('extension'),
70-
// Copy pdfkit after extension builds. webpack can't handle pdfkit.
71-
new removeFilesWebpackPlugin({
72-
after: { include: ['./out/client/node_modules/pdfkit/js/pdfkit.standalone.*'] }
70+
// Copy gather spec files into a known location for the webpacked extension
71+
new FileManagerPlugin({
72+
onEnd: [
73+
{
74+
copy: [
75+
{
76+
source: './node_modules/@msrvida/python-program-analysis/dist/es5/specs/*.yaml',
77+
destination: './out/client/gatherSpecs'
78+
}
79+
]
80+
}
81+
]
7382
}),
7483
new copyWebpackPlugin([
7584
{

package-lock.json

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,68 +1655,6 @@
16551655
"markdownDescription": "Defines the location and order of the sources where scripts files for Widgets are downloaded from (e.g. ipywidgest, bqplot, beakerx, ipyleaflet, etc). Not selecting any of these could result in widgets not rendering or function correctly. See [here](https://aka.ms/PVSCIPyWidgets) for more information. Once updated you will need to restart the Kernel.",
16561656
"scope": "machine"
16571657
},
1658-
"python.dataScience.gatherRules": {
1659-
"type": "array",
1660-
"default": [
1661-
{
1662-
"objectName": "df",
1663-
"functionName": "head",
1664-
"doesNotModify": [
1665-
"OBJECT"
1666-
]
1667-
},
1668-
{
1669-
"objectName": "df",
1670-
"functionName": "describe",
1671-
"doesNotModify": [
1672-
"OBJECT"
1673-
]
1674-
},
1675-
{
1676-
"objectName": "df",
1677-
"functionName": "tail",
1678-
"doesNotModify": [
1679-
"OBJECT"
1680-
]
1681-
},
1682-
{
1683-
"functionName": "print",
1684-
"doesNotModify": [
1685-
"ARGUMENTS"
1686-
]
1687-
},
1688-
{
1689-
"functionName": "KMeans",
1690-
"doesNotModify": [
1691-
"ARGUMENTS"
1692-
]
1693-
},
1694-
{
1695-
"functionName": "scatter",
1696-
"doesNotModify": [
1697-
"ARGUMENTS"
1698-
]
1699-
},
1700-
{
1701-
"functionName": "fit",
1702-
"doesNotModify": [
1703-
"ARGUMENTS"
1704-
]
1705-
},
1706-
{
1707-
"functionName": "sum",
1708-
"doesNotModify": [
1709-
"ARGUMENTS"
1710-
]
1711-
},
1712-
{
1713-
"functionName": "len",
1714-
"doesNotModify": [
1715-
"ARGUMENTS"
1716-
]
1717-
}
1718-
]
1719-
},
17201658
"python.dataScience.askForLargeDataFrames": {
17211659
"type": "boolean",
17221660
"default": true,
@@ -1941,6 +1879,12 @@
19411879
"description": "Python Insiders Only: If experimental gather feature is enabled, gather code to a python script rather than a notebook.",
19421880
"scope": "resource"
19431881
},
1882+
"python.dataScience.gatherSpecPath": {
1883+
"type": "string",
1884+
"default": "",
1885+
"description": "Python Insiders Only: If experimental gather feature is enabled, this setting specifies a folder that contains additional or replacement spec files used for analysis.",
1886+
"scope": "resource"
1887+
},
19441888
"python.dataScience.codeLenses": {
19451889
"type": "string",
19461890
"default": "python.datascience.runcell, python.datascience.runallcellsabove, python.datascience.debugcell",

src/client/common/types.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,6 @@ export interface IAnalysisSettings {
327327
readonly logLevel: LogLevel;
328328
}
329329

330-
interface IGatherRule {
331-
objectName?: string;
332-
functionName: string;
333-
doesNotModify: string[] | number[];
334-
}
335-
336330
export interface IVariableQuery {
337331
language: string;
338332
query: string;
@@ -356,7 +350,7 @@ export interface IDataScienceSettings {
356350
maxOutputSize: number;
357351
enableGather?: boolean;
358352
gatherToScript?: boolean;
359-
gatherRules?: IGatherRule[];
353+
gatherSpecPath?: string;
360354
sendSelectionToInteractiveWindow: boolean;
361355
markdownRegularExpression: string;
362356
codeRegularExpression: string;

src/client/datascience/gather/gather.ts

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import * as ppatypes from '@msrvida-python-program-analysis';
22
import { inject, injectable } from 'inversify';
3+
import * as path from 'path';
34
import * as uuid from 'uuid/v4';
45
import { IApplicationShell, ICommandManager } from '../../common/application/types';
56
import { traceInfo } from '../../common/logger';
7+
import { IFileSystem } from '../../common/platform/types';
68
import { IConfigurationService, IDisposableRegistry } from '../../common/types';
79
import * as localize from '../../common/utils/localize';
810
// tslint:disable-next-line: no-duplicate-imports
@@ -19,12 +21,14 @@ export class GatherProvider implements IGatherProvider {
1921
private _executionSlicer: ppatypes.ExecutionLogSlicer<ppatypes.Cell> | undefined;
2022
private dataflowAnalyzer: ppatypes.DataflowAnalyzer | undefined;
2123
private _enabled: boolean;
24+
private initPromise: Promise<void>;
2225

2326
constructor(
2427
@inject(IConfigurationService) private configService: IConfigurationService,
2528
@inject(IApplicationShell) private applicationShell: IApplicationShell,
2629
@inject(IDisposableRegistry) private disposables: IDisposableRegistry,
27-
@inject(ICommandManager) private commandManager: ICommandManager
30+
@inject(ICommandManager) private commandManager: ICommandManager,
31+
@inject(IFileSystem) private fileSystem: IFileSystem
2832
) {
2933
// Disable gather if we're not running on insiders.
3034
this._enabled =
@@ -33,28 +37,12 @@ export class GatherProvider implements IGatherProvider {
3337
? true
3438
: false;
3539

36-
if (this._enabled) {
37-
try {
38-
// tslint:disable-next-line: no-require-imports
39-
const ppa = require('@msrvida/python-program-analysis') as typeof import('@msrvida-python-program-analysis');
40-
41-
if (ppa) {
42-
this.dataflowAnalyzer = new ppa.DataflowAnalyzer();
43-
this._executionSlicer = new ppa.ExecutionLogSlicer(this.dataflowAnalyzer);
44-
45-
this.disposables.push(
46-
this.configService.getSettings(undefined).onDidChange((e) => this.updateEnableGather(e))
47-
);
48-
}
49-
} catch (ex) {
50-
traceInfo(
51-
'Gathering tools could not be activated. Indicates build of VSIX could not find @msrvida/python-program-analysis'
52-
);
53-
}
54-
}
40+
this.initPromise = this.init();
5541
}
5642

57-
public logExecution(vscCell: IVscCell): void {
43+
public async logExecution(vscCell: IVscCell): Promise<void> {
44+
await this.initPromise;
45+
5846
const gatherCell = convertVscToGatherCell(vscCell);
5947

6048
if (gatherCell) {
@@ -65,6 +53,8 @@ export class GatherProvider implements IGatherProvider {
6553
}
6654

6755
public async resetLog(): Promise<void> {
56+
await this.initPromise;
57+
6858
if (this._executionSlicer) {
6959
this._executionSlicer.reset();
7060
}
@@ -90,11 +80,7 @@ export class GatherProvider implements IGatherProvider {
9080

9181
// Call internal slice method
9282
const slice = this._executionSlicer.sliceLatestExecution(gatherCell.persistentId);
93-
const program = slice.cellSlices.reduce(concat, '').replace(/#%%/g, defaultCellMarker);
94-
95-
// Add a comment at the top of the file explaining what gather does
96-
const descriptor = localize.DataScience.gatheredScriptDescription();
97-
return descriptor.concat(program);
83+
return slice.cellSlices.reduce(concat, '').replace(/#%%/g, defaultCellMarker);
9884
}
9985

10086
public get executionSlicer() {
@@ -124,6 +110,50 @@ export class GatherProvider implements IGatherProvider {
124110
}
125111
}
126112
}
113+
114+
private async init(): Promise<void> {
115+
if (this._enabled) {
116+
try {
117+
// tslint:disable-next-line: no-require-imports
118+
const ppa = require('@msrvida/python-program-analysis') as typeof import('@msrvida-python-program-analysis');
119+
120+
if (ppa) {
121+
// If the __builtins__ specs are not available for gather, then no specs have been found. Look in a specific location relative
122+
// to the extension.
123+
if (!ppa.getSpecs()) {
124+
const defaultSpecFolder = path.join(__dirname, 'gatherSpecs');
125+
if (await this.fileSystem.directoryExists(defaultSpecFolder)) {
126+
ppa.setSpecFolder(defaultSpecFolder);
127+
}
128+
}
129+
130+
// Check to see if any additional specs can be found.
131+
const additionalSpecPath = this.configService.getSettings().datascience.gatherSpecPath;
132+
if (additionalSpecPath && (await this.fileSystem.directoryExists(additionalSpecPath))) {
133+
ppa.addSpecFolder(additionalSpecPath);
134+
} else {
135+
traceInfo(`Gather: additional spec folder ${additionalSpecPath} but not found.`);
136+
}
137+
138+
// Only continue to initialize gather if we were successful in finding SOME specs.
139+
if (ppa.getSpecs()) {
140+
this.dataflowAnalyzer = new ppa.DataflowAnalyzer();
141+
this._executionSlicer = new ppa.ExecutionLogSlicer(this.dataflowAnalyzer);
142+
143+
this.disposables.push(
144+
this.configService.getSettings(undefined).onDidChange((e) => this.updateEnableGather(e))
145+
);
146+
} else {
147+
this._enabled = false;
148+
traceInfo("Gather couldn't find any package specs. Disabling.");
149+
}
150+
}
151+
} catch (ex) {
152+
this._enabled = false;
153+
traceInfo(`Gathering tools could't be activated. ${ex.message}`);
154+
}
155+
}
156+
}
127157
}
128158

129159
/**

0 commit comments

Comments
 (0)