Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 2ea7caf

Browse files
committed
Change python executable
1 parent 5b4e490 commit 2ea7caf

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ abs_file_path = os.path.abspath(os.path.join(vault_path, file_path))
7474
print(f"This is the open file: {abs_file_path}")
7575
```
7676

77-
## TODO
77+
## Settings
7878

79-
- Auto reload when python dir is updated
79+
You have the ability to change the python script location in settings. Additionally you have the ability to change which python executable is used.
80+
81+
## Debugging
82+
83+
If your script fails to run. An error is shown in the top right of obsidian and in the *developer console* which can be found with the following hotkeys: "ctrl" + "shift" + "i" on Windows, or "cmd" + "option" + "i" on MacOS

main.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { exec } from 'child_process';
66

77
interface PythonScripterSettings {
88
pythonPath: string;
9+
pythonExe: string;
910
}
1011

1112
const DEFAULT_SETTINGS: PythonScripterSettings = {
12-
pythonPath: ""
13+
pythonPath: "",
14+
pythonExe: ""
1315
}
1416

1517
export default class PythonScripterPlugin extends Plugin {
@@ -63,28 +65,35 @@ export default class PythonScripterPlugin extends Plugin {
6365
console.error(err);
6466
return;
6567
}
68+
let python_exe = "python";
69+
if (this.settings.pythonExe != "") {
70+
python_exe = this.settings.pythonExe
71+
}
6672
if (stats.isFile()) {
6773
var local_current_file_path = this.app.workspace.activeEditor?.file?.path;
6874
if (local_current_file_path === undefined) {
6975
local_current_file_path = "";
7076
}
71-
exec(`python \"${filePath}\" \"${basePath}\" \"${local_current_file_path}\"`, {cwd: this.pythonDirectory}, (error: any, stdout: any, stderr: any) => {
77+
78+
79+
exec(`${python_exe} \"${filePath}\" \"${basePath}\" \"${local_current_file_path}\"`, {cwd: this.pythonDirectory}, (error: any, stdout: any, stderr: any) => {
7280
if (error) {
7381
new Notice(`Error executing script ${filePath}: ${error}`);
82+
console.log(`Error executing script ${filePath}: ${error}`)
7483
return;
7584
}
7685
new Notice(`Script ` + fileName + ` output:\n${stdout}`);
7786
});
7887
} else if (stats.isDirectory()) {
7988
var dir = path.join(filePath);
80-
var executable = path.join(".", filePath, "src", "main.py");
8189
var local_current_file_path = this.app.workspace.activeEditor?.file?.path;
8290
if (local_current_file_path === undefined) {
8391
local_current_file_path = "";
8492
}
85-
exec(`python \"${path.join(filePath, "src", "main.py")}\" \"${basePath}\" \"${local_current_file_path}\"`, {cwd: dir}, (error: any, stdout: any, stderr: any) => {
93+
exec(`${python_exe} \"${path.join(filePath, "src", "main.py")}\" \"${basePath}\" \"${local_current_file_path}\"`, {cwd: dir}, (error: any, stdout: any, stderr: any) => {
8694
if (error) {
8795
new Notice(`Error executing folder program: ${error}`);
96+
console.log(`Error executing folder program: ${error}`)
8897
return;
8998
}
9099
new Notice(`Script ` + fileName + " " + basePath + ` output:\n${stdout}`);
@@ -138,5 +147,15 @@ class PythonScripterSettingTab extends PluginSettingTab {
138147
this.plugin.settings.pythonPath = value;
139148
await this.plugin.saveSettings();
140149
}));
150+
new Setting(containerEl)
151+
.setName('Python Executable')
152+
.setDesc('Defaults to python')
153+
.addText(text => text
154+
.setPlaceholder('Enter path or command')
155+
.setValue(this.plugin.settings.pythonExe)
156+
.onChange(async (value) => {
157+
this.plugin.settings.pythonExe = value;
158+
await this.plugin.saveSettings();
159+
}));
141160
}
142161
}

0 commit comments

Comments
 (0)