Skip to content

Commit 71193b7

Browse files
authored
Add support for preloading modules (#148)
* Add support for preloading modules See palantir/python-language-server#367 * Add config for Eope extensionModules
1 parent c2c5d50 commit 71193b7

File tree

4 files changed

+170
-9
lines changed

4 files changed

+170
-9
lines changed

lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const cp = require("child_process");
22
const { shell } = require("electron");
33
const { AutoLanguageClient } = require("atom-languageclient");
4-
const { detectVirtualEnv } = require("./utils");
4+
const { detectVirtualEnv, sanitizeConfig } = require("./utils");
55

66
// Ref: https://github.com/nteract/hydrogen/blob/master/lib/autocomplete-provider.js#L33
77
// adapted from http://stackoverflow.com/q/5474008
@@ -34,7 +34,7 @@ class PythonLanguageClient extends AutoLanguageClient {
3434
return {
3535
pyls: {
3636
configurationSources: configuration.pylsConfigurationSources,
37-
rope: { ropeFolder: configuration.ropeFolder !== "null" ? configuration.ropeFolder : null },
37+
rope: sanitizeConfig(configuration.rope),
3838
plugins: configuration.pylsPlugins
3939
}
4040
};

lib/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ async function detectVirtualEnv(path) {
4242
}
4343
}
4444

45+
function sanitizeConfig(config) {
46+
Object.entries(config).forEach(([key, value]) => {
47+
if (value === "null") {
48+
config[key] = null;
49+
}
50+
});
51+
return config;
52+
}
53+
4554
exports.detectVirtualEnv = detectVirtualEnv;
55+
exports.sanitizeConfig = sanitizeConfig;

package.json

Lines changed: 136 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,10 @@
5555
]
5656
}
5757
},
58-
"ropeFolder": {
59-
"order": 3,
60-
"type": "string",
61-
"default": ".ropeproject",
62-
"description": "The name of the folder in which rope stores project configurations and data. Pass `null` for not using such a folder at all."
63-
},
6458
"pylsPlugins": {
6559
"title": "Python Language Server Plugins",
6660
"type": "object",
61+
"order": 3,
6762
"properties": {
6863
"jedi_completion": {
6964
"title": "Jedi Completion",
@@ -162,6 +157,74 @@
162157
}
163158
}
164159
},
160+
"preload": {
161+
"title": "Preload",
162+
"type": "object",
163+
"properties": {
164+
"enabled": {
165+
"title": "Enabled",
166+
"type": "boolean",
167+
"default": true,
168+
"description": "Enable or disable preload."
169+
},
170+
"modules": {
171+
"title": "Modules",
172+
"type": "array",
173+
"default": [
174+
"OpenGL",
175+
"PIL",
176+
"array",
177+
"audioop",
178+
"binascii",
179+
"cPickle",
180+
"cStringIO",
181+
"cmath",
182+
"collections",
183+
"datetime",
184+
"errno",
185+
"exceptions",
186+
"gc",
187+
"imageop",
188+
"imp",
189+
"itertools",
190+
"marshal",
191+
"math",
192+
"matplotlib",
193+
"mmap",
194+
"mpmath",
195+
"msvcrt",
196+
"networkx",
197+
"nose",
198+
"nt",
199+
"numpy",
200+
"operator",
201+
"os",
202+
"os.path",
203+
"pandas",
204+
"parser",
205+
"rgbimg",
206+
"scipy",
207+
"signal",
208+
"skimage",
209+
"sklearn",
210+
"statsmodels",
211+
"strop",
212+
"sympy",
213+
"sys",
214+
"thread",
215+
"time",
216+
"wx",
217+
"xxsubtype",
218+
"zipimport",
219+
"zlib"
220+
],
221+
"items": {
222+
"type": "string"
223+
},
224+
"description": "List of modules to import on startup"
225+
}
226+
}
227+
},
165228
"pycodestyle": {
166229
"title": "PyCodeStyle",
167230
"type": "object",
@@ -345,6 +408,73 @@
345408
}
346409
}
347410
}
411+
},
412+
"rope": {
413+
"type": "object",
414+
"properties": {
415+
"ropeFolder": {
416+
"title": "Rope Folder",
417+
"type": "string",
418+
"default": ".ropeproject",
419+
"description": "The name of the folder in which rope stores project configurations and data. Pass `null` for not using such a folder at all."
420+
},
421+
"extensionModules": {
422+
"title": "Extension Modules",
423+
"type": "array",
424+
"default": [
425+
"OpenGL",
426+
"PIL",
427+
"array",
428+
"audioop",
429+
"binascii",
430+
"cPickle",
431+
"cStringIO",
432+
"cmath",
433+
"collections",
434+
"datetime",
435+
"errno",
436+
"exceptions",
437+
"gc",
438+
"imageop",
439+
"imp",
440+
"itertools",
441+
"marshal",
442+
"math",
443+
"matplotlib",
444+
"mmap",
445+
"mpmath",
446+
"msvcrt",
447+
"networkx",
448+
"nose",
449+
"nt",
450+
"numpy",
451+
"operator",
452+
"os",
453+
"os.path",
454+
"pandas",
455+
"parser",
456+
"rgbimg",
457+
"scipy",
458+
"signal",
459+
"skimage",
460+
"sklearn",
461+
"statsmodels",
462+
"strop",
463+
"sympy",
464+
"sys",
465+
"thread",
466+
"time",
467+
"wx",
468+
"xxsubtype",
469+
"zipimport",
470+
"zlib"
471+
],
472+
"items": {
473+
"type": "string"
474+
},
475+
"description": "Builtin and c-extension modules that are allowed to be imported and inspected by rope."
476+
}
477+
}
348478
}
349479
},
350480
"consumedServices": {

spec/utils-spec.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const path = require("path");
2-
const { detectVirtualEnv } = require("../lib/utils");
2+
const { detectVirtualEnv, sanitizeConfig } = require("../lib/utils");
33

44
const venvFixturesDir = path.join(__dirname, "fixtures", "venv");
55

@@ -50,3 +50,24 @@ describe("detectVirtualEnv", () => {
5050
});
5151
});
5252
});
53+
54+
describe("sanitizeConfig", () => {
55+
it("converts 'null' to null", () => {
56+
const config = {
57+
ropeFolder: "null",
58+
extensionModules: ["numpy", "pandas"]
59+
};
60+
expect(sanitizeConfig(config)).toEqual({
61+
ropeFolder: null,
62+
extensionModules: ["numpy", "pandas"]
63+
});
64+
});
65+
66+
it("doesn't change object", () => {
67+
const config = {
68+
ropeFolder: ".ropeproject",
69+
extensionModules: ["numpy", "pandas"]
70+
};
71+
expect(sanitizeConfig(config)).toEqual(config);
72+
});
73+
});

0 commit comments

Comments
 (0)