Skip to content

Commit

Permalink
Misc/improve ux activation scripts (#560)
Browse files Browse the repository at this point in the history
Hopefully helping the users with confusion around the activation
scripts.

Related issue: #551
  • Loading branch information
ruben-arts authored Dec 11, 2023
1 parent 136e066 commit 506dd16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 10 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 13 additions & 1 deletion src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,19 @@ pub async fn run_activation_async(
project: &Project,
prefix: Prefix,
) -> miette::Result<HashMap<String, String>> {
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()),
Expand Down

0 comments on commit 506dd16

Please sign in to comment.