Skip to content

Add conda-forge activation script support with pattern matching#281

Merged
wolfv merged 3 commits intomainfrom
claude/test-conda-activation-scripts-RelVH
Mar 21, 2026
Merged

Add conda-forge activation script support with pattern matching#281
wolfv merged 3 commits intomainfrom
claude/test-conda-activation-scripts-RelVH

Conversation

@wolfv
Copy link
Member

@wolfv wolfv commented Mar 20, 2026

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.pest and parser.rs)

  • Added support for indirect variable expansion (${!var}) for dynamic variable name resolution
  • Implemented variable pattern modifiers:
    • ${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
  • Added logical operators in conditionals (|| and &&)
  • Added support for function keyword in function definitions
  • Added ConditionExpression as a standalone command type for bare conditional expressions like [[ -d $DIR ]]
  • Created PATTERN_PENDING_WORD rule to allow : in pattern matching contexts

Execution Engine (execute.rs)

  • Implemented pattern matching functions (remove_suffix, remove_prefix, glob_match) with support for glob-style wildcards
  • Added evaluation of logical operators (LogicalOr, LogicalAnd) in conditions with proper short-circuit behavior
  • Changed if-clause condition evaluation to execute as a SequentialList (compound command) rather than a pure conditional, allowing complex command sequences in conditions
  • Added execution handler for standalone ConditionExpression commands
  • Implemented variable modifiers for all new pattern and check operations

Testing Infrastructure

  • Added comprehensive test suite (conda_activation_tests.rs) with 30+ tests covering:
    • Real conda-forge activation scripts (go, rust, flang, compiler toolchains)
    • Pattern matching operations
    • Indirect variable expansion
    • Logical operators in conditionals
    • Function definitions with various syntaxes
    • Common activation script patterns (backup/restore, path manipulation, platform checks)
  • Added test_conda_activation.sh script to download and test real activation scripts from conda-forge feedstocks
  • Includes template variable preprocessing to replace conda-build variables (@VAR@) with plausible dummy values

Notable Implementation Details

  • Pattern matching uses glob-style semantics where * matches any sequence of characters
  • Logical operators in conditionals properly short-circuit (e.g., || stops evaluating after first true condition)
  • If-clause conditions now execute as full command sequences, allowing environment variable changes from commands to persist
  • Indirect variable expansion (${!ref}) resolves the variable name first, then expands the result
  • The CheckSet and CheckUnset modifiers distinguish between unset and empty variables, matching bash semantics

https://claude.ai/code/session_0178vMPxzmTVt9Kso1zkYjeN

claude and others added 3 commits March 20, 2026 07:30
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
@wolfv wolfv merged commit 72201e7 into main Mar 21, 2026
8 checks passed
@wolfv wolfv deleted the claude/test-conda-activation-scripts-RelVH branch March 21, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants