|
30 | 30 | import tomllib |
31 | 31 | from pathlib import Path |
32 | 32 | from typing import Any |
33 | | -from warnings import warn |
34 | 33 |
|
35 | 34 | # ## Local First Party Imports ---- |
36 | 35 | from toolbox_python.dictionaries import DotDict |
@@ -98,30 +97,32 @@ def update_files(files: list[DotDict]) -> None: |
98 | 97 | ### Extract variables ---- |
99 | 98 | filepath = Path(file.file) |
100 | 99 | pattern: str = file.pattern |
101 | | - search_pattern: str = pattern.replace("{VERSION}", ".*?") |
| 100 | + search_pattern: str = "^" + pattern.replace("{VERSION}", ".*?") |
102 | 101 |
|
103 | 102 | ### Check ---- |
104 | 103 | if args.verbose: |
105 | 104 | print(f"- {file.file}") |
106 | 105 |
|
107 | 106 | ### Check if the file exists ---- |
108 | 107 | if not filepath.exists(): |
109 | | - warn(f"-- File does not exist: {file.file}") |
| 108 | + print(f"-- File does not exist: {file.file}") |
110 | 109 | continue |
111 | 110 |
|
112 | 111 | ### Read the file ---- |
113 | 112 | content: str = filepath.read_text() |
114 | 113 |
|
115 | 114 | ### Check if the pattern exists in the file ---- |
116 | | - if not re.search(search_pattern, content): |
117 | | - warn(f"-- Pattern not found in file: {file.pattern}") |
| 115 | + if not re.search(pattern=search_pattern, string=content, flags=re.MULTILINE): |
| 116 | + print(f"-- !! Pattern not found in file: {file.pattern}") |
118 | 117 | continue |
119 | 118 |
|
120 | 119 | new_content: list[str] = [] |
121 | 120 | for line in content.splitlines(): |
122 | | - if re.search(search_pattern, line): |
| 121 | + if re.search(pattern=search_pattern, string=line, flags=re.MULTILINE): |
123 | 122 | new_line: str = re.sub( |
124 | | - search_pattern, pattern.replace("{VERSION}", args.version), line |
| 123 | + pattern=search_pattern, |
| 124 | + repl=pattern.replace("{VERSION}", args.version), |
| 125 | + string=line, |
125 | 126 | ) |
126 | 127 | new_content.append(new_line) |
127 | 128 | if args.verbose: |
|
0 commit comments