From 7eb374416adcddd32be0e7927c47835482dc43eb Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Mon, 11 Dec 2023 10:43:44 +0100 Subject: [PATCH 1/2] docs: clearify which scripts can be used --- docs/configuration.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index f2a682f2f..d86336359 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -313,14 +313,20 @@ If the project is cross-compiled, the architecture of the build and target machi If you want to run an activation script inside the environment when either doing a `pixi run` or `pixi shell` these can be defined here. The scripts defined in this table will be sourced when the environment is activated using `pixi run` or `pixi shell` +!!! note + The activation scripts are run by the system shell interpreter as they run before an environment is available. + This means that it runs as `cmd.exe` on windows and `bash` on linux and osx (Unix). + Only `.sh`, `.bash` and `.bat` files are supported. + + If you have scripts per platform use the [target](#the-target-table) table. + ```toml [activation] scripts = ["env_setup.sh"] +# To support windows platforms as well add the following +[target.win-64.activation] +scripts = ["env_setup.bat"] ``` -!!! note - Specify different scripts for different platforms using the [target](#the-target-table) table - - ## The `target` table The target table is a table that allows for platform specific configuration. From 0ef5c31cc19ef6db30cf0502f91f354a5f86dbb5 Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Mon, 11 Dec 2023 10:44:00 +0100 Subject: [PATCH 2/2] ux: add warning when using wrong script format --- src/cli/run.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cli/run.rs b/src/cli/run.rs index e89f42216..4a7c9cc5a 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -306,7 +306,19 @@ pub async fn run_activation_async( project: &Project, prefix: Prefix, ) -> miette::Result> { - let additional_activation_scripts = project.activation_scripts(Platform::current())?; + let platform = Platform::current(); + let additional_activation_scripts = project.activation_scripts(platform)?; + + // Check if the platform and activation script extension match. For Platform::Windows the extension should be .bat and for All other platforms it should be .sh or .bash. + for script in additional_activation_scripts.iter() { + let extension = script.extension().unwrap_or_default(); + if platform.is_windows() && extension != "bat" { + tracing::warn!("The activation script '{}' does not have the correct extension for the platform '{}'. The extension should be '.bat'.", script.display(), platform); + } else if !platform.is_windows() && extension != "sh" && extension != "bash" { + tracing::warn!("The activation script '{}' does not have the correct extension for the platform '{}'. The extension should be '.sh' or '.bash'.", script.display(), platform); + } + } + await_in_progress( "activating environment", run_activation(prefix, additional_activation_scripts.into_iter().collect()),