refactor: Enhance Unicode handling in build scripts and rename sync_version function

This commit is contained in:
claudi 2026-02-18 13:54:17 +01:00
parent ff804790e6
commit aad2e59c1c
2 changed files with 43 additions and 23 deletions

View file

@ -130,34 +130,26 @@ def update_changelog(version: str) -> None:
print(f"✓ Added version header to CHANGELOG.md for {version}")
def sync_version() -> int:
def do_sync_version(version: str | None = None) -> int:
"""Sync version across project.
Updates __init__.py (source of truth) and changelog.
Config and pyproject.toml automatically read from __init__.py.
Args:
version: Version to set (if None, reads from __init__.py)
Returns:
0 on success, 1 on error
"""
parser = argparse.ArgumentParser(
description="Sync version from __init__.py to dependent files"
)
parser.add_argument(
"--version",
type=str,
help="Version to set (if not provided, reads from __init__.py)",
)
args = parser.parse_args()
try:
if args.version:
if not re.match(r"^\d+\.\d+\.\d+", args.version):
if version:
if not re.match(r"^\d+\.\d+\.\d+", version):
print(
"❌ Invalid version format. Use semantic versioning"
" (e.g., 1.2.3)"
)
return 1
version = args.version
update_init_version(version)
else:
version = get_current_version_from_init()
@ -174,5 +166,26 @@ def sync_version() -> int:
return 1
def sync_version() -> int:
"""Sync version across project (command-line interface).
Parses command-line arguments and calls do_sync_version().
This function is only called when the script is run directly.
Returns:
0 on success, 1 on error
"""
parser = argparse.ArgumentParser(
description="Sync version from __init__.py to dependent files"
)
parser.add_argument(
"--version",
type=str,
help="Version to set (if not provided, reads from __init__.py)",
)
args = parser.parse_args()
return do_sync_version(args.version)
if __name__ == "__main__":
sys.exit(sync_version())