MCPcopy Index your code
hub / github.com/RustPython/RustPython / expand_makefile_vars

Function expand_makefile_vars

Lib/sysconfig/__init__.py:754–789  ·  view source on GitHub ↗

Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in 'string' according to 'vars' (a dictionary mapping variable names to values). Variables not present in 'vars' are silently expanded to the empty string. The variable values in 'vars' should not contain further variable e

(s, vars)

Source from the content-addressed store, hash-verified

752
753
754def expand_makefile_vars(s, vars):
755 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
756 'string' according to 'vars' (a dictionary mapping variable names to
757 values). Variables not present in 'vars' are silently expanded to the
758 empty string. The variable values in 'vars' should not contain further
759 variable expansions; if 'vars' is the output of 'parse_makefile()',
760 you're fine. Returns a variable-expanded version of 's'.
761 """
762
763 import warnings
764 warnings.warn(
765 'sysconfig.expand_makefile_vars is deprecated and will be removed in '
766 'Python 3.16. Use sysconfig.get_paths(vars=...) instead.',
767 DeprecationWarning,
768 stacklevel=2,
769 )
770
771 import re
772
773 _findvar1_rx = r"\$\(([A-Za-z][A-Za-z0-9_]*)\)"
774 _findvar2_rx = r"\${([A-Za-z][A-Za-z0-9_]*)}"
775
776 # This algorithm does multiple expansion, so if vars['foo'] contains
777 # "${bar}", it will expand ${foo} to ${bar}, and then expand
778 # ${bar}... and so forth. This is fine as long as 'vars' comes from
779 # 'parse_makefile()', which takes care of such expansions eagerly,
780 # according to make's variable expansion semantics.
781
782 while True:
783 m = re.search(_findvar1_rx, s) or re.search(_findvar2_rx, s)
784 if m:
785 (beg, end) = m.span()
786 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
787 else:
788 break
789 return s

Callers

nothing calls this directly

Calls 5

spanMethod · 0.80
warnMethod · 0.45
searchMethod · 0.45
getMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected