Skip to content

Commit 51ed1a6

Browse files
authored
Merge pull request #360 from atom-community/python3
2 parents 477e7c1 + 2850374 commit 51ed1a6

9 files changed

+2674
-567
lines changed

.eslintrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "eslint-config-atomic",
3+
"ignorePatterns": ["dist/", "node_modules/", "lib/debugger/VendorLib"]
4+
}

.github/workflows/CI.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ jobs:
4747
- name: Format ✨
4848
run: npm run test.format
4949

50-
# - name: Lint ✨
51-
# run: npm run test.lint
50+
- name: Lint ✨
51+
run: npm run test.lint
5252

5353
Release:
5454
needs: [Test]

babel.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
let presets = ["babel-preset-atomic"]
1+
const presets = ["babel-preset-atomic"]
22

3-
let plugins = []
3+
const plugins = []
44

55
module.exports = {
6-
presets: presets,
7-
plugins: plugins,
6+
presets,
7+
plugins,
88
exclude: ["node_modules/**", "lib/debugger/VendorLib/**"],
99
sourceMap: "inline",
1010
}

lib/debugger/RemoteDebuggerCommandService.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function observeAttachDebugTargets(): ConnectableObservable<Array<PythonD
5656
}
5757

5858
function isPortUsed(port: number): Promise<boolean> {
59-
const tryConnectPromise = new Promise((resolve, reject) => {
59+
const tryConnectPromise = new Promise((resolve) => {
6060
const client = new net.Socket()
6161
client
6262
.once("connect", () => {
@@ -134,7 +134,7 @@ function handleJsonRequest(body, res) {
134134
const port = Number(body.port)
135135
getLogger().info("Remote debug target attach request", body)
136136
const target = attachReady.get(port)
137-
if (target != null) {
137+
if (target !== undefined) {
138138
debugRequests.next({
139139
type,
140140
command,

lib/debugger/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { fastDebounce } from "@atom-ide-community/nuclide-commons/observable"
1010
import UniversalDisposable from "@atom-ide-community/nuclide-commons/UniversalDisposable"
1111
import { Observable } from "rxjs-compat/bundles/rxjs-compat.umd.min.js"
1212
import { track } from "@atom-ide-community/nuclide-commons/analytics"
13-
import * as RemoteDebuggerCommandServiceLocal from "./RemoteDebuggerCommandService"
1413
import nullthrows from "nullthrows"
15-
import { getLogger } from "log4js"
1614

1715
let _rpcService: ?nuclide$RpcService = null
1816

@@ -52,6 +50,7 @@ export function listenToRemoteDebugCommands(): IDisposable {
5250
const rootUri = hostname === "local" ? "" : nuclideUri.createRemoteUri(hostname, "/")
5351
const service = getRemoteDebuggerCommandServiceByNuclideUri(rootUri)
5452
if (service == null) {
53+
const { getLogger } = require("log4js")
5554
getLogger().error("null remote command service for uri:", rootUri)
5655
return Observable.empty()
5756
} else {
@@ -146,6 +145,7 @@ function findDuplicateAttachTargetIds(targets: Array<PythonDebuggerAttachTarget>
146145
}
147146

148147
export function getRemoteDebuggerCommandServiceByNuclideUri(uri: NuclideUri): RemoteDebuggerCommandService {
148+
const RemoteDebuggerCommandServiceLocal = require("./RemoteDebuggerCommandService")
149149
if (_rpcService == null && !nuclideUri.isRemote(uri)) {
150150
return RemoteDebuggerCommandServiceLocal
151151
}

lib/main.js

+23-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createDebuggerProvider, activate as debuggerActivate, dispose as debugg
77

88
// Ref: https://github.com/nteract/hydrogen/blob/master/lib/autocomplete-provider.js#L33
99
// adapted from http://stackoverflow.com/q/5474008
10-
const PYTHON_REGEX = /(([^\d\W]|[\u00A0-\uFFFF])[\w.\u00A0-\uFFFF]*)|\.$/
10+
const PYTHON_REGEX = /(([^\W\d]|[\u00A0-\uFFFF])[\w.\u00A0-\uFFFF]*)|\.$/
1111

1212
class PythonLanguageClient extends AutoLanguageClient {
1313
activate() {
@@ -23,8 +23,12 @@ class PythonLanguageClient extends AutoLanguageClient {
2323
atom.notifications.addSuccess("ide-pyhon: atom-ide-base was installed and enabled...")
2424
})
2525
}
26+
// Remove deprecated option
27+
atom.config.unset("ide-python.pylsPath")
28+
debuggerActivate()
2629
}
2730

31+
/* eslint-disable class-methods-use-this */
2832
getGrammarScopes() {
2933
return ["source.python", "python"]
3034
}
@@ -41,13 +45,6 @@ class PythonLanguageClient extends AutoLanguageClient {
4145
return "ide-python"
4246
}
4347

44-
activate() {
45-
// Remove deprecated option
46-
atom.config.unset("ide-python.pylsPath")
47-
super.activate()
48-
debuggerActivate()
49-
}
50-
5148
mapConfigurationObject(configuration) {
5249
return {
5350
pyls: {
@@ -57,20 +54,28 @@ class PythonLanguageClient extends AutoLanguageClient {
5754
},
5855
}
5956
}
57+
/* eslint-enable class-methods-use-this */
6058

6159
async startServerProcess(projectPath) {
6260
const venvPath = (await detectPipEnv(projectPath)) || (await detectVirtualEnv(projectPath))
6361
const pylsEnvironment = Object.assign({}, process.env)
6462
if (venvPath) {
65-
pylsEnvironment["VIRTUAL_ENV"] = venvPath
63+
pylsEnvironment.VIRTUAL_ENV = venvPath
64+
}
65+
66+
let pythonBin = atom.config.get("ide-python.python") || "python3"
67+
if (whichSync(pythonBin, { nothrow: true }) === null) {
68+
pythonBin = "python"
6669
}
67-
this.python = replacePipEnvPathVar(atom.config.get("ide-python.python"), venvPath)
70+
71+
this.python = replacePipEnvPathVar(pythonBin, venvPath)
6872

6973
let pyls = atom.config.get("ide-python.pyls") || "pylsp"
7074
// check if it exists
7175
if (whichSync(pyls, { nothrow: true }) === null) {
7276
pyls = "pyls"
7377
}
78+
7479
const childProcess = super.spawn(this.python, ["-m", pyls], {
7580
cwd: projectPath,
7681
env: pylsEnvironment,
@@ -80,7 +85,7 @@ class PythonLanguageClient extends AutoLanguageClient {
8085

8186
onSpawnError(err) {
8287
const description =
83-
err.code == "ENOENT"
88+
err.code === "ENOENT"
8489
? `No Python interpreter found at \`${this.python}\`.`
8590
: `Could not spawn the Python interpreter \`${this.python}\`.`
8691
atom.notifications.addError("`ide-python` could not launch your Python runtime.", {
@@ -90,7 +95,7 @@ class PythonLanguageClient extends AutoLanguageClient {
9095
}
9196

9297
onSpawnClose(code, signal) {
93-
if (code !== 0 && signal == null) {
98+
if (code !== 0 && signal === null) {
9499
atom.notifications.addError("Unable to start the Python language server.", {
95100
dismissable: true,
96101
buttons: [
@@ -113,8 +118,10 @@ class PythonLanguageClient extends AutoLanguageClient {
113118
}
114119
}
115120

116-
async getSuggestions(request) {
117-
if (!PYTHON_REGEX.test(request.prefix)) return null
121+
getSuggestions(request) {
122+
if (!PYTHON_REGEX.test(request.prefix)) {
123+
return null
124+
}
118125
return super.getSuggestions(request)
119126
}
120127

@@ -124,8 +131,8 @@ class PythonLanguageClient extends AutoLanguageClient {
124131
}
125132

126133
createTimeoutPromise(milliseconds) {
127-
return new Promise((resolve, reject) => {
128-
let timeout = setTimeout(() => {
134+
return new Promise((resolve) => {
135+
const timeout = setTimeout(() => {
129136
clearTimeout(timeout)
130137
this.logger.error(`Server failed to shutdown in ${milliseconds}ms, forcing termination`)
131138
resolve()

lib/utils.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,29 @@ function detectPipEnv(path) {
2222
}
2323

2424
async function detectVirtualEnv(path) {
25-
const entries = await new Promise((resolve) =>
26-
new Directory(path).getEntries((error, entries) => {
25+
const entries = await new Promise((resolve) => {
26+
new Directory(path).getEntries((error, resolvedEntries) => {
2727
if (error === null) {
28-
resolve(entries)
28+
resolve(resolvedEntries)
2929
} else {
3030
resolve(null)
3131
}
3232
})
33-
)
33+
})
3434
if (entries) {
35-
for (let entry of entries) {
35+
for (const entry of entries) {
3636
if (entry.isDirectory()) {
3737
if (VIRTUAL_ENV_BIN_DIRS.indexOf(entry.getBaseName()) !== -1) {
38-
for (let executable of VIRTUAL_ENV_EXECUTABLES) {
38+
for (const executable of VIRTUAL_ENV_EXECUTABLES) {
39+
/* eslint-disable-next-line no-await-in-loop */
3940
if (await entry.getFile(executable).exists()) {
4041
return path
4142
}
4243
}
4344
} else {
44-
for (let dir_name of VIRTUAL_ENV_BIN_DIRS) {
45-
for (let executable of VIRTUAL_ENV_EXECUTABLES) {
45+
for (const dir_name of VIRTUAL_ENV_BIN_DIRS) {
46+
for (const executable of VIRTUAL_ENV_EXECUTABLES) {
47+
/* eslint-disable-next-line no-await-in-loop */
4648
if (await entry.getSubdirectory(dir_name).getFile(executable).exists()) {
4749
return entry.getPath()
4850
}

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
"babel": "npm run clean && shx cp -r lib dist && cross-env NODE_ENV=production cross-env BABEL_KEEP_MODULES=false babel dist --out-dir dist",
3838
"copy": "shx cp -r lib/debugger/VendorLib dist/debugger",
3939
"build": "npm run babel",
40-
"build-commit": "build-commit -o dist",
41-
"prepare": "npm run build"
40+
"build-commit": "build-commit -o dist"
4241
},
4342
"package-deps": [
4443
"atom-ide-base"
@@ -48,7 +47,7 @@
4847
"@atom-ide-community/nuclide-commons-atom": "^0.8.2",
4948
"@atom-ide-community/nuclide-debugger-common": "^0.8.2",
5049
"arch": "2.1.0",
51-
"atom-languageclient": "^1.12.1",
50+
"atom-languageclient": "^1.14.1",
5251
"atom-package-deps": "^7.2.3",
5352
"dotenv": "5.0.1",
5453
"fs-extra": "4.0.3",
@@ -77,9 +76,10 @@
7776
"devDependencies": {
7877
"@babel/cli": "7.14.3",
7978
"@babel/core": "7.14.3",
80-
"babel-preset-atomic": "^4.1.0",
79+
"babel-preset-atomic": "^4.2.0",
8180
"build-commit": "0.1.4",
8281
"cross-env": "^7.0.3",
82+
"eslint-config-atomic": "^1.16.2",
8383
"mock-spawn": "0.2.6",
8484
"prettier-config-atomic": "^2.0.5",
8585
"shx": "^0.3.3"
@@ -96,7 +96,7 @@
9696
"title": "Python Executable",
9797
"order": 1,
9898
"type": "string",
99-
"default": "python",
99+
"default": "python3",
100100
"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. Use `$PIPENV_PATH/bin/python` if you want to use the pipenv path of your project"
101101
},
102102
"pyls": {

0 commit comments

Comments
 (0)