ref: Auto-fix ruff rules in tests (#4154)
This commit is contained in:
parent
51b3909d60
commit
45c8f98692
80 changed files with 359 additions and 456 deletions
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
Idea from https://github.com/streamlit/streamlit/blob/4841cf91f1c820a392441092390c4c04907f9944/scripts/pypi_nightly_create_tag.py
|
||||
"""
|
||||
"""Idea from https://github.com/streamlit/streamlit/blob/4841cf91f1c820a392441092390c4c04907f9944/scripts/pypi_nightly_create_tag.py."""
|
||||
|
||||
import sys
|
||||
|
||||
|
|
@ -24,13 +22,15 @@ def get_latest_published_version(build_type: str, is_nightly: bool) -> Version:
|
|||
elif build_type == "main":
|
||||
url = PYPI_LANGFLOW_NIGHTLY_URL if is_nightly else PYPI_LANGFLOW_URL
|
||||
else:
|
||||
raise ValueError(f"Invalid build type: {build_type}")
|
||||
msg = f"Invalid build type: {build_type}"
|
||||
raise ValueError(msg)
|
||||
|
||||
res = requests.get(url)
|
||||
try:
|
||||
version_str = res.json()["info"]["version"]
|
||||
except Exception as e:
|
||||
raise RuntimeError("Got unexpected response from PyPI", e)
|
||||
msg = "Got unexpected response from PyPI"
|
||||
raise RuntimeError(msg, e)
|
||||
return Version(version_str)
|
||||
|
||||
|
||||
|
|
@ -75,7 +75,8 @@ def create_tag(build_type: str):
|
|||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
raise Exception("Specify base or main")
|
||||
msg = "Specify base or main"
|
||||
raise Exception(msg)
|
||||
|
||||
build_type = sys.argv[1]
|
||||
tag = create_tag(build_type)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import sys
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import packaging.version
|
||||
|
|
@ -10,39 +10,38 @@ BASE_DIR = Path(__file__).parent.parent.parent
|
|||
def update_base_dep(pyproject_path: str, new_version: 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")
|
||||
|
||||
replacement = f'langflow-base-nightly = "{new_version}"'
|
||||
|
||||
# Updates the pattern for poetry
|
||||
pattern = re.compile(r'langflow-base = \{ path = "\./src/backend/base", develop = true \}')
|
||||
if not pattern.search(content):
|
||||
raise Exception(f'langflow-base poetry dependency not found in "{filepath}"')
|
||||
msg = f'langflow-base poetry 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 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) != 2:
|
||||
raise Exception("New version not specified")
|
||||
msg = "New version not specified"
|
||||
raise Exception(msg)
|
||||
base_version = sys.argv[1]
|
||||
|
||||
# Strip "v" prefix from version if present
|
||||
if base_version.startswith("v"):
|
||||
base_version = base_version[1:]
|
||||
base_version = base_version.removeprefix("v")
|
||||
|
||||
verify_pep440(base_version)
|
||||
update_base_dep("pyproject.toml", base_version)
|
||||
|
|
|
|||
|
|
@ -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__":
|
||||
|
|
|
|||
|
|
@ -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__":
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import sys
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent.parent
|
||||
|
|
@ -7,30 +7,31 @@ BASE_DIR = Path(__file__).parent.parent.parent
|
|||
|
||||
def update_uv_dep(base_version: str) -> None:
|
||||
"""Update the langflow-base dependency in pyproject.toml."""
|
||||
|
||||
pyproject_path = BASE_DIR / "pyproject.toml"
|
||||
|
||||
# Read the pyproject.toml file content
|
||||
content = pyproject_path.read_text()
|
||||
content = pyproject_path.read_text(encoding="utf-8")
|
||||
|
||||
# For the main project, update the langflow-base dependency in the UV section
|
||||
pattern = re.compile(r'(dependencies\s*=\s*\[\s*\n\s*)("langflow-base==[\d.]+")')
|
||||
replacement = r'\1"langflow-base-nightly=={}"'.format(base_version)
|
||||
replacement = rf'\1"langflow-base-nightly=={base_version}"'
|
||||
|
||||
# Check if the pattern is found
|
||||
if not pattern.search(content):
|
||||
raise Exception(f"{pattern} UV dependency not found in {pyproject_path}")
|
||||
msg = f"{pattern} UV dependency not found in {pyproject_path}"
|
||||
raise Exception(msg)
|
||||
|
||||
# Replace the matched pattern with the new one
|
||||
content = pattern.sub(replacement, content)
|
||||
|
||||
# Write the updated content back to the file
|
||||
pyproject_path.write_text(content)
|
||||
pyproject_path.write_text(content, encoding="utf-8")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if len(sys.argv) != 2:
|
||||
raise Exception("specify base version")
|
||||
msg = "specify base version"
|
||||
raise Exception(msg)
|
||||
base_version = sys.argv[1]
|
||||
base_version = base_version.lstrip("v")
|
||||
update_uv_dep(base_version)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
# ]
|
||||
# ///
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from huggingface_hub import HfApi, list_models
|
||||
from rich import print
|
||||
|
|
@ -23,11 +24,11 @@ space = parsed_args.space
|
|||
|
||||
if not space:
|
||||
print("Please provide a space to restart.")
|
||||
exit()
|
||||
sys.exit()
|
||||
|
||||
if not parsed_args.token:
|
||||
print("Please provide an API token.")
|
||||
exit()
|
||||
sys.exit()
|
||||
|
||||
# Or configure a HfApi client
|
||||
hf_api = HfApi(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue