Skip to content

Commit eb428f9

Browse files
authored
chore: Run prettier (#153)
1 parent bbaaa51 commit eb428f9

File tree

3 files changed

+102
-58
lines changed

3 files changed

+102
-58
lines changed

lib/main.js

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const cp = require("child_process");
22
const { shell } = require("electron");
33
const { AutoLanguageClient } = require("atom-languageclient");
4-
const { detectVirtualEnv, detectPipEnv, replacePipEnvPathVar, sanitizeConfig } = require("./utils");
4+
const {
5+
detectVirtualEnv,
6+
detectPipEnv,
7+
replacePipEnvPathVar,
8+
sanitizeConfig
9+
} = require("./utils");
510

611
// Ref: https://github.com/nteract/hydrogen/blob/master/lib/autocomplete-provider.js#L33
712
// adapted from http://stackoverflow.com/q/5474008
@@ -42,13 +47,17 @@ class PythonLanguageClient extends AutoLanguageClient {
4247

4348
async startServerProcess(projectPath) {
4449
await new Promise(resolve => atom.whenShellEnvironmentLoaded(resolve));
45-
const venvPath = await detectPipEnv(projectPath) || await detectVirtualEnv(projectPath);
50+
const venvPath =
51+
(await detectPipEnv(projectPath)) ||
52+
(await detectVirtualEnv(projectPath));
4653
const pylsEnvironment = Object.assign({}, process.env);
4754
if (venvPath) {
4855
pylsEnvironment["VIRTUAL_ENV"] = venvPath;
4956
}
50-
let python = atom.config.get("ide-python.python");
51-
python = replacePipEnvPathVar(python, venvPath);
57+
const python = replacePipEnvPathVar(
58+
atom.config.get("ide-python.python"),
59+
venvPath
60+
);
5261
const childProcess = cp.spawn(python, ["-m", "pyls"], {
5362
cwd: projectPath,
5463
env: pylsEnvironment
@@ -58,32 +67,40 @@ class PythonLanguageClient extends AutoLanguageClient {
5867
err.code == "ENOENT"
5968
? `No Python interpreter found at \`${python}\`.`
6069
: `Could not spawn the Python interpreter \`${python}\`.`;
61-
atom.notifications.addError("`ide-python` could not launch your Python runtime.", {
62-
dismissable: true,
63-
description: `${description}<p>If you have Python installed please set "Python Executable" setting correctly. If you do not please install Python.</p>`
64-
});
70+
atom.notifications.addError(
71+
"`ide-python` could not launch your Python runtime.",
72+
{
73+
dismissable: true,
74+
description: `${description}<p>If you have Python installed please set "Python Executable" setting correctly. If you do not please install Python.</p>`
75+
}
76+
);
6577
});
6678

6779
childProcess.on("close", (code, signal) => {
6880
if (code !== 0 && signal == null) {
69-
atom.notifications.addError("Unable to start the Python language server.", {
70-
dismissable: true,
71-
buttons: [
72-
{
73-
text: "Install Instructions",
74-
onDidClick: () => atom.workspace.open("atom://config/packages/ide-python")
75-
},
76-
{
77-
text: "Download Python",
78-
onDidClick: () => shell.openExternal("https://www.python.org/downloads/")
79-
}
80-
],
81-
description:
82-
"Make sure to install `pyls` 0.19 or newer by running:\n" +
83-
"```\n" +
84-
`${python} -m pip install 'python-language-server[all]'\n` +
85-
"```"
86-
});
81+
atom.notifications.addError(
82+
"Unable to start the Python language server.",
83+
{
84+
dismissable: true,
85+
buttons: [
86+
{
87+
text: "Install Instructions",
88+
onDidClick: () =>
89+
atom.workspace.open("atom://config/packages/ide-python")
90+
},
91+
{
92+
text: "Download Python",
93+
onDidClick: () =>
94+
shell.openExternal("https://www.python.org/downloads/")
95+
}
96+
],
97+
description:
98+
"Make sure to install `pyls` 0.19 or newer by running:\n" +
99+
"```\n" +
100+
`${python} -m pip install 'python-language-server[all]'\n` +
101+
"```"
102+
}
103+
);
87104
}
88105
});
89106
return childProcess;
@@ -102,7 +119,9 @@ class PythonLanguageClient extends AutoLanguageClient {
102119
return new Promise((resolve, reject) => {
103120
let timeout = setTimeout(() => {
104121
clearTimeout(timeout);
105-
this.logger.error(`Server failed to shutdown in ${milliseconds}ms, forcing termination`);
122+
this.logger.error(
123+
`Server failed to shutdown in ${milliseconds}ms, forcing termination`
124+
);
106125
resolve();
107126
}, milliseconds);
108127
});

lib/utils.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ const VIRTUAL_ENV_EXECUTABLES = ["python", "python.exe"];
66

77
function detectPipEnv(path) {
88
return new Promise(resolve => {
9-
const pipEnvProcess = cp.spawn('pipenv', ["--venv"], {
9+
const pipEnvProcess = cp.spawn("pipenv", ["--venv"], {
1010
cwd: path
1111
});
12-
pipEnvProcess.stdout.on('data', (data) => {
12+
pipEnvProcess.stdout.on("data", data => {
1313
resolve(`${data}`.trim());
1414
});
15-
pipEnvProcess.stderr.on('data', () => {
15+
pipEnvProcess.stderr.on("data", () => {
1616
resolve(null);
1717
});
18-
pipEnvProcess.on('error', () => {
18+
pipEnvProcess.on("error", () => {
1919
resolve(null);
20-
})
20+
});
2121
});
2222
}
2323

@@ -69,8 +69,8 @@ function sanitizeConfig(config) {
6969
}
7070

7171
function replacePipEnvPathVar(pythonPath, pipEnvPath) {
72-
if (pythonPath.indexOf('$PIPENV_PATH') !== -1 && pipEnvPath) {
73-
return pythonPath.replace('$PIPENV_PATH', pipEnvPath);
72+
if (pythonPath.indexOf("$PIPENV_PATH") !== -1 && pipEnvPath) {
73+
return pythonPath.replace("$PIPENV_PATH", pipEnvPath);
7474
}
7575
return pythonPath;
7676
}

spec/utils-spec.js

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
const path = require("path");
22
const mockSpawn = require("mock-spawn");
33
const assert = require("assert");
4-
const child_process = require('child_process');
5-
const { detectVirtualEnv, sanitizeConfig, detectPipEnv, replacePipEnvPathVar } = require("../lib/utils");
4+
const child_process = require("child_process");
5+
const {
6+
detectVirtualEnv,
7+
sanitizeConfig,
8+
detectPipEnv,
9+
replacePipEnvPathVar
10+
} = require("../lib/utils");
611

712
const venvFixturesDir = path.join(__dirname, "fixtures", "venv");
813

@@ -55,58 +60,78 @@ describe("detectVirtualEnv", () => {
5560
});
5661

5762
describe("detect PipEnv", () => {
58-
const spawn = mockSpawn()
59-
child_process.spawn = spawn
60-
spawn.sequence.add(function (cb) {
61-
this.emit('error', new Error('spawn ENOENT'));
62-
setTimeout(function() { return cb(8); }, 10);
63+
const spawn = mockSpawn();
64+
child_process.spawn = spawn;
65+
spawn.sequence.add(function(cb) {
66+
this.emit("error", new Error("spawn ENOENT"));
67+
setTimeout(function() {
68+
return cb(8);
69+
}, 10);
6370
});
6471
it("with no pipenv", () => {
6572
waitsForPromise(() => {
6673
return detectPipEnv("/home/mock_pipenv").then(venv => {
6774
expect(venv).toBeNull();
68-
assert.equal('pipenv', spawn.calls[0].command);
69-
assert.deepEqual(['--venv'], spawn.calls[0].args);
75+
assert.equal("pipenv", spawn.calls[0].command);
76+
assert.deepEqual(["--venv"], spawn.calls[0].args);
7077
});
7178
});
7279
});
7380

7481
it("with Unix pipenv", () => {
75-
spawn.sequence.add(spawn.simple(1, '/home/tvallois/.local/share/virtualenvs/unix-XZE001N_'));
82+
spawn.sequence.add(
83+
spawn.simple(1, "/home/tvallois/.local/share/virtualenvs/unix-XZE001N_")
84+
);
7685
waitsForPromise(() => {
7786
return detectPipEnv("/home/mock_pipenv").then(venv => {
78-
expect(venv).toBe('/home/tvallois/.local/share/virtualenvs/unix-XZE001N_');
79-
assert.equal('pipenv', spawn.calls[1].command);
80-
assert.deepEqual(['--venv'], spawn.calls[1].args);
87+
expect(venv).toBe(
88+
"/home/tvallois/.local/share/virtualenvs/unix-XZE001N_"
89+
);
90+
assert.equal("pipenv", spawn.calls[1].command);
91+
assert.deepEqual(["--venv"], spawn.calls[1].args);
8192
});
8293
});
8394
});
8495

8596
it("with Windows pipenv", () => {
86-
spawn.sequence.add(spawn.simple(1, 'C:\\Program Files\\tvallois\\virtualenvs\\windows-XZE001N_'));
97+
spawn.sequence.add(
98+
spawn.simple(
99+
1,
100+
"C:\\Program Files\\tvallois\\virtualenvs\\windows-XZE001N_"
101+
)
102+
);
87103
waitsForPromise(() => {
88104
return detectPipEnv("C:\\Program Files\\mock_pipenv").then(venv => {
89-
expect(venv).toBe('C:\\Program Files\\tvallois\\virtualenvs\\windows-XZE001N_');
90-
assert.equal('pipenv', spawn.calls[2].command);
91-
assert.deepEqual(['--venv'], spawn.calls[2].args);
105+
expect(venv).toBe(
106+
"C:\\Program Files\\tvallois\\virtualenvs\\windows-XZE001N_"
107+
);
108+
assert.equal("pipenv", spawn.calls[2].command);
109+
assert.deepEqual(["--venv"], spawn.calls[2].args);
92110
});
93111
});
94112
});
95113
});
96114

97115
describe("replacePipEnvPathVar", () => {
98116
it("replace $PIPENV_PATH", () => {
99-
expect(replacePipEnvPathVar("$PIPENV_PATH/bin/python",
100-
"/home/tvallois/.local/share/virtualenvs/unix-XZE001N_"))
101-
.toEqual("/home/tvallois/.local/share/virtualenvs/unix-XZE001N_/bin/python");
117+
expect(
118+
replacePipEnvPathVar(
119+
"$PIPENV_PATH/bin/python",
120+
"/home/tvallois/.local/share/virtualenvs/unix-XZE001N_"
121+
)
122+
).toEqual(
123+
"/home/tvallois/.local/share/virtualenvs/unix-XZE001N_/bin/python"
124+
);
102125
});
103126

104127
it("no $PIPENV_PATH", () => {
105-
expect(replacePipEnvPathVar("python",
106-
"/home/tvallois/.local/share/virtualenvs/unix-XZE001N_"))
107-
.toEqual("python");
128+
expect(
129+
replacePipEnvPathVar(
130+
"python",
131+
"/home/tvallois/.local/share/virtualenvs/unix-XZE001N_"
132+
)
133+
).toEqual("python");
108134
});
109-
110135
});
111136

112137
describe("sanitizeConfig", () => {

0 commit comments

Comments
 (0)