Skip to content

Commit cb830c1

Browse files
committed
TMC_LANGS_PYTHON_EXEC for overriding python executable
1 parent 1498ec0 commit cb830c1

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

tmc-langs-python3/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Environment variables
2+
3+
| var name | usage |
4+
| ----------------------- | --------------------------- |
5+
| `TMC_LANGS_PYTHON_EXEC` | Sets the Python executable. |

tmc-langs-python3/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ enum LocalPy {
1818
Unix,
1919
Windows,
2020
WindowsConda { conda_path: String },
21+
Custom { python_exec: String },
2122
}
2223

2324
lazy_static! {
2425
// the python command is platform-dependent
2526
static ref LOCAL_PY: LocalPy = {
27+
if let Ok(python_exec) = env::var("TMC_LANGS_PYTHON_EXEC") {
28+
log::debug!("using Python from environment variable TMC_LANGS_PYTHON_EXEC={}", python_exec);
29+
return LocalPy::Custom { python_exec };
30+
}
31+
2632
if cfg!(windows) {
2733
// Check for Conda
2834
let conda = env::var("CONDA_PYTHON_EXE");

tmc-langs-python3/src/plugin.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ impl LanguagePlugin for Python3Plugin {
4949
path: &Path,
5050
timeout: Option<Duration>,
5151
) -> Result<RunResult, TmcError> {
52-
let run_result = run_tmc_command(path, &[], timeout);
53-
54-
if let Err(error) = run_result {
55-
log::error!("Failed to parse exercise description. {}", error);
56-
}
57-
52+
run_tmc_command(path, &[], timeout)?;
5853
Ok(parse_test_result(path)?)
5954
}
6055

@@ -98,11 +93,13 @@ fn run_tmc_command(
9893
LocalPy::Unix => ("python3", Command::new("python3")),
9994
LocalPy::Windows => ("py", Command::new("py")),
10095
LocalPy::WindowsConda { conda_path } => ("conda", Command::new(conda_path)),
96+
LocalPy::Custom { python_exec } => (python_exec.as_str(), Command::new(python_exec)),
10197
};
10298
let command = match &*LOCAL_PY {
10399
LocalPy::Unix => &mut command,
104100
LocalPy::Windows => command.args(&["-3"]),
105101
LocalPy::WindowsConda { .. } => &mut command,
102+
LocalPy::Custom { .. } => &mut command,
106103
};
107104
let command = command
108105
.args(&common_args)

0 commit comments

Comments
 (0)