diff --git a/.github/config-schema.json b/.github/config-schema.json index 111fb0650..19b284087 100644 --- a/.github/config-schema.json +++ b/.github/config-schema.json @@ -1459,9 +1459,15 @@ "pyenv_prefix": "pyenv ", "pyenv_version_name": false, "python_binary": [ - "python", - "python3", - "python2" + [ + "python" + ], + [ + "python3" + ], + [ + "python2" + ] ], "style": "yellow bold", "symbol": "🐍 ", @@ -5325,13 +5331,19 @@ }, "python_binary": { "default": [ - "python", - "python3", - "python2" + [ + "python" + ], + [ + "python3" + ], + [ + "python2" + ] ], "allOf": [ { - "$ref": "#/definitions/Either_for_String_and_Array_of_String" + "$ref": "#/definitions/Either_for_Either_for_String_and_Array_of_String_and_Array_of_Either_for_String_and_Array_of_String" } ] }, @@ -5400,6 +5412,19 @@ }, "additionalProperties": false }, + "Either_for_Either_for_String_and_Array_of_String_and_Array_of_Either_for_String_and_Array_of_String": { + "anyOf": [ + { + "$ref": "#/definitions/Either_for_String_and_Array_of_String" + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/Either_for_String_and_Array_of_String" + } + } + ] + }, "Either_for_String_and_Array_of_String": { "anyOf": [ { diff --git a/src/configs/python.rs b/src/configs/python.rs index f85f5c7c4..c894180b8 100644 --- a/src/configs/python.rs +++ b/src/configs/python.rs @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; pub struct PythonConfig<'a> { pub pyenv_version_name: bool, pub pyenv_prefix: &'a str, - pub python_binary: VecOr<&'a str>, + pub python_binary: VecOr>, pub format: &'a str, pub version_format: &'a str, pub style: &'a str, @@ -29,7 +29,11 @@ impl Default for PythonConfig<'_> { PythonConfig { pyenv_version_name: false, pyenv_prefix: "pyenv ", - python_binary: VecOr(vec!["python", "python3", "python2"]), + python_binary: VecOr(vec![ + VecOr(vec!["python"]), + VecOr(vec!["python3"]), + VecOr(vec!["python2"]), + ]), format: "via [${symbol}${pyenv_prefix}(${version} )(\\($virtualenv\\) )]($style)", version_format: "v${raw}", style: "yellow bold", diff --git a/src/modules/python.rs b/src/modules/python.rs index 5b4701e37..786984f60 100644 --- a/src/modules/python.rs +++ b/src/modules/python.rs @@ -93,14 +93,24 @@ fn get_pyenv_version(context: &Context) -> Option { } fn get_python_version(context: &Context, config: &PythonConfig) -> Option { - let version = config + config .python_binary .0 .iter() - .find_map(|binary| context.exec_cmd(binary, &["--version"])) - .map(get_command_string_output)?; + .find_map(|binary| { + let command = binary.0.first()?; + let args: Vec<_> = binary + .0 + .iter() + .skip(1) + .copied() + .chain(std::iter::once("--version")) + .collect(); - parse_python_version(&version) + context.exec_cmd(command, &args) + }) + .map(get_command_string_output) + .map(|output| parse_python_version(&output))? } fn parse_python_version(python_version_string: &str) -> Option {