From c323026236eec52ba3261751a52be16660fd2e00 Mon Sep 17 00:00:00 2001 From: Lukas Geiger Date: Mon, 3 Dec 2018 09:45:09 +0100 Subject: [PATCH 1/2] Add support for preloading modules See https://github.com/palantir/python-language-server/pull/367 --- package.json | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/package.json b/package.json index 6a3eece8..9a9dfb90 100644 --- a/package.json +++ b/package.json @@ -162,6 +162,74 @@ } } }, + "preload": { + "title": "Preload", + "type": "object", + "properties": { + "enabled": { + "title": "Enabled", + "type": "boolean", + "default": true, + "description": "Enable or disable preload." + }, + "modules": { + "title": "Modules", + "type": "array", + "default": [ + "OpenGL", + "PIL", + "array", + "audioop", + "binascii", + "cPickle", + "cStringIO", + "cmath", + "collections", + "datetime", + "errno", + "exceptions", + "gc", + "imageop", + "imp", + "itertools", + "marshal", + "math", + "matplotlib", + "mmap", + "mpmath", + "msvcrt", + "networkx", + "nose", + "nt", + "numpy", + "operator", + "os", + "os.path", + "pandas", + "parser", + "rgbimg", + "scipy", + "signal", + "skimage", + "sklearn", + "statsmodels", + "strop", + "sympy", + "sys", + "thread", + "time", + "wx", + "xxsubtype", + "zipimport", + "zlib" + ], + "items": { + "type": "string" + }, + "description": "List of modules to import on startup" + } + } + }, "pycodestyle": { "title": "PyCodeStyle", "type": "object", From 72b76a923f6249e771e7f60a23876f78e53a45e6 Mon Sep 17 00:00:00 2001 From: Lukas Geiger Date: Mon, 3 Dec 2018 10:11:34 +0100 Subject: [PATCH 2/2] Add config for Eope extensionModules --- lib/main.js | 4 +-- lib/utils.js | 10 +++++++ package.json | 74 ++++++++++++++++++++++++++++++++++++++++++---- spec/utils-spec.js | 23 +++++++++++++- 4 files changed, 102 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index b70fd5d4..548bfdc9 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,7 +1,7 @@ const cp = require("child_process"); const { shell } = require("electron"); const { AutoLanguageClient } = require("atom-languageclient"); -const { detectVirtualEnv } = require("./utils"); +const { detectVirtualEnv, sanitizeConfig } = require("./utils"); // Ref: https://github.com/nteract/hydrogen/blob/master/lib/autocomplete-provider.js#L33 // adapted from http://stackoverflow.com/q/5474008 @@ -34,7 +34,7 @@ class PythonLanguageClient extends AutoLanguageClient { return { pyls: { configurationSources: configuration.pylsConfigurationSources, - rope: { ropeFolder: configuration.ropeFolder !== "null" ? configuration.ropeFolder : null }, + rope: sanitizeConfig(configuration.rope), plugins: configuration.pylsPlugins } }; diff --git a/lib/utils.js b/lib/utils.js index 85850db0..86baa63a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -42,4 +42,14 @@ async function detectVirtualEnv(path) { } } +function sanitizeConfig(config) { + Object.entries(config).forEach(([key, value]) => { + if (value === "null") { + config[key] = null; + } + }); + return config; +} + exports.detectVirtualEnv = detectVirtualEnv; +exports.sanitizeConfig = sanitizeConfig; diff --git a/package.json b/package.json index 9a9dfb90..978e1888 100644 --- a/package.json +++ b/package.json @@ -55,15 +55,10 @@ ] } }, - "ropeFolder": { - "order": 3, - "type": "string", - "default": ".ropeproject", - "description": "The name of the folder in which rope stores project configurations and data. Pass `null` for not using such a folder at all." - }, "pylsPlugins": { "title": "Python Language Server Plugins", "type": "object", + "order": 3, "properties": { "jedi_completion": { "title": "Jedi Completion", @@ -413,6 +408,73 @@ } } } + }, + "rope": { + "type": "object", + "properties": { + "ropeFolder": { + "title": "Rope Folder", + "type": "string", + "default": ".ropeproject", + "description": "The name of the folder in which rope stores project configurations and data. Pass `null` for not using such a folder at all." + }, + "extensionModules": { + "title": "Extension Modules", + "type": "array", + "default": [ + "OpenGL", + "PIL", + "array", + "audioop", + "binascii", + "cPickle", + "cStringIO", + "cmath", + "collections", + "datetime", + "errno", + "exceptions", + "gc", + "imageop", + "imp", + "itertools", + "marshal", + "math", + "matplotlib", + "mmap", + "mpmath", + "msvcrt", + "networkx", + "nose", + "nt", + "numpy", + "operator", + "os", + "os.path", + "pandas", + "parser", + "rgbimg", + "scipy", + "signal", + "skimage", + "sklearn", + "statsmodels", + "strop", + "sympy", + "sys", + "thread", + "time", + "wx", + "xxsubtype", + "zipimport", + "zlib" + ], + "items": { + "type": "string" + }, + "description": "Builtin and c-extension modules that are allowed to be imported and inspected by rope." + } + } } }, "consumedServices": { diff --git a/spec/utils-spec.js b/spec/utils-spec.js index a6a9df6d..bd104aae 100644 --- a/spec/utils-spec.js +++ b/spec/utils-spec.js @@ -1,5 +1,5 @@ const path = require("path"); -const { detectVirtualEnv } = require("../lib/utils"); +const { detectVirtualEnv, sanitizeConfig } = require("../lib/utils"); const venvFixturesDir = path.join(__dirname, "fixtures", "venv"); @@ -50,3 +50,24 @@ describe("detectVirtualEnv", () => { }); }); }); + +describe("sanitizeConfig", () => { + it("converts 'null' to null", () => { + const config = { + ropeFolder: "null", + extensionModules: ["numpy", "pandas"] + }; + expect(sanitizeConfig(config)).toEqual({ + ropeFolder: null, + extensionModules: ["numpy", "pandas"] + }); + }); + + it("doesn't change object", () => { + const config = { + ropeFolder: ".ropeproject", + extensionModules: ["numpy", "pandas"] + }; + expect(sanitizeConfig(config)).toEqual(config); + }); +});