style: Improve code formatting and readability in update_version.py
This commit is contained in:
parent
5dfb96874e
commit
c9353cf8ea
1 changed files with 6 additions and 11 deletions
|
|
@ -27,11 +27,13 @@ def validate_version(version: str) -> bool:
|
||||||
Returns:
|
Returns:
|
||||||
True if valid, False otherwise
|
True if valid, False otherwise
|
||||||
"""
|
"""
|
||||||
pattern = r'^\d+\.\d+\.\d+(?:-[a-zA-Z0-9]+)?$'
|
pattern = r"^\d+\.\d+\.\d+(?:-[a-zA-Z0-9]+)?$"
|
||||||
return bool(re.match(pattern, version))
|
return bool(re.match(pattern, version))
|
||||||
|
|
||||||
|
|
||||||
def update_file(file_path: Path, old_pattern: str, new_version: str, multiline: bool = False) -> bool:
|
def update_file(
|
||||||
|
file_path: Path, old_pattern: str, new_version: str, multiline: bool = False
|
||||||
|
) -> bool:
|
||||||
"""Update version in a file.
|
"""Update version in a file.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
@ -94,10 +96,7 @@ def main() -> int:
|
||||||
# Use word boundary to match 'version' but not 'python_version'
|
# Use word boundary to match 'version' but not 'python_version'
|
||||||
pattern = r'^version = "[^"]+"'
|
pattern = r'^version = "[^"]+"'
|
||||||
success &= update_file(
|
success &= update_file(
|
||||||
pyproject_path,
|
pyproject_path, pattern, f'version = "{new_version}"', multiline=True
|
||||||
pattern,
|
|
||||||
f'version = "{new_version}"',
|
|
||||||
multiline=True
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print(f"✗ {pyproject_path} not found")
|
print(f"✗ {pyproject_path} not found")
|
||||||
|
|
@ -106,11 +105,7 @@ def main() -> int:
|
||||||
# Update __init__.py
|
# Update __init__.py
|
||||||
if init_path.exists():
|
if init_path.exists():
|
||||||
pattern = r'__version__ = "[^"]+"'
|
pattern = r'__version__ = "[^"]+"'
|
||||||
success &= update_file(
|
success &= update_file(init_path, pattern, f'__version__ = "{new_version}"')
|
||||||
init_path,
|
|
||||||
pattern,
|
|
||||||
f'__version__ = "{new_version}"'
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
print(f"✗ {init_path} not found")
|
print(f"✗ {init_path} not found")
|
||||||
success = False
|
success = False
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue