MCPcopy Create free account
hub / github.com/FastLED/FastLED / _resolve_variable_substitution

Function _resolve_variable_substitution

ci/compiler/platformio_ini.py:444–485  ·  view source on GitHub ↗

Resolve variable substitution in a configuration value. Supports patterns like ${env:generic-esp.build_flags} and ${platformio.build_cache_dir}. Args: value: Value potentially containing variable references config: ConfigParser to resolve variables from Returns:

(
    value: str, config: configparser.ConfigParser
)

Source from the content-addressed store, hash-verified

442
443
444def _resolve_variable_substitution(
445 value: str, config: configparser.ConfigParser
446) -> str:
447 """
448 Resolve variable substitution in a configuration value.
449 Supports patterns like ${env:generic-esp.build_flags} and ${platformio.build_cache_dir}.
450
451 Args:
452 value: Value potentially containing variable references
453 config: ConfigParser to resolve variables from
454
455 Returns:
456 Value with variables resolved
457 """
458 if not value or "${" not in value:
459 return value
460
461 # Pattern to match ${section.option} or ${section:subsection.option}
462 pattern = r"\$\{([^}]+)\}"
463
464 def replace_variable(match: re.Match[str]) -> str:
465 var_ref = match.group(1)
466
467 # Handle section:subsection.option format (like env:generic-esp.build_flags)
468 if ":" in var_ref:
469 section_part, option = var_ref.split(".", 1)
470 section = section_part.replace(":", ":")
471 else:
472 # Handle section.option format (like platformio.build_cache_dir)
473 section, option = var_ref.split(".", 1)
474
475 try:
476 if config.has_option(section, option):
477 return config.get(section, option)
478 else:
479 # Return original if not found
480 return match.group(0)
481 except (configparser.NoSectionError, configparser.NoOptionError):
482 # Return original if resolution fails
483 return match.group(0)
484
485 return re.sub(pattern, replace_variable, value)
486
487
488def _resolve_list_variables(

Callers 2

_resolve_list_variablesFunction · 0.85
_parse_env_sectionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected