-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
2 changed files
with
57 additions
and
0 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,48 @@ | ||
import subprocess | ||
import sys | ||
import re | ||
import os | ||
|
||
|
||
def get_latest_version_tag(): | ||
tags = ( | ||
subprocess.check_output(["git", "tag", "--sort=-creatordate"], text=True) | ||
.strip() | ||
.split("\n") | ||
) | ||
version_tags = [tag for tag in tags if re.match(r"^v\d+\.\d+\.\d+$", tag)] | ||
if version_tags: | ||
return version_tags[0] | ||
return None | ||
|
||
|
||
def get_version(): | ||
version_file = "endf_parserpy/__init__.py" | ||
if not os.path.exists(version_file): | ||
raise RuntimeError(f"Could not find {version_file}.") | ||
with open(version_file, "r") as file: | ||
for line in file: | ||
if line.strip().startswith("__version"): | ||
version = line.split("=")[1].strip().strip('"') | ||
return version | ||
raise RuntimeError("Could not find version string.") | ||
|
||
|
||
def main(): | ||
tag = get_latest_version_tag() | ||
if not tag: | ||
print("No version tag found. Skipping version check.") | ||
sys.exit(0) | ||
|
||
version = get_version_from_init() | ||
tag_version = tag[1:] | ||
if version != tag_version: | ||
print(f"Tag '{tag}' does not match version '{version}' in __init__.py") | ||
sys.exit(1) | ||
|
||
print(f"Tag '{tag}' matches version '{version}' in __init__.py") | ||
sys.exit(0) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |