MLCompilerBridge
Tools for streamlining communication with ML models for compiler optimizations.
Loading...
Searching...
No Matches
fetch_version.py
Go to the documentation of this file.
1# ------------------------------------------------------------------------------
2#
3# Part of the MLCompilerBridge Project, under the Apache License v2.0 with LLVM
4# Exceptions. See the LICENSE file for license information.
5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6#
7# ------------------------------------------------------------------------------
8
9import re
10
11version_regex = re.compile(r"^project\‍(MLCompilerBridge VERSION (?P<version>[^)]+)\‍)$")
12toml_field_regex = r'version[ ]*=[ ]*"(.*)"'
13
14VERSION = ""
15with open("../CMakeLists.txt", "r") as f:
16 for line in f:
17 vmatch = version_regex.match(line) # Not using walrus because Python3.6
18 if vmatch:
19 VERSION = vmatch.group("version")
20 break
21
22print("Version detected =", VERSION)
23lines = []
24with open("./pyproject.toml", "r") as f:
25 lines = f.readlines()
26
27with open("./pyproject.toml", "w") as f:
28 for line in lines:
29 if re.search(toml_field_regex, line):
30 new_text = f'version = "{VERSION}"\n'
31 f.write(new_text)
32 else:
33 f.write(line)