|
Lines 490-496
class Spec:
Link Here
|
| 490 |
return spec |
490 |
return spec |
| 491 |
|
491 |
|
| 492 |
|
492 |
|
| 493 |
def replace_macros(string: str, spec: Spec) -> str: |
493 |
def replace_macros(string: str, spec: Spec, max_attempts: int = 1000) -> str: |
| 494 |
"""Replace all macros in given string with corresponding values. |
494 |
"""Replace all macros in given string with corresponding values. |
| 495 |
|
495 |
|
| 496 |
For example, a string '%{name}-%{version}.tar.gz' will be transformed to 'foo-2.0.tar.gz'. |
496 |
For example, a string '%{name}-%{version}.tar.gz' will be transformed to 'foo-2.0.tar.gz'. |
|
Lines 552-561
def replace_macros(string: str, spec: Sp
Link Here
|
| 552 |
|
552 |
|
| 553 |
return match.string[match.start() : match.end()] |
553 |
return match.string[match.start() : match.end()] |
| 554 |
|
554 |
|
| 555 |
# Recursively expand macros |
555 |
# Recursively expand macros, respecting the limit imposed by 'max_attempts' |
| 556 |
# Note: If macros are not defined in the spec file, this won't try to |
556 |
# Note: If macros are not defined in the spec file, this won't try to |
| 557 |
# expand them. |
557 |
# expand them. |
| 558 |
while True: |
558 |
attempt = 0 |
|
|
559 |
while attempt < max_attempts: |
| 560 |
attempt += 1 |
| 559 |
ret = re.sub(_macro_pattern, get_replacement_string, string) |
561 |
ret = re.sub(_macro_pattern, get_replacement_string, string) |
| 560 |
if ret != string: |
562 |
if ret != string: |
| 561 |
string = ret |
563 |
string = ret |