mirror of
https://github.com/starship/starship.git
synced 2025-03-12 05:59:17 +01:00
feat(python): add support for python_binary
arguments in config (#6523)
This commit is contained in:
parent
eb42f5ac70
commit
76675559c0
35
.github/config-schema.json
vendored
35
.github/config-schema.json
vendored
@ -1459,9 +1459,15 @@
|
||||
"pyenv_prefix": "pyenv ",
|
||||
"pyenv_version_name": false,
|
||||
"python_binary": [
|
||||
"python",
|
||||
"python3",
|
||||
[
|
||||
"python"
|
||||
],
|
||||
[
|
||||
"python3"
|
||||
],
|
||||
[
|
||||
"python2"
|
||||
]
|
||||
],
|
||||
"style": "yellow bold",
|
||||
"symbol": "🐍 ",
|
||||
@ -5325,13 +5331,19 @@
|
||||
},
|
||||
"python_binary": {
|
||||
"default": [
|
||||
"python",
|
||||
"python3",
|
||||
[
|
||||
"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": [
|
||||
{
|
||||
|
@ -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<VecOr<&'a str>>,
|
||||
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",
|
||||
|
@ -93,14 +93,24 @@ fn get_pyenv_version(context: &Context) -> Option<String> {
|
||||
}
|
||||
|
||||
fn get_python_version(context: &Context, config: &PythonConfig) -> Option<String> {
|
||||
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<String> {
|
||||
|
Loading…
Reference in New Issue
Block a user