Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc/improve ux activation scripts #560

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -306,7 +306,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