Skip to content

Commit 391ac5d

Browse files
authored
Start language server with "python -m pyls" (#114)
* Start pyls with python -m pyls * Improve startup error handling * Remove deprecated settings option * Add note about changing python executable * Remove mentions of old pyls versions We now require pyls 0.19 * Update required pyls version in Readme * Clarify python executable setting * Update Readme * Improve error message when python executable is not found
1 parent fd03182 commit 391ac5d

File tree

3 files changed

+67
-42
lines changed

3 files changed

+67
-42
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Python language support for [Atom-IDE](https://ide.atom.io/), powered by the [Py
88

99
## Requirements
1010

11-
[`ide-python`](https://atom.io/packages/ide-python) requires [Atom `1.21+`](https://atom.io/), [Python language server `0.18+`](https://github.com/palantir/python-language-server) and the [`atom-ide-ui`](https://atom.io/packages/atom-ide-ui) package to expose the functionality within Atom.
11+
[`ide-python`](https://atom.io/packages/ide-python) requires [Atom `1.21+`](https://atom.io/), [Python language server `0.19+`](https://github.com/palantir/python-language-server) and the [`atom-ide-ui`](https://atom.io/packages/atom-ide-ui) package to expose the functionality within Atom.
1212

1313
## Feature Providers
1414

@@ -25,15 +25,15 @@ Python language support for [Atom-IDE](https://ide.atom.io/), powered by the [Py
2525

2626
### Language Server
2727

28-
Install the language server with:
28+
Install the language server (0.19.0 or newer) with:
2929

3030
```bash
31-
pip install 'python-language-server[all]'
31+
python -m pip install 'python-language-server[all]'
3232
```
3333

3434
This command will install the language server and all supported feature providers, which can be enabled or disabled in the settings. Checkout the [official installation instructions](https://github.com/palantir/python-language-server#installation) on how to install only the providers you need.
3535

36-
Verify that everything is correctly installed and `pyls` is on your `PATH` by running `pyls --help` from the command line.
36+
You can verify that everything is correctly installed by running `python -m pyls --help` from the command line.
3737
It should return
3838

3939
```bash
@@ -44,7 +44,7 @@ Python Language Server
4444
...
4545
```
4646

47-
Depending on your Python setup `pyls` may be installed in a non default folder. In this case either add the directory to your `PATH` or edit the "Python Language Server Path" setting of `ide-python` to point to the `pyls` executable.
47+
If you have installed `pyls` using a non default installation of Python, you can add modify the *Python Executable* config in the `ide-python` settings.
4848

4949
### Atom Package
5050

lib/main.js

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ class PythonLanguageClient extends AutoLanguageClient {
2424
return "ide-python";
2525
}
2626

27+
activate() {
28+
// Remove deprecated option
29+
atom.config.unset("ide-python.pylsPath");
30+
super.activate();
31+
}
32+
2733
mapConfigurationObject(configuration) {
2834
return {
2935
pyls: {
@@ -45,27 +51,46 @@ class PythonLanguageClient extends AutoLanguageClient {
4551
pylsEnvironment["VIRTUAL_ENV"] = venvPath;
4652
}
4753

48-
const childProcess = cp.spawn(atom.config.get("ide-python.pylsPath"), {
54+
const python = atom.config.get("ide-python.python");
55+
56+
const childProcess = cp.spawn(python, ["-m", "pyls"], {
4957
cwd: projectPath,
5058
env: pylsEnvironment
5159
});
52-
childProcess.on("error", err =>
53-
atom.notifications.addError("Unable to start the Python language server.", {
60+
61+
childProcess.on("error", err => {
62+
const description =
63+
err.code == "ENOENT"
64+
? `No Python interpreter found at \`${python}\`.`
65+
: `Could not spawn the Python interpreter \`${python}\`.`;
66+
atom.notifications.addError("`ide-python` could not launch your Python runtime.", {
5467
dismissable: true,
55-
buttons: [
56-
{
57-
text: "Install Instructions",
58-
onDidClick: () => atom.workspace.open("atom://config/packages/ide-python")
59-
},
60-
{
61-
text: "Download Python",
62-
onDidClick: () => shell.openExternal("https://www.python.org/downloads/")
63-
}
64-
],
65-
description:
66-
"This can occur if you do not have Python installed or if it is not in your path.\n\n Make sure to install `pyls` by running:\n```\npip install 'python-language-server[all]'\n```"
67-
})
68-
);
68+
description: `${description}<p>If you have Python installed please set "Python Executable" setting correctly. If you do not please install Python.</p>`
69+
});
70+
});
71+
72+
childProcess.on("close", (code, signal) => {
73+
if (code !== 0 && signal == null) {
74+
atom.notifications.addError("Unable to start the Python language server.", {
75+
dismissable: true,
76+
buttons: [
77+
{
78+
text: "Install Instructions",
79+
onDidClick: () => atom.workspace.open("atom://config/packages/ide-python")
80+
},
81+
{
82+
text: "Download Python",
83+
onDidClick: () => shell.openExternal("https://www.python.org/downloads/")
84+
}
85+
],
86+
description:
87+
"Make sure to install `pyls` 0.19 or newer by running:\n" +
88+
"```\n" +
89+
`${python} -m pip install 'python-language-server[all]'\n` +
90+
"```"
91+
});
92+
}
93+
});
6994
return childProcess;
7095
}
7196

package.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
"source.python"
3333
],
3434
"configSchema": {
35-
"pylsPath": {
36-
"title": "Python Language Server Path",
35+
"python": {
36+
"title": "Python Executable",
3737
"order": 1,
3838
"type": "string",
39-
"default": "pyls",
40-
"description": "Absolute path to `pyls` executable."
39+
"default": "python",
40+
"description": "Absolute path of your Python binary. This is used to launch the Python language server. Make sure to install `pyls` for this version of Python. Changes will take effect after a restart of the language server."
4141
},
4242
"pylsConfigurationSources": {
4343
"order": 2,
@@ -46,7 +46,7 @@
4646
"pycodestyle",
4747
"flake8"
4848
],
49-
"description": "List of configuration sources to use. Requires `pyls` 0.12.1+",
49+
"description": "List of configuration sources to use.",
5050
"items": {
5151
"type": "string",
5252
"enum": [
@@ -59,7 +59,7 @@
5959
"order": 3,
6060
"type": "string",
6161
"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. Requires `pyls` 0.17+"
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."
6363
},
6464
"pylsPlugins": {
6565
"title": "Python Language Server Plugins",
@@ -140,7 +140,7 @@
140140
"title": "All Scopes",
141141
"type": "boolean",
142142
"default": true,
143-
"description": "If enabled lists the names of all scopes instead of only the module namespace. Requires `pyls` 0.7+"
143+
"description": "If enabled lists the names of all scopes instead of only the module namespace."
144144
}
145145
}
146146
},
@@ -181,7 +181,7 @@
181181
"type": "string"
182182
},
183183
"default": [],
184-
"description": "Select errors and warnings. Requires `pyls` 0.14+"
184+
"description": "Select errors and warnings."
185185
},
186186
"ignore": {
187187
"order": 3,
@@ -199,21 +199,21 @@
199199
"items": {
200200
"type": "string"
201201
},
202-
"description": "Ignore errors and warnings. Requires `pyls` 0.14+"
202+
"description": "Ignore errors and warnings."
203203
},
204204
"hangClosing": {
205205
"order": 4,
206206
"title": "Hang Closing",
207207
"type": "boolean",
208208
"default": false,
209-
"description": "Hang closing bracket instead of matching indentation of opening bracket's line. Requires `pyls` 0.12.1+"
209+
"description": "Hang closing bracket instead of matching indentation of opening bracket's line."
210210
},
211211
"maxLineLength": {
212212
"order": 5,
213213
"title": "Max Line Length",
214214
"type": "number",
215215
"default": 79,
216-
"description": "Set maximum allowed line length. Requires `pyls` 0.12.1+"
216+
"description": "Set maximum allowed line length."
217217
}
218218
}
219219
},
@@ -233,14 +233,14 @@
233233
"title": "Match",
234234
"type": "string",
235235
"default": "(?!test_).*\\.py",
236-
"description": "Check only files that exactly match the given regular expression; default is to match files that don't start with 'test_' but end with '.py'. Requires `pyls` 0.17+"
236+
"description": "Check only files that exactly match the given regular expression; default is to match files that don't start with 'test_' but end with '.py'."
237237
},
238238
"matchDir": {
239239
"order": 3,
240240
"title": "Match Dir",
241241
"type": "string",
242242
"default": "[^\\.].*",
243-
"description": "Search only dirs that exactly match the given regular expression; default is to match dirs which do not begin with a dot. Requires `pyls` 0.17+"
243+
"description": "Search only dirs that exactly match the given regular expression; default is to match dirs which do not begin with a dot."
244244
},
245245
"select": {
246246
"order": 4,
@@ -250,7 +250,7 @@
250250
"items": {
251251
"type": "string"
252252
},
253-
"description": "Select errors and warnings Requires `pyls` 0.17+"
253+
"description": "Select errors and warnings"
254254
},
255255
"ignore": {
256256
"order": 5,
@@ -260,7 +260,7 @@
260260
"items": {
261261
"type": "string"
262262
},
263-
"description": "Ignore errors and warnings Requires `pyls` 0.17+"
263+
"description": "Ignore errors and warnings"
264264
},
265265
"convention": {
266266
"order": 6,
@@ -272,7 +272,7 @@
272272
""
273273
],
274274
"default": "",
275-
"description": "Choose the basic list of checked errors by specifying an existing convention. Requires `pyls` 0.17+"
275+
"description": "Choose the basic list of checked errors by specifying an existing convention."
276276
},
277277
"addSelect": {
278278
"order": 7,
@@ -282,7 +282,7 @@
282282
"items": {
283283
"type": "string"
284284
},
285-
"description": "Select errors and warnings in addition to the specified convention. Requires `pyls` 0.17+"
285+
"description": "Select errors and warnings in addition to the specified convention."
286286
},
287287
"addIgnore": {
288288
"order": 8,
@@ -292,7 +292,7 @@
292292
"items": {
293293
"type": "string"
294294
},
295-
"description": "Ignore errors and warnings in addition to the specified convention. Requires `pyls` 0.17+"
295+
"description": "Ignore errors and warnings in addition to the specified convention."
296296
}
297297
}
298298
},
@@ -316,7 +316,7 @@
316316
"title": "Enabled",
317317
"type": "boolean",
318318
"default": false,
319-
"description": "Enable or disable the plugin. Requires `pyls` 0.12.1+"
319+
"description": "Enable or disable the plugin."
320320
}
321321
}
322322
},
@@ -340,7 +340,7 @@
340340
"title": "Enabled",
341341
"type": "boolean",
342342
"default": true,
343-
"description": "Enable or disable autopep8. Formats code according to PyCodeStyle config. Requires `pyls` 0.17+"
343+
"description": "Enable or disable autopep8. Formats code according to PyCodeStyle config."
344344
}
345345
}
346346
}

0 commit comments

Comments
 (0)