Add conda-forge activation script support with pattern matching#281
Merged
Add conda-forge activation script support with pattern matching#281
Conversation
Add a bash script (scripts/test_conda_activation.sh) that downloads all
activation/deactivation .sh scripts from conda-forge feedstocks (go, rust,
flang, ctng-compiler, clang-compiler, clang-win) and runs them through
the shell binary to test compatibility.
Add Rust integration tests (conda_activation_tests.rs) that test specific
patterns used in these activation scripts. Results:
- 10 passing: simple exports, function definitions, conditionals, path
manipulation, backup/restore env vars
- 3 ignored (documents unsupported features):
- `function name() {}` syntax (bash keyword-style)
- `[[ ]]` double-bracket conditionals
- `${!var}` indirect variable expansion
https://claude.ai/code/session_0178vMPxzmTVt9Kso1zkYjeN
Implement multiple bash features required to run conda-forge activation
scripts:
- `function name() {}` syntax (bash keyword-style function definition)
- `[[ ]]` as standalone command (not just in if/while/until)
- `||` and `&&` inside `[[ ]]` conditional expressions
- `${!var}` indirect variable expansion
- `${var%%pattern}` / `${var%pattern}` suffix removal (longest/shortest)
- `${var##pattern}` / `${var#pattern}` prefix removal (longest/shortest)
- `${var+word}` / `${var-word}` check-set/check-unset modifiers
- `if compound_list; then` (POSIX-compliant if condition as command list)
These features enable the shell to parse and execute activation scripts
from go-activation, rust-activation, flang-activation, and the simpler
compiler activation feedstocks. All 68 tests pass with 0 ignored.
https://claude.ai/code/session_0178vMPxzmTVt9Kso1zkYjeN
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR adds comprehensive support for parsing and executing conda-forge activation scripts by implementing missing bash features including variable pattern matching, logical operators in conditionals, indirect variable expansion, and standalone condition expressions.
Key Changes
Parser Enhancements (
grammar.pestandparser.rs)${!var}) for dynamic variable name resolution${var%%pattern}- Remove longest matching suffix${var%pattern}- Remove shortest matching suffix${var##pattern}- Remove longest matching prefix${var#pattern}- Remove shortest matching prefix${var+word}- Substitute word if var is set${var-word}- Substitute word if var is unset||and&&)functionkeyword in function definitionsConditionExpressionas a standalone command type for bare conditional expressions like[[ -d $DIR ]]PATTERN_PENDING_WORDrule to allow:in pattern matching contextsExecution Engine (
execute.rs)remove_suffix,remove_prefix,glob_match) with support for glob-style wildcardsLogicalOr,LogicalAnd) in conditions with proper short-circuit behaviorSequentialList(compound command) rather than a pure conditional, allowing complex command sequences in conditionsConditionExpressioncommandsTesting Infrastructure
conda_activation_tests.rs) with 30+ tests covering:test_conda_activation.shscript to download and test real activation scripts from conda-forge feedstocks@VAR@) with plausible dummy valuesNotable Implementation Details
*matches any sequence of characters||stops evaluating after first true condition)${!ref}) resolves the variable name first, then expands the resultCheckSetandCheckUnsetmodifiers distinguish between unset and empty variables, matching bash semanticshttps://claude.ai/code/session_0178vMPxzmTVt9Kso1zkYjeN