mirror of
https://github.com/starship/starship.git
synced 2026-06-24 02:01:36 +07:00
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:
+277
-770
File diff suppressed because it is too large
Load Diff
+47
-4
@@ -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. |
|
| `style` | `'bold green'` | The style for the module. |
|
||||||
| `format` | `'via [$symbol$environment]($style) '` | The format for the module. |
|
| `format` | `'via [$symbol$environment]($style) '` | The format for the module. |
|
||||||
| `ignore_base` | `true` | Ignores `base` environment when activated. |
|
| `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. |
|
| `disabled` | `false` | Disables the `conda` module. |
|
||||||
|
|
||||||
### Variables
|
### 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. |
|
| `truncation_symbol` | `'…'` | The symbol used to indicate a branch name was truncated. |
|
||||||
| `disabled` | `true` | Disables the `pijul` module. |
|
| `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
|
## Pulumi
|
||||||
|
|
||||||
The `pulumi` module shows the current username, selected [Pulumi Stack](https://www.pulumi.com/docs/intro/concepts/stack/), and version.
|
The `pulumi` module shows the current username, selected [Pulumi Stack](https://www.pulumi.com/docs/intro/concepts/stack/), and version.
|
||||||
@@ -3770,7 +3814,6 @@ 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 `requirements.txt` file
|
||||||
- The current directory contains a `setup.py` file
|
- The current directory contains a `setup.py` file
|
||||||
- The current directory contains a `tox.ini` 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 `.py` extension.
|
||||||
- The current directory contains a file with the `.ipynb` extension.
|
- The current directory contains a file with the `.ipynb` extension.
|
||||||
- A virtual environment is currently activated
|
- A virtual environment is currently activated
|
||||||
@@ -3778,16 +3821,16 @@ By default, the module will be shown if any of the following conditions are met:
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| -------------------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
| -------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- |
|
||||||
| `format` | `'via [${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style)'` | The format for the module. |
|
| `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` |
|
| `version_format` | `'v${raw}'` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
|
||||||
| `symbol` | `'🐍 '` | A format string representing the symbol of Python |
|
| `symbol` | `'🐍 '` | A format string representing the symbol of Python |
|
||||||
| `style` | `'yellow bold'` | The style for the module. |
|
| `style` | `'yellow bold'` | The style for the module. |
|
||||||
| `pyenv_version_name` | `false` | Use pyenv to get Python version |
|
| `pyenv_version_name` | `false` | Use pyenv to get Python version |
|
||||||
| `pyenv_prefix` | `'pyenv'` | Prefix before pyenv version display, only used if pyenv is used |
|
| `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. |
|
| `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_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_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 |
|
| `detect_folders` | `[]` | Which folders should trigger this module |
|
||||||
| `disabled` | `false` | Disables the `python` module. |
|
| `disabled` | `false` | Disables the `python` module. |
|
||||||
|
|
||||||
|
|||||||
@@ -139,6 +139,9 @@ format = '\[[$symbol($version)]($style)\]'
|
|||||||
[pijul_channel]
|
[pijul_channel]
|
||||||
format = '\[[$symbol$channel]($style)\]'
|
format = '\[[$symbol$channel]($style)\]'
|
||||||
|
|
||||||
|
[pixi]
|
||||||
|
format = '\[[$symbol$version( $environment)]($style)\]'
|
||||||
|
|
||||||
[pulumi]
|
[pulumi]
|
||||||
format = '\[[$symbol$stack]($style)\]'
|
format = '\[[$symbol$stack]($style)\]'
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ $python\
|
|||||||
[](fg:color_blue bg:color_bg3)\
|
[](fg:color_blue bg:color_bg3)\
|
||||||
$docker_context\
|
$docker_context\
|
||||||
$conda\
|
$conda\
|
||||||
|
$pixi\
|
||||||
[](fg:color_bg3 bg:color_bg1)\
|
[](fg:color_bg3 bg:color_bg1)\
|
||||||
$time\
|
$time\
|
||||||
[ ](fg:color_bg1)\
|
[ ](fg:color_bg1)\
|
||||||
@@ -156,6 +157,10 @@ format = '[[ $symbol( $context) ](fg:#83a598 bg:color_bg3)]($style)'
|
|||||||
style = "bg:color_bg3"
|
style = "bg:color_bg3"
|
||||||
format = '[[ $symbol( $environment) ](fg:#83a598 bg:color_bg3)]($style)'
|
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]
|
[time]
|
||||||
disabled = false
|
disabled = false
|
||||||
time_format = "%R"
|
time_format = "%R"
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ $vagrant\
|
|||||||
$zig\
|
$zig\
|
||||||
$buf\
|
$buf\
|
||||||
$conda\
|
$conda\
|
||||||
|
$pixi\
|
||||||
$meson\
|
$meson\
|
||||||
$spack\
|
$spack\
|
||||||
$memory_usage\
|
$memory_usage\
|
||||||
@@ -267,6 +268,10 @@ format = " [$symbol($version(-$name))]($style)"
|
|||||||
symbol = "◯ "
|
symbol = "◯ "
|
||||||
format = " conda [$symbol$environment]($style)"
|
format = " conda [$symbol$environment]($style)"
|
||||||
|
|
||||||
|
[pixi]
|
||||||
|
symbol = "■ "
|
||||||
|
format = " pixi [$symbol$version ($environment )]($style)"
|
||||||
|
|
||||||
[dart]
|
[dart]
|
||||||
symbol = "◁◅ "
|
symbol = "◁◅ "
|
||||||
format = " dart [$symbol($version )]($style)"
|
format = " dart [$symbol($version )]($style)"
|
||||||
|
|||||||
@@ -159,6 +159,9 @@ symbol = " "
|
|||||||
[pijul_channel]
|
[pijul_channel]
|
||||||
symbol = " "
|
symbol = " "
|
||||||
|
|
||||||
|
[pixi]
|
||||||
|
symbol = " "
|
||||||
|
|
||||||
[python]
|
[python]
|
||||||
symbol = " "
|
symbol = " "
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ format = 'via [$symbol]($style)'
|
|||||||
[perl]
|
[perl]
|
||||||
format = 'via [$symbol]($style)'
|
format = 'via [$symbol]($style)'
|
||||||
|
|
||||||
|
[pixi]
|
||||||
|
format = 'via [$symbol($environment )]($style)'
|
||||||
|
|
||||||
[php]
|
[php]
|
||||||
format = 'via [$symbol]($style)'
|
format = 'via [$symbol]($style)'
|
||||||
|
|
||||||
|
|||||||
@@ -204,6 +204,9 @@ symbol = "php "
|
|||||||
[pijul_channel]
|
[pijul_channel]
|
||||||
symbol = "pijul "
|
symbol = "pijul "
|
||||||
|
|
||||||
|
[pixi]
|
||||||
|
symbol = "pixi "
|
||||||
|
|
||||||
[pulumi]
|
[pulumi]
|
||||||
symbol = "pulumi "
|
symbol = "pulumi "
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ pub struct CondaConfig<'a> {
|
|||||||
pub symbol: &'a str,
|
pub symbol: &'a str,
|
||||||
pub style: &'a str,
|
pub style: &'a str,
|
||||||
pub ignore_base: bool,
|
pub ignore_base: bool,
|
||||||
|
pub detect_env_vars: Vec<&'a str>,
|
||||||
pub disabled: bool,
|
pub disabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ impl Default for CondaConfig<'_> {
|
|||||||
symbol: "🅒 ",
|
symbol: "🅒 ",
|
||||||
style: "green bold",
|
style: "green bold",
|
||||||
ignore_base: true,
|
ignore_base: true,
|
||||||
|
detect_env_vars: vec!["!PIXI_ENVIRONMENT_NAME"],
|
||||||
disabled: false,
|
disabled: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ pub mod package;
|
|||||||
pub mod perl;
|
pub mod perl;
|
||||||
pub mod php;
|
pub mod php;
|
||||||
pub mod pijul_channel;
|
pub mod pijul_channel;
|
||||||
|
pub mod pixi;
|
||||||
pub mod pulumi;
|
pub mod pulumi;
|
||||||
pub mod purescript;
|
pub mod purescript;
|
||||||
pub mod python;
|
pub mod python;
|
||||||
@@ -255,6 +256,8 @@ pub struct FullConfig<'a> {
|
|||||||
#[serde(borrow)]
|
#[serde(borrow)]
|
||||||
pijul_channel: pijul_channel::PijulConfig<'a>,
|
pijul_channel: pijul_channel::PijulConfig<'a>,
|
||||||
#[serde(borrow)]
|
#[serde(borrow)]
|
||||||
|
pixi: pixi::PixiConfig<'a>,
|
||||||
|
#[serde(borrow)]
|
||||||
pulumi: pulumi::PulumiConfig<'a>,
|
pulumi: pulumi::PulumiConfig<'a>,
|
||||||
#[serde(borrow)]
|
#[serde(borrow)]
|
||||||
purescript: purescript::PureScriptConfig<'a>,
|
purescript: purescript::PureScriptConfig<'a>,
|
||||||
|
|||||||
@@ -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"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,7 +48,6 @@ impl Default for PythonConfig<'_> {
|
|||||||
"tox.ini",
|
"tox.ini",
|
||||||
"setup.py",
|
"setup.py",
|
||||||
"__init__.py",
|
"__init__.py",
|
||||||
"pixi.toml",
|
|
||||||
],
|
],
|
||||||
detect_folders: vec![],
|
detect_folders: vec![],
|
||||||
detect_env_vars: vec!["VIRTUAL_ENV"],
|
detect_env_vars: vec!["VIRTUAL_ENV"],
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ pub const PROMPT_ORDER: &[&str] = &[
|
|||||||
"guix_shell",
|
"guix_shell",
|
||||||
"nix_shell",
|
"nix_shell",
|
||||||
"conda",
|
"conda",
|
||||||
|
"pixi",
|
||||||
"meson",
|
"meson",
|
||||||
"spack",
|
"spack",
|
||||||
"memory_usage",
|
"memory_usage",
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ pub const ALL_MODULES: &[&str] = &[
|
|||||||
"perl",
|
"perl",
|
||||||
"php",
|
"php",
|
||||||
"pijul_channel",
|
"pijul_channel",
|
||||||
|
"pixi",
|
||||||
"pulumi",
|
"pulumi",
|
||||||
"purescript",
|
"purescript",
|
||||||
"python",
|
"python",
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
if config.ignore_base && conda_env == "base" {
|
if config.ignore_base && conda_env == "base" {
|
||||||
return None;
|
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);
|
let conda_env = truncate(&conda_env, config.truncation_length).unwrap_or(conda_env);
|
||||||
|
|
||||||
@@ -80,6 +83,18 @@ mod tests {
|
|||||||
assert_eq!(expected, actual);
|
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]
|
#[test]
|
||||||
fn env_set() {
|
fn env_set() {
|
||||||
let actual = ModuleRenderer::new("conda")
|
let actual = ModuleRenderer::new("conda")
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ mod package;
|
|||||||
mod perl;
|
mod perl;
|
||||||
mod php;
|
mod php;
|
||||||
mod pijul_channel;
|
mod pijul_channel;
|
||||||
|
mod pixi;
|
||||||
mod pulumi;
|
mod pulumi;
|
||||||
mod purescript;
|
mod purescript;
|
||||||
mod python;
|
mod python;
|
||||||
@@ -183,6 +184,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
|
|||||||
"perl" => perl::module(context),
|
"perl" => perl::module(context),
|
||||||
"php" => php::module(context),
|
"php" => php::module(context),
|
||||||
"pijul_channel" => pijul_channel::module(context),
|
"pijul_channel" => pijul_channel::module(context),
|
||||||
|
"pixi" => pixi::module(context),
|
||||||
"pulumi" => pulumi::module(context),
|
"pulumi" => pulumi::module(context),
|
||||||
"purescript" => purescript::module(context),
|
"purescript" => purescript::module(context),
|
||||||
"python" => python::module(context),
|
"python" => python::module(context),
|
||||||
@@ -312,6 +314,9 @@ pub fn description(module: &str) -> &'static str {
|
|||||||
"perl" => "The currently installed version of Perl",
|
"perl" => "The currently installed version of Perl",
|
||||||
"php" => "The currently installed version of PHP",
|
"php" => "The currently installed version of PHP",
|
||||||
"pijul_channel" => "The current channel of the repo in the current directory",
|
"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",
|
"pulumi" => "The current username, stack, and installed version of Pulumi",
|
||||||
"purescript" => "The currently installed version of PureScript",
|
"purescript" => "The currently installed version of PureScript",
|
||||||
"python" => "The currently installed version of Python",
|
"python" => "The currently installed version of Python",
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -289,18 +289,6 @@ Python 3.7.9 (7e6e2bb30ac5fbdbd443619cae28c51d5c162a02, Nov 24 2020, 10:03:59)
|
|||||||
dir.close()
|
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]
|
#[test]
|
||||||
fn folder_with_ipynb_file() -> io::Result<()> {
|
fn folder_with_ipynb_file() -> io::Result<()> {
|
||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
|
|||||||
@@ -440,6 +440,10 @@ WebAssembly: unavailable
|
|||||||
stdout: String::from("Outputting repository ↖"),
|
stdout: String::from("Outputting repository ↖"),
|
||||||
stderr: String::default(),
|
stderr: String::default(),
|
||||||
}),
|
}),
|
||||||
|
"pixi --version" => Some(CommandOutput {
|
||||||
|
stdout: String::from("pixi 0.33.0"),
|
||||||
|
stderr: String::default(),
|
||||||
|
}),
|
||||||
"pulumi version" => Some(CommandOutput {
|
"pulumi version" => Some(CommandOutput {
|
||||||
stdout: String::from("1.2.3-ver.1631311768+e696fb6c"),
|
stdout: String::from("1.2.3-ver.1631311768+e696fb6c"),
|
||||||
stderr: String::default(),
|
stderr: String::default(),
|
||||||
|
|||||||
Reference in New Issue
Block a user