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
BASE_DIR = Path(__file__).parent.parent.parent
@ -8,22 +8,23 @@ BASE_DIR = Path(__file__).parent.parent.parent
def update_pyproject_name(pyproject_path: str, new_project_name: str) -> None:
"""Update the project name 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'(?<=^name = ")[^"]+(?=")', re.MULTILINE)
if not pattern.search(content):
raise Exception(f'Project name not found in "{filepath}"')
msg = f'Project name not found in "{filepath}"'
raise Exception(msg)
content = pattern.sub(new_project_name, content)
filepath.write_text(content)
filepath.write_text(content, encoding="utf-8")
def update_uv_dep(pyproject_path: str, new_project_name: str) -> None:
"""Update the langflow-base dependency in pyproject.toml."""
filepath = BASE_DIR / pyproject_path
content = filepath.read_text()
content = filepath.read_text(encoding="utf-8")
if new_project_name == "langflow-nightly":
pattern = re.compile(r"langflow = \{ workspace = true \}")
@ -32,18 +33,21 @@ def update_uv_dep(pyproject_path: str, new_project_name: str) -> None:
pattern = re.compile(r"langflow-base = \{ workspace = true \}")
replacement = "langflow-base-nightly = { workspace = true }"
else:
raise ValueError(f"Invalid project name: {new_project_name}")
msg = f"Invalid project name: {new_project_name}"
raise ValueError(msg)
# Updates the dependency name for uv
if not pattern.search(content):
raise Exception(f"{replacement} uv dependency not found in {filepath}")
msg = f"{replacement} uv dependency not found in {filepath}"
raise Exception(msg)
content = pattern.sub(replacement, content)
filepath.write_text(content)
filepath.write_text(content, encoding="utf-8")
def main() -> None:
if len(sys.argv) != 3:
raise Exception("Must specify project name and build type, e.g. langflow-nightly base")
msg = "Must specify project name and build type, e.g. langflow-nightly base"
raise Exception(msg)
new_project_name = sys.argv[1]
build_type = sys.argv[2]
@ -54,7 +58,8 @@ def main() -> None:
update_pyproject_name("pyproject.toml", new_project_name)
update_uv_dep("pyproject.toml", new_project_name)
else:
raise ValueError(f"Invalid build type: {build_type}")
msg = f"Invalid build type: {build_type}"
raise ValueError(msg)
if __name__ == "__main__":