-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c344f8c
commit ff6f11f
Showing
2 changed files
with
37 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import re | ||
|
||
def extract_version_from_cmake(): | ||
cmake_file = 'CMakeLists.txt' | ||
|
||
if not os.path.exists(cmake_file): | ||
raise FileNotFoundError(f"{cmake_file} not found in the current directory") | ||
|
||
with open(cmake_file, 'r') as file: | ||
content = file.read() | ||
|
||
major = re.search(r'set\(LIB3MF_VERSION_MAJOR\s+([0-9]+)\)', content) | ||
minor = re.search(r'set\(LIB3MF_VERSION_MINOR\s+([0-9]+)\)', content) | ||
micro = re.search(r'set\(LIB3MF_VERSION_MICRO\s+([0-9]+)\)', content) | ||
prerelease = re.search(r'set\(LIB3MF_VERSION_PRERELEASE\s+"([^"]*)"\)', content) | ||
|
||
if not major or not minor or not micro: | ||
raise ValueError("Could not find version components in CMakeLists.txt") | ||
|
||
version = f"{major.group(1)}.{minor.group(1)}.{micro.group(1)}" | ||
if prerelease and prerelease.group(1): | ||
version += f"-{prerelease.group(1)}" | ||
|
||
return version | ||
|
||
if __name__ == "__main__": | ||
try: | ||
version = extract_version_from_cmake() | ||
print(version) | ||
except Exception as e: | ||
print(f"Error: {str(e)}") |