ref: Auto-fix ruff rules in tests (#4154)

This commit is contained in:
Christophe Bornet 2024-10-16 17:42:36 +02:00 committed by GitHub
commit 45c8f98692
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
80 changed files with 359 additions and 456 deletions

View file

@ -1,5 +1,5 @@
import sys
import re
import sys
from pathlib import Path
import packaging.version
@ -10,40 +10,39 @@ BASE_DIR = Path(__file__).parent.parent.parent
def update_pyproject_version(pyproject_path: str, new_version: str) -> None:
"""Update the version in pyproject.toml."""
filepath = BASE_DIR / pyproject_path
content = filepath.read_text()
content = filepath.read_text(encoding="utf-8")
# Regex to match the version line under [tool.poetry]
pattern = re.compile(r'(?<=^version = ")[^"]+(?=")', re.MULTILINE)
if not pattern.search(content):
raise Exception(f'Project version not found in "{filepath}"')
msg = f'Project version not found in "{filepath}"'
raise Exception(msg)
content = pattern.sub(new_version, content)
filepath.write_text(content)
filepath.write_text(content, encoding="utf-8")
def verify_pep440(version):
"""
Verify if version is PEP440 compliant.
"""Verify if version is PEP440 compliant.
https://github.com/pypa/packaging/blob/16.7/packaging/version.py#L191
"""
try:
return packaging.version.Version(version)
except packaging.version.InvalidVersion as e:
raise e
except packaging.version.InvalidVersion:
raise
def main() -> None:
if len(sys.argv) != 3:
raise Exception("New version not specified")
msg = "New version not specified"
raise Exception(msg)
new_version = sys.argv[1]
# Strip "v" prefix from version if present
if new_version.startswith("v"):
new_version = new_version[1:]
new_version = new_version.removeprefix("v")
build_type = sys.argv[2]
@ -54,7 +53,8 @@ def main() -> None:
elif build_type == "main":
update_pyproject_version("pyproject.toml", new_version)
else:
raise ValueError(f"Invalid build type: {build_type}")
msg = f"Invalid build type: {build_type}"
raise ValueError(msg)
if __name__ == "__main__":