-
Notifications
You must be signed in to change notification settings - Fork 464
fix: Override environment variables based on priority #3940
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
Merged
Hofer-Julian
merged 79 commits into
prefix-dev:main
from
magentaqin:bugfix/environment-variable-priority
Aug 5, 2025
Merged
Changes from all commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
76bcfc4
feat: override environment variables based on priority and export all…
magentaqin c62be75
draft: override environment varibales of run_activation function in r…
magentaqin 30929bd
feat: [activation.env] should override activation scripts
magentaqin ab6dacc
chore: remove unecessary blank line
magentaqin 97c5921
fix: remove unnecessary binding
magentaqin 10b0607
test: update test for 'get_export_specific_task_env' and 'as_script'
magentaqin 42535ac
test: update unit tests
magentaqin 9be1dc2
fix: exclude certain keys
magentaqin bcf0ada
style: fix lint issues
magentaqin 418ef0f
test: add integration test for environment variable priority'
magentaqin edee77f
test: compare priority of activation.env and activation.script
magentaqin 237d5f5
fix: Platform-specific export format
magentaqin 98ff4c4
fix: Platform-specific export format with proper escaping
magentaqin 8b0e9e6
fix: escape opening parenthesis
magentaqin 289f389
fix: Early return if task.env() is empty
magentaqin dbdc7bd
fix: If task.env() and command_env don't have duplicated keys, simpl…
magentaqin 8784f5c
test: add test for activation.script > activation scripts from depen…
magentaqin 14325f2
test: update unit test
magentaqin 7b9d674
test: update test 'test_task_with_env'
magentaqin 9b690ca
fix: fix proper quotes
magentaqin 04d2edd
fix: fix esacpe parenthis
magentaqin ef68cc9
test: update env key
magentaqin 66701f5
fix: fix issues mentioned in PR comments
magentaqin 7302460
fix: fix windows test errors
magentaqin a3b8187
fix: Skip command env to avoid exporting system variables
magentaqin 28d78f2
fix: fix compatible issues in 'test_task_with_env'
magentaqin 3a31933
fix: fix compatible issues in 'test_task_with_env'
magentaqin db3b7c7
fix: fix compatible issues in 'test_run_with_environment_variable_pri…
magentaqin 80c6053
fix: fix compatible issues
magentaqin 5893e29
fix: fix compatible issues
magentaqin 7b6c081
fix: fix compatible issues
magentaqin f623552
fix: fix compatible issues
magentaqin 42c7707
fix: add single quote
magentaqin d3f8317
chore: remove spaces in test_task_with_env
magentaqin ace5ee3
fix: in windows, child shell should inherit the parent's environemnt …
magentaqin 7d295ca
fix: in windows, child shell should inherit the parent's environemnt …
magentaqin cd0c430
chore: add debugger helper for 'test_task_with_env'
magentaqin 6df2457
fix: revert changes
magentaqin 3a6b998
fix: remove set
magentaqin a1215ea
fix: fix powershell issues
magentaqin bc36791
fix: fix powershell compatible issues
magentaqin a64be50
fix: fix powershell compatible issues
magentaqin 5d12d82
fix: fix escaping issues
magentaqin 3c052ea
chore: print err for test_task_with_env
magentaqin 6bc06aa
fix: Use PowerShell environment variable syntax
magentaqin 38e066d
chore: add println for 'expected_prefix'
magentaqin b8dd9f3
fix: replace .bat with ps1
magentaqin f21a07d
chore: print echo_cmd
magentaqin 42b74df
fix: remove unecessary windows code
magentaqin 073b638
fix: fix linting error
magentaqin 9125d7c
fix: Only the keys that are in TASK_SPECIFIC_ENVS map would be exported.
magentaqin 1863e96
fix: use '. bat' for windows
magentaqin aa7f150
chore: print env set in windows
magentaqin 8f8c2c1
fix: specify 'target.win-64.activation' in pixi.toml
magentaqin b008b67
chore: remove unecessary echo
magentaqin a869e18
chore: update test order
magentaqin c2d5ec4
test: add tests for 'activation scripts from dependencies > outside e…
magentaqin 766d013
doc: add 'test' section to CONTRIBUTING.md
magentaqin 1b050d6
Update src/activation.rs
magentaqin 2c54b1e
Update src/task/executable_task.rs
magentaqin 506c853
Update tests/integration_python/test_run_cli.py
magentaqin ae1b505
chore: remove unecessary comments in test
magentaqin aff1145
doc: add doc to explain priority rules of environment variables defin…
magentaqin 969d2f7
refactor: refactor get_export_specific_task_env with EnvMap struct
magentaqin ab821a2
test: update tests-test unecessary exports
magentaqin 86456f6
Merge branch 'main' into bugfix/environment-variable-priority
lucascolley 82b9bfd
Merge branch 'main' into bugfix/environment-variable-priority
Hofer-Julian 7e03bd9
Apply suggestions from code review
lucascolley c17b427
move docs, add warning
lucascolley 347d019
fix syntax
lucascolley f429903
remove old docs
lucascolley 473c47d
fix syntax
lucascolley a1aa9f3
fix example syntax
lucascolley 0950cd4
add file names to docs
lucascolley 6c2096c
run CI
lucascolley 5ff1ed8
chore: merge main branch and solve conflicts
magentaqin c0b8849
feat: resolve variable references
magentaqin 5b82d73
docs: split docs between tasks and env vars pages
lucascolley 210a47d
Merge branch 'main' into bugfix/environment-variable-priority
lucascolley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,6 +236,19 @@ async fn try_get_valid_activation_cache( | |
| } | ||
| } | ||
|
|
||
| // Extract variable name | ||
| fn extract_variable_name(value: &str) -> Option<&str> { | ||
| if let Some(inner) = value.strip_prefix('$') { | ||
| Some(inner) | ||
| } else if let Some(inner) = value.strip_prefix('%').and_then(|s| s.strip_suffix('%')) { | ||
| Some(inner) | ||
| } else if let Some(inner) = value.strip_prefix("${").and_then(|s| s.strip_suffix('}')) { | ||
| Some(inner) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
|
Comment on lines
+239
to
+250
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Hofer-Julian do you know if we already have something like this elsewhere?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least after a quick look at our code base, I wouldn't be able to find it |
||
|
|
||
| /// Runs and caches the activation script. | ||
| pub async fn run_activation( | ||
| environment: &Environment<'_>, | ||
|
|
@@ -286,7 +299,7 @@ pub async fn run_activation( | |
| let current_env = std::env::vars().collect::<HashMap<_, _>>(); | ||
|
|
||
| // Run and cache the activation script | ||
| activator.run_activation( | ||
| let new_activator = activator.run_activation( | ||
| ActivationVariables { | ||
| // Get the current PATH variable | ||
| path: Default::default(), | ||
|
|
@@ -301,7 +314,29 @@ pub async fn run_activation( | |
| current_env, | ||
| }, | ||
| None, | ||
| ) | ||
| ); | ||
|
|
||
| // `activator.env_vars` should override `activator_result` for duplicate keys | ||
| new_activator.map(|mut map: HashMap<String, String>| { | ||
| // First pass: Add all variables from activator.env_vars(as map is unordered, we need to update the referenced value in the second loop) | ||
| for (k, v) in &activator.env_vars { | ||
| map.insert(k.clone(), v.clone()); | ||
| } | ||
|
|
||
| // Second pass: Loop through the map and resolve variable references | ||
| let keys_to_update: Vec<String> = map.keys().cloned().collect(); | ||
| for key in keys_to_update { | ||
| if let Some(value) = map.get(&key).cloned() { | ||
| if let Some(referenced_var) = extract_variable_name(&value) { | ||
| if let Some(actual_value) = map.get(referenced_var) { | ||
| map.insert(key, actual_value.clone()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| map | ||
| }) | ||
| }) | ||
| .await | ||
| .into_diagnostic()? | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.