feat: Add support for pixi (#6335)

---------

Co-authored-by: Lucas Colley <lucas.colley8@gmail.com>
Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
This commit is contained in:
Pavel Zwerschke
2025-04-26 22:13:57 +02:00
committed by GitHub
parent ed07646099
commit 7e88ba9561
19 changed files with 566 additions and 797 deletions
+277 -770
View File
File diff suppressed because it is too large Load Diff
+57 -14
View File
@@ -957,6 +957,7 @@ If you use [pixi](https://pixi.sh), you can disable pixi's prompt modifier by ru
| `style` | `'bold green'` | The style for the module. |
| `format` | `'via [$symbol$environment]($style) '` | The format for the module. |
| `ignore_base` | `true` | Ignores `base` environment when activated. |
| `detect_env_vars` | `["!PIXI_ENVIRONMENT_NAME"]` | Which environment variable(s) should trigger this module. If it's a pixi environment, this module is not being triggered by default. |
| `disabled` | `false` | Disables the `conda` module. |
### Variables
@@ -3652,6 +3653,49 @@ The `pijul_channel` module shows the active channel of the repo in your current
| `truncation_symbol` | `'…'` | The symbol used to indicate a branch name was truncated. |
| `disabled` | `true` | Disables the `pijul` module. |
## Pixi
The `pixi` module shows the installed [pixi](https://pixi.sh) version as well as the activated environment, if `$PIXI_ENVIRONMENT_NAME` is set.
::: tip
This does not suppress pixi's own prompt modifier, you may want to run `pixi config set change-ps1 false`.
:::
### Options
| Option | Default | Description |
| -------------------------- | ------------------------------------------------------- | --------------------------------------------------------------------------------- |
| `format` | `'via [$symbol($version )(\($environment\) )]($style)'` | The format for the module. |
| `version_format` | `'v${raw}'` | The version format. Available vars are `raw`, `major`, `minor`, & `patch`. |
| `symbol` | `'🧚 '` | The symbol used before the environment name. |
| `style` | `'yellow bold' | The style for the module. |
| `show_default_environment` | `true` | Whether to indicate that the `default` environment of your project is activated. |
| `pixi_binary` | `['pixi']` | Configures the pixi binary that Starship should execute when getting the version. |
| `detect_extensions` | `[]` | Which extensions should trigger this module. |
| `detect_files` | `['pixi.toml']` | Which filenames should trigger this module. |
| `detect_folders` | `['.pixi']` | Which folders should trigger this module. |
| `disabled` | `false` | Disables the `pixi` module. |
### Variables
| Variable | Example | Description |
| ----------- | --------- | ------------------------------------ |
| version | `v0.33.0` | The version of `pixi` |
| environment | `py311` | The current pixi environment |
| symbol | | Mirrors the value of option `symbol` |
| style | | Mirrors the value of option `style` |
### Example
```toml
# ~/.config/starship.toml
[pixi]
format = '[$symbol$environment](yellow) '
```
## Pulumi
The `pulumi` module shows the current username, selected [Pulumi Stack](https://www.pulumi.com/docs/intro/concepts/stack/), and version.
@@ -3770,26 +3814,25 @@ By default, the module will be shown if any of the following conditions are met:
- The current directory contains a `requirements.txt` file
- The current directory contains a `setup.py` file
- The current directory contains a `tox.ini` file
- The current directory contains a `pixi.toml` file
- The current directory contains a file with the `.py` extension.
- The current directory contains a file with the `.ipynb` extension.
- A virtual environment is currently activated
### Options
| Option | Default | Description |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| `format` | `'via [${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style)'` | The format for the module. |
| `version_format` | `'v${raw}'` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
| `symbol` | `'🐍 '` | A format string representing the symbol of Python |
| `style` | `'yellow bold'` | The style for the module. |
| `pyenv_version_name` | `false` | Use pyenv to get Python version |
| `pyenv_prefix` | `'pyenv'` | Prefix before pyenv version display, only used if pyenv is used |
| `python_binary` | `['python', 'python3', 'python2']` | Configures the python binaries that Starship should executes when getting the version. |
| `detect_extensions` | `['py', 'ipynb']` | Which extensions should trigger this module |
| `detect_files` | `['.python-version', 'Pipfile', '__init__.py', 'pyproject.toml', 'requirements.txt', 'setup.py', 'tox.ini', 'pixi.toml']` | Which filenames should trigger this module |
| `detect_folders` | `[]` | Which folders should trigger this module |
| `disabled` | `false` | Disables the `python` module. |
| Option | Default | Description |
| -------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- |
| `format` | `'via [${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style)'` | The format for the module. |
| `version_format` | `'v${raw}'` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
| `symbol` | `'🐍 '` | A format string representing the symbol of Python |
| `style` | `'yellow bold'` | The style for the module. |
| `pyenv_version_name` | `false` | Use pyenv to get Python version |
| `pyenv_prefix` | `'pyenv'` | Prefix before pyenv version display, only used if pyenv is used |
| `python_binary` | `['python', 'python3', 'python2']` | Configures the python binaries that Starship should execute when getting the version. |
| `detect_extensions` | `['py', 'ipynb']` | Which extensions should trigger this module |
| `detect_files` | `['.python-version', 'Pipfile', '__init__.py', 'pyproject.toml', 'requirements.txt', 'setup.py', 'tox.ini']` | Which filenames should trigger this module |
| `detect_folders` | `[]` | Which folders should trigger this module |
| `disabled` | `false` | Disables the `python` module. |
::: tip
@@ -139,6 +139,9 @@ format = '\[[$symbol($version)]($style)\]'
[pijul_channel]
format = '\[[$symbol$channel]($style)\]'
[pixi]
format = '\[[$symbol$version( $environment)]($style)\]'
[pulumi]
format = '\[[$symbol$stack]($style)\]'
@@ -23,6 +23,7 @@ $python\
[](fg:color_blue bg:color_bg3)\
$docker_context\
$conda\
$pixi\
[](fg:color_bg3 bg:color_bg1)\
$time\
[ ](fg:color_bg1)\
@@ -156,6 +157,10 @@ format = '[[ $symbol( $context) ](fg:#83a598 bg:color_bg3)]($style)'
style = "bg:color_bg3"
format = '[[ $symbol( $environment) ](fg:#83a598 bg:color_bg3)]($style)'
[pixi]
style = "bg:color_bg3"
format = '[[ $symbol( $version)( $environment) ](fg:color_fg0 bg:color_bg3)]($style)'
[time]
disabled = false
time_format = "%R"
+5
View File
@@ -73,6 +73,7 @@ $vagrant\
$zig\
$buf\
$conda\
$pixi\
$meson\
$spack\
$memory_usage\
@@ -267,6 +268,10 @@ format = " [$symbol($version(-$name))]($style)"
symbol = "◯ "
format = " conda [$symbol$environment]($style)"
[pixi]
symbol = "■ "
format = " pixi [$symbol$version ($environment )]($style)"
[dart]
symbol = "◁◅ "
format = " dart [$symbol($version )]($style)"
@@ -159,6 +159,9 @@ symbol = " "
[pijul_channel]
symbol = " "
[pixi]
symbol = "󰏗 "
[python]
symbol = " "
@@ -82,6 +82,9 @@ format = 'via [$symbol]($style)'
[perl]
format = 'via [$symbol]($style)'
[pixi]
format = 'via [$symbol($environment )]($style)'
[php]
format = 'via [$symbol]($style)'
@@ -204,6 +204,9 @@ symbol = "php "
[pijul_channel]
symbol = "pijul "
[pixi]
symbol = "pixi "
[pulumi]
symbol = "pulumi "
+2
View File
@@ -13,6 +13,7 @@ pub struct CondaConfig<'a> {
pub symbol: &'a str,
pub style: &'a str,
pub ignore_base: bool,
pub detect_env_vars: Vec<&'a str>,
pub disabled: bool,
}
@@ -24,6 +25,7 @@ impl Default for CondaConfig<'_> {
symbol: "🅒 ",
style: "green bold",
ignore_base: true,
detect_env_vars: vec!["!PIXI_ENVIRONMENT_NAME"],
disabled: false,
}
}
+3
View File
@@ -72,6 +72,7 @@ pub mod package;
pub mod perl;
pub mod php;
pub mod pijul_channel;
pub mod pixi;
pub mod pulumi;
pub mod purescript;
pub mod python;
@@ -255,6 +256,8 @@ pub struct FullConfig<'a> {
#[serde(borrow)]
pijul_channel: pijul_channel::PijulConfig<'a>,
#[serde(borrow)]
pixi: pixi::PixiConfig<'a>,
#[serde(borrow)]
pulumi: pulumi::PulumiConfig<'a>,
#[serde(borrow)]
purescript: purescript::PureScriptConfig<'a>,
+40
View File
@@ -0,0 +1,40 @@
use serde::{Deserialize, Serialize};
use crate::config::VecOr;
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(default)]
pub struct PixiConfig<'a> {
pub pixi_binary: VecOr<&'a str>,
pub show_default_environment: bool,
pub format: &'a str,
pub version_format: &'a str,
pub symbol: &'a str,
pub style: &'a str,
pub disabled: bool,
pub detect_extensions: Vec<&'a str>,
pub detect_files: Vec<&'a str>,
pub detect_folders: Vec<&'a str>,
}
impl Default for PixiConfig<'_> {
fn default() -> Self {
PixiConfig {
pixi_binary: VecOr(vec!["pixi"]),
show_default_environment: true,
format: "via [$symbol($version )(\\($environment\\) )]($style)",
version_format: "v${raw}",
symbol: "🧚 ",
style: "yellow bold",
disabled: false,
detect_extensions: vec![],
detect_files: vec!["pixi.toml", "pixi.lock"],
detect_folders: vec![".pixi"],
}
}
}
-1
View File
@@ -48,7 +48,6 @@ impl Default for PythonConfig<'_> {
"tox.ini",
"setup.py",
"__init__.py",
"pixi.toml",
],
detect_folders: vec![],
detect_env_vars: vec!["VIRTUAL_ENV"],
+1
View File
@@ -106,6 +106,7 @@ pub const PROMPT_ORDER: &[&str] = &[
"guix_shell",
"nix_shell",
"conda",
"pixi",
"meson",
"spack",
"memory_usage",
+1
View File
@@ -76,6 +76,7 @@ pub const ALL_MODULES: &[&str] = &[
"perl",
"php",
"pijul_channel",
"pixi",
"pulumi",
"purescript",
"python",
+15
View File
@@ -20,6 +20,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
if config.ignore_base && conda_env == "base" {
return None;
}
if !context.detect_env_vars(&config.detect_env_vars) {
return None;
}
let conda_env = truncate(&conda_env, config.truncation_length).unwrap_or(conda_env);
@@ -80,6 +83,18 @@ mod tests {
assert_eq!(expected, actual);
}
#[test]
fn ignore_pixi_envs() {
let actual = ModuleRenderer::new("conda")
.env("CONDA_DEFAULT_ENV", "my-env")
.env("PIXI_ENVIRONMENT_NAME", "my-env")
.collect();
let expected = None;
assert_eq!(expected, actual);
}
#[test]
fn env_set() {
let actual = ModuleRenderer::new("conda")
+5
View File
@@ -69,6 +69,7 @@ mod package;
mod perl;
mod php;
mod pijul_channel;
mod pixi;
mod pulumi;
mod purescript;
mod python;
@@ -183,6 +184,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
"perl" => perl::module(context),
"php" => php::module(context),
"pijul_channel" => pijul_channel::module(context),
"pixi" => pixi::module(context),
"pulumi" => pulumi::module(context),
"purescript" => purescript::module(context),
"python" => python::module(context),
@@ -312,6 +314,9 @@ pub fn description(module: &str) -> &'static str {
"perl" => "The currently installed version of Perl",
"php" => "The currently installed version of PHP",
"pijul_channel" => "The current channel of the repo in the current directory",
"pixi" => {
"The currently installed version of Pixi, and the active environment if $PIXI_ENVIRONMENT_NAME is set"
}
"pulumi" => "The current username, stack, and installed version of Pulumi",
"purescript" => "The currently installed version of PureScript",
"python" => "The currently installed version of Python",
+139
View File
@@ -0,0 +1,139 @@
use super::{Context, Module, ModuleConfig};
use crate::configs::pixi::PixiConfig;
use crate::formatter::{StringFormatter, VersionFormatter};
use crate::utils::get_command_string_output;
/// Creates a module with the current Pixi environment
///
/// Will display the Pixi environment iff `$PIXI_ENVIRONMENT_NAME` is set.
/// Will display the Pixi version iff pixi files are detected or `$PIXI_ENVIRONMENT_NAME` is set.
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("pixi");
let config: PixiConfig = PixiConfig::try_load(module.config);
let pixi_environment_name = context.get_env("PIXI_ENVIRONMENT_NAME");
let is_pixi_project = pixi_environment_name.is_some()
|| context
.try_begin_scan()?
.set_files(&config.detect_files)
.set_extensions(&config.detect_extensions)
.set_folders(&config.detect_folders)
.is_match();
if !is_pixi_project {
return None;
}
let pixi_environment_name = if !config.show_default_environment
&& pixi_environment_name == Some("default".to_string())
{
None
} else {
pixi_environment_name
};
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|variable, _| match variable {
"symbol" => Some(config.symbol),
_ => None,
})
.map_style(|variable| match variable {
"style" => Some(Ok(config.style)),
_ => None,
})
.map(|variable| match variable {
"environment" => pixi_environment_name.clone().map(Ok),
"version" => {
let pixi_version = get_pixi_version(context, &config)?;
VersionFormatter::format_module_version(
module.get_name(),
&pixi_version,
config.version_format,
)
.map(Ok)
}
_ => None,
})
.parse(None, Some(context))
});
module.set_segments(match parsed {
Ok(segments) => segments,
Err(error) => {
log::warn!("Error in module `pixi`:\n{}", error);
return None;
}
});
Some(module)
}
fn get_pixi_version(context: &Context, config: &PixiConfig) -> Option<String> {
let version = config
.pixi_binary
.0
.iter()
.find_map(|binary| context.exec_cmd(binary, &["--version"]))
.map(get_command_string_output)?;
Some(version.split_once(" ")?.1.trim().to_string())
}
#[cfg(test)]
mod tests {
use std::{fs::File, io};
use crate::test::ModuleRenderer;
use nu_ansi_term::Color;
#[test]
fn not_in_env() {
let actual = ModuleRenderer::new("pixi").collect();
let expected = None;
assert_eq!(expected, actual);
}
#[test]
fn ignore_default_environment() {
let actual = ModuleRenderer::new("pixi")
.env("PIXI_ENVIRONMENT_NAME", "default")
.config(toml::toml! {
[pixi]
show_default_environment = false
})
.collect();
let expected = Some(format!("via {}", Color::Yellow.bold().paint("🧚 v0.33.0 ")));
assert_eq!(expected, actual);
}
#[test]
fn env_set() {
let actual = ModuleRenderer::new("pixi")
.env("PIXI_ENVIRONMENT_NAME", "py312")
.collect();
let expected = Some(format!(
"via {}",
Color::Yellow.bold().paint("🧚 v0.33.0 (py312) ")
));
assert_eq!(expected, actual);
}
#[test]
fn folder_with_pixi_toml() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("pixi.toml"))?.sync_all()?;
let actual = ModuleRenderer::new("pixi").path(dir.path()).collect();
let expected = Some(format!("via {}", Color::Yellow.bold().paint("🧚 v0.33.0 ")));
assert_eq!(expected, actual);
dir.close()
}
}
-12
View File
@@ -289,18 +289,6 @@ Python 3.7.9 (7e6e2bb30ac5fbdbd443619cae28c51d5c162a02, Nov 24 2020, 10:03:59)
dir.close()
}
#[test]
fn folder_with_pixi_file() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("pixi.toml"))?.sync_all()?;
check_python2_renders(&dir, None);
check_python3_renders(&dir, None);
check_pyenv_renders(&dir, None);
check_multiple_binaries_renders(&dir, None);
dir.close()
}
#[test]
fn folder_with_ipynb_file() -> io::Result<()> {
let dir = tempfile::tempdir()?;
+4
View File
@@ -440,6 +440,10 @@ WebAssembly: unavailable
stdout: String::from("Outputting repository ↖"),
stderr: String::default(),
}),
"pixi --version" => Some(CommandOutput {
stdout: String::from("pixi 0.33.0"),
stderr: String::default(),
}),
"pulumi version" => Some(CommandOutput {
stdout: String::from("1.2.3-ver.1631311768+e696fb6c"),
stderr: String::default(),