Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue_1499
Browse files Browse the repository at this point in the history
  • Loading branch information
tdejager authored Jun 18, 2024
2 parents 4f10a1a + f8f84d3 commit e16c359
Show file tree
Hide file tree
Showing 25 changed files with 528 additions and 177 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.24.2] - 2024-06-14
#### Documentation
- Add readthedocs examples by @bollwyvl in [#1423](https://github.com/prefix-dev/pixi/pull/1423)
- Fix typo in project_configuration.md by @RaulPL in [#1502](https://github.com/prefix-dev/pixi/pull/1502)

#### Fixed
- Too much shell variables in activation of `pixi shell` by @ruben-arts in [#1507](https://github.com/prefix-dev/pixi/pull/1507)

## [0.24.1] - 2024-06-12
### 📃 Details
#### Fixed
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ authors:
name-particle: de
family-names: Jager
email: [email protected]
repository-code: 'https://github.com/prefix-dev/pixi/releases/tag/v0.24.1'
url: 'https://pixi.sh/v0.24.1'
repository-code: 'https://github.com/prefix-dev/pixi/releases/tag/v0.24.2'
url: 'https://pixi.sh/v0.24.2'
abstract: >-
A cross-platform, language agnostic, package/project
management tool for development in virtual environments.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pixi"
version = "0.24.1"
version = "0.24.2"
description = "A package management and workflow tool"
edition = "2021"
authors = ["pixi contributors <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/github_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ We created [prefix-dev/setup-pixi](https://github.com/prefix-dev/setup-pixi) to
```yaml
- uses: prefix-dev/[email protected]
with:
pixi-version: v0.24.1
pixi-version: v0.24.2
cache: true
auth-host: prefix.dev
auth-token: ${{ secrets.PREFIX_DEV_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion docs/basic_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Use the `shell` command to activate the environment and start a new shell in the
```shell
pixi shell
python
exit
exit()
```

You've just learned the basic features of pixi:
Expand Down
31 changes: 31 additions & 0 deletions docs/dev-release-steps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Making a release of pixi

## Prep
- Make sure main is up-to-date and ci passes: [![build-badge](https://img.shields.io/github/actions/workflow/status/prefix-dev/pixi/rust.yml?style=flat-square&branch=main)](https://github.com/prefix-dev/pixi/actions/workflows/rust.yml?query=branch%3Amain+)
- Set the variable `export RELEASE_VERSION=X.Y.Z` in your shell
- Make a new branch for the release: `git checkout main && git pull upstream main && git checkout -b bump/prepare-v$RELEASE_VERSION`
- Bump all versions: `pixi run bump`
- Update the changelog: `pixi run bump-changelog`
- Don't forget to update the "Highlights" section.
- Commit the changes: `git commit -am "chore: version to $RELEASE_VERSION"`
- Push the changes: `git push origin`

## Release prep PR
- Create a PR to check off the change with the peers
- Merge that PR

## Tagging the release
- Checkout main: `git fetch && git checkout upstream/main`
- Tag the release: `git tag v$RELEASE_VERSION -m "Release $RELEASE_VERSION"`
- Push the tag: `git push upstream v$RELEASE_VERSION`

## Publishing the release
- After that, update the Release which has CI created for you (after the first build) and add the changelog to the release notes.
- Make sure all the artifacts are there and the CI is green!!!
- Publish the release and make sure it is set as latest.

## Test the release using the install script:
- `curl -fsSL https://pixi.sh/install.sh | bash` or `iwr -useb https://pixi.sh/install.ps1 | iex`
- `pixi --version` should show the new version

DONE!
2 changes: 1 addition & 1 deletion install/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.LINK
https://github.com/prefix-dev/pixi
.NOTES
Version: v0.24.1
Version: v0.24.2
#>
param (
[string] $PixiVersion = 'latest',
Expand Down
2 changes: 1 addition & 1 deletion install/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
# Version: v0.24.1
# Version: v0.24.2

__wrap__() {

Expand Down
180 changes: 180 additions & 0 deletions pixi.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install = "cargo install --path . --locked"
test = "cargo test"
test-all = "cargo test --all-features"
lint = "pre-commit run --all"
bump = "tbump --only-patch"
bump = "tbump --only-patch $RELEASE_VERSION"
pypi-proxy = "python ./tests/pypi_proxy.py"

[feature.dev.dependencies]
Expand All @@ -44,13 +44,15 @@ pillow = ">=9.4.0"
cairosvg = "2.7.1.*"
mike = "2.0.0.*"
mkdocs-redirects = ">=1.2.1,<2"
git-cliff = ">=2.2.1,<2.4"

[feature.docs.tasks]
build-docs = "mkdocs build --strict"
docs = "mkdocs serve"
deploy-latest = "mike deploy --push --update-aliases $RELEASE_VERSION latest"
deploy-dev = "mike deploy --push dev devel"
mike-serve = "mike serve"
bump-changelog = "git-cliff --unreleased --prepend CHANGELOG.md --tag $RELEASE_VERSION"

[feature.schema.tasks]
generate-schema = { cmd = "python model.py > schema.json", cwd = "schema" }
Expand All @@ -67,6 +69,6 @@ pyyaml = ">=6.0.1,<6.1"
taplo = ">=0.9.1,<0.10"

[environments]
default = { features = ["build", "dev", "docs", "schema"], solve-group = "one"}
docs = { features = ["docs"], no-default-feature = true, solve-group = "one"}
schema = { features = ["schema"], no-default-feature = true , solve-group = "one"}
default = { features = ["build", "dev", "docs", "schema"], solve-group = "default"}
docs = { features = ["docs"], no-default-feature = true, solve-group = "default"}
schema = { features = ["schema"], no-default-feature = true , solve-group = "default"}
4 changes: 2 additions & 2 deletions schema/schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://pixi.sh/v0.24.1/schema/manifest/schema.json",
"$id": "https://pixi.sh/v0.24.2/schema/manifest/schema.json",
"title": "`pixi.toml` manifest file",
"description": "The configuration for a [`pixi`](https://pixi.sh) project.",
"type": "object",
Expand All @@ -13,7 +13,7 @@
"title": "Schema",
"description": "The schema identifier for the project's configuration",
"type": "string",
"default": "https://pixi.sh/v0.24.1/schema/manifest/schema.json",
"default": "https://pixi.sh/v0.24.2/schema/manifest/schema.json",
"format": "uri-reference"
},
"activation": {
Expand Down
119 changes: 54 additions & 65 deletions src/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@ use std::collections::HashMap;
use itertools::Itertools;
use miette::IntoDiagnostic;
use rattler_conda_types::Platform;
use rattler_shell::activation::ActivationError::FailedToRunActivationScript;
use rattler_shell::{
activation::{ActivationError, ActivationVariables, Activator, PathModificationBehavior},
activation::{
ActivationError, ActivationError::FailedToRunActivationScript, ActivationVariables,
Activator, PathModificationBehavior,
},
shell::ShellEnum,
};

use crate::project::has_features::HasFeatures;
use crate::{
environment::{get_up_to_date_prefix, LockFileUsage},
project::{manifest::EnvironmentName, Environment},
project::{has_features::HasFeatures, manifest::EnvironmentName, Environment},
Project,
};

// Setting a base prefix for the pixi package
const PROJECT_PREFIX: &str = "PIXI_PROJECT_";

pub enum CurrentEnvVarBehavior {
/// Clean the environment variables of the current shell.
/// This will return the minimal set of environment variables that are required to run the command.
Clean,
/// Copy the environment variables of the current shell.
Include,
/// Do not take any environment variables from the current shell.
Exclude,
}

impl Project {
/// Returns environment variables and their values that should be injected when running a command.
pub fn get_metadata_env(&self) -> HashMap<String, String> {
Expand Down Expand Up @@ -124,15 +134,15 @@ pub fn get_activator<'p>(
// Add the environment variables from the project.
activator
.env_vars
.extend(get_environment_variables(environment));
.extend(get_static_environment_variables(environment));

Ok(activator)
}

/// Runs and caches the activation script.
pub async fn run_activation(
environment: &Environment<'_>,
clean_env: bool,
env_var_behavior: &CurrentEnvVarBehavior,
) -> miette::Result<HashMap<String, String>> {
let activator = get_activator(environment, ShellEnum::default()).map_err(|e| {
miette::miette!(format!(
Expand All @@ -142,10 +152,11 @@ pub async fn run_activation(
))
})?;

let path_modification_behavior = if clean_env {
PathModificationBehavior::Replace
} else {
PathModificationBehavior::Prepend
let path_modification_behavior = match env_var_behavior {
// We need to replace the full environment path with the new one.
// So only the executables from the pixi environment are available.
CurrentEnvVarBehavior::Clean => PathModificationBehavior::Replace,
_ => PathModificationBehavior::Prepend,
};

let activator_result = match tokio::task::spawn_blocking(move || {
Expand Down Expand Up @@ -193,51 +204,13 @@ pub async fn run_activation(
}
};

if clean_env && cfg!(windows) {
return Err(miette::miette!(
format!("It's not possible to run a `clean-env` on Windows as it requires so many non conda specific files that it is basically useless to use. \
So pixi currently doesn't support this feature.")));
} else if clean_env {
let mut cleaned_environment_variables = get_clean_environment_variables();

// Extend with the original activation environment
cleaned_environment_variables.extend(activator_result);

// Enable this when we found a better way to support windows.
// On Windows the path is not completely replace, but we need to strip some paths to keep it as clean as possible.
// if cfg!(target_os = "windows") {
// let path = env
// .get("Path")
// .map(|path| {
// // Keep some of the paths
// let win_path = std::env::split_paths(&path).filter(|p| {
// // Required for base functionalities
// p.to_string_lossy().contains(":\\Windows")
// // Required for compilers
// || p.to_string_lossy().contains("\\Program Files")
// // Required for pixi environments
// || p.starts_with(environment.dir())
// });
// // Join back up the paths
// std::env::join_paths(win_path).expect("Could not join paths")
// })
// .expect("Could not find PATH in environment variables");
// // Insert the path back into the env.
// env.insert(
// "Path".to_string(),
// path.to_str()
// .expect("Path contains non-utf8 paths")
// .to_string(),
// );
// }

return Ok(cleaned_environment_variables);
}
Ok(std::env::vars().chain(activator_result).collect())
Ok(activator_result)
}

/// Get the environment variables that are statically generated from the project and the environment.
pub fn get_environment_variables<'p>(environment: &'p Environment<'p>) -> HashMap<String, String> {
pub fn get_static_environment_variables<'p>(
environment: &'p Environment<'p>,
) -> HashMap<String, String> {
// Get environment variables from the project
let project_env = environment.project().get_metadata_env();

Expand All @@ -260,6 +233,8 @@ pub fn get_environment_variables<'p>(environment: &'p Environment<'p>) -> HashMa
.collect()
}

/// Get the environment variables that are set in the current shell
/// and strip them down to the minimal set required to run a command.
pub fn get_clean_environment_variables() -> HashMap<String, String> {
let env = std::env::vars().collect::<HashMap<_, _>>();

Expand Down Expand Up @@ -302,18 +277,32 @@ pub fn get_clean_environment_variables() -> HashMap<String, String> {
/// Determine the environment variables that need to be set in an interactive shell to make it
/// function as if the environment has been activated. This method runs the activation scripts from
/// the environment and stores the environment variables it added, finally it adds environment
/// variables from the project.
pub async fn get_activation_env<'p>(
environment: &'p Environment<'p>,
lock_file_usage: LockFileUsage,
) -> miette::Result<&HashMap<String, String>> {
// Get the prefix which we can then activate.
get_up_to_date_prefix(environment, lock_file_usage, false).await?;

environment
.project()
.get_env_variables(environment, false)
.await
/// variables from the project and based on the clean_env setting it will also add in the current
/// shell environment variables.
pub(crate) async fn initialize_env_variables(
environment: &Environment<'_>,
env_var_behavior: CurrentEnvVarBehavior,
) -> miette::Result<HashMap<String, String>> {
let activation_env = run_activation(environment, &env_var_behavior).await?;

// Get environment variables from the currently activated shell.
let current_shell_env_vars = match env_var_behavior {
CurrentEnvVarBehavior::Clean if cfg!(windows) => {
return Err(miette::miette!(
"Currently it's not possible to run a `clean-env` option on Windows."
));
}
CurrentEnvVarBehavior::Clean => get_clean_environment_variables(),
CurrentEnvVarBehavior::Include => std::env::vars().collect(),
CurrentEnvVarBehavior::Exclude => HashMap::new(),
};

let all_variables: HashMap<String, String> = current_shell_env_vars
.into_iter()
.chain(activation_env)
.collect();

Ok(all_variables)
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod upload;
#[command(
version,
about = "
Pixi [version 0.24.1] - Developer Workflow and Environment Management for Multi-Platform, Language-Agnostic Projects.
Pixi [version 0.24.2] - Developer Workflow and Environment Management for Multi-Platform, Language-Agnostic Projects.
Pixi is a versatile developer workflow tool designed to streamline the management of your project's dependencies, tasks, and environments.
Built on top of the Conda ecosystem, Pixi offers seamless integration with the PyPI ecosystem.
Expand Down
Loading

0 comments on commit e16c359

Please sign in to comment.