Skip to content

Commit bbc62b7

Browse files
committed
Use regular expression for replacement version
Make the replacement work accross multiple python versions by using a regular expression instead of a version string.
1 parent 84cb890 commit bbc62b7

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

relenv/build/windows.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,41 @@ def populate_env(env, dirs):
3737

3838

3939
def patch_file(path, old, new):
40+
"""
41+
Search a file line by line for a string to replace.
42+
43+
:param path: Location of the file to search
44+
:type path: str
45+
:param old: The value that will be replaced
46+
:type path: str
47+
:param new: The value that will replace the 'old' value.
48+
:type path: str
49+
"""
50+
import re
51+
4052
with open(path, "r") as fp:
4153
content = fp.read()
4254
new_content = ""
4355
for line in content.splitlines():
44-
line.replace(old, new)
45-
new_content += line + os.linesp
56+
re.sub(old, new, line)
57+
new_content += line + os.linesep
4658
with open(path, "w") as fp:
4759
fp.write(new_content)
4860

4961

50-
def override_dependency_string(dirs, old, new):
51-
patch_file(dirs.source / "PCbuild" / "python.props", old, new)
52-
patch_file(dirs.source / "PCbuild" / "get_externals.bat", old, new)
53-
62+
def override_dependency(source, old, new):
63+
"""
64+
Overwrite a dependency string for Windoes PCBuild.
65+
66+
:param source: Python's source directory
67+
:type path: str
68+
:param old: Regular expression to search for
69+
:type path: str
70+
:param new: Replacement text
71+
:type path: str
72+
"""
73+
patch_file(source / "PCbuild" / "python.props", old, new)
74+
patch_file(source / "PCbuild" / "get_externals.bat", old, new)
5475

5576

5677
def build_python(env, dirs, logfp):
@@ -64,9 +85,8 @@ def build_python(env, dirs, logfp):
6485
:param logfp: A handle for the log file
6586
:type logfp: file
6687
"""
67-
6888
# Override default versions
69-
override_dependency(dirs, "sqlite-3.40.1.0", "sqlite-3.50.4.0")
89+
override_dependency(dirs.source, r"sqlite-\d+.\d+.\d+.\d+", "sqlite-3.50.4.0")
7090

7191
arch_to_plat = {
7292
"amd64": "x64",

0 commit comments

Comments
 (0)