-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathatom-python-run.js
More file actions
60 lines (57 loc) · 1.82 KB
/
atom-python-run.js
File metadata and controls
60 lines (57 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* global atom */
"use strict";
const path = require("path");
const child_process = require("child_process");
module.exports = {
activate: () => {
atom.commands.add("atom-text-editor", "Python run: run", run);
},
config: {
disable_notifications: {
title: "Disable notifications of success",
description: "Disable notifications of saving and running",
type: "boolean",
default: false
},
disable_notifications_on_fail: {
title: "Disable notifications of failure",
description: "Disable notifications of extension name does not match",
type: "boolean",
default: false
}
}
};
function run() {
var editor = atom.workspace.getActiveTextEditor();
if (!editor) {
return;
}
var file = editor.buffer.file;
if (!file) {
//if (!atom.config.get("atom-python-run.disable_notifications_on_fail")) {
atom.notifications.add("warning", "You have to create the file first.");
//}
return;
}
if (!atom.config.get("atom-python-run.disable_notifications")) {
atom.notifications.add("info", "Saving...");
}
editor.save();
var info = path.parse(file.path);
if (info.ext != ".py") {
if (!atom.config.get("atom-python-run.disable_notifications_on_fail")) {
atom.notifications.add("warning", info.base + " is not a .py file, exit.");
}
return;
}
if (!atom.config.get("atom-python-run.disable_notifications")) {
atom.notifications.add("info", "Running " + info.base + " ...");
}
var child = child_process.spawn("cmd", [
"/c", "start", __dirname + "/../bin/cp.exe", "python.exe", "\"" + file.path + "\""
], {
cwd: info.dir,
detached: true
});
child.unref();
}