From 8f15225b82299af593a94e44b601cb9e6df12fe7 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Sat, 26 Jul 2025 09:41:58 -0300 Subject: [PATCH] Adjusted project information - Added mypy as dev dependency - Ignored some local files - Added script to check version consistency --- .gitignore | 3 ++ .pre-commit-config.yaml | 15 ++++++++ pyproject.toml | 5 ++- src/requirements-dev.txt | 2 +- tools/check_versions.py | 80 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 2 deletions(-) create mode 100755 tools/check_versions.py diff --git a/.gitignore b/.gitignore index d95843e..02dc25d 100644 --- a/.gitignore +++ b/.gitignore @@ -196,3 +196,6 @@ cython_debug/ *.dst *.epr .*~ +tags +sync.sh +0LEEME diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c8aa035..bc412c0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -64,3 +64,18 @@ repos: # whole project as configured in mypy.ini, rather than just the changed files. # Try without it first. # pass_filenames: false + +# --- Version checking --- +- repo: local + hooks: + - id: version-check + name: check for version consistency + # The command to execute. It's a Python script. + entry: python tools/check_versions.py + # Use 'system' to run it with the current environment's Python + language: system + # This hook doesn't need to run on every file. + # It should run if either of the version files change. + # This makes it very fast. + files: ^(pyproject\.toml|src/nodes/__init__\.py)$ + # The regex `^...$` ensures it matches the full path from the repo root. diff --git a/pyproject.toml b/pyproject.toml index 608d586..fa75fd3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,9 +7,12 @@ Signal generator (`sine`, `square`, `sawtooth`, `triangle`, `sweep`, `noise`). Musical note to frequency. Audio downloader for quick workflows which downloads its example data. """ +# Inconsistent mechanism needed by comfy-cli, no dynamic variables version = "1.3.0" +# Deprecated mechanism, comfy-cli doesn't support SPDX license = { file = "LICENSE" } -dependencies = [] +# Not really used, ComfyUI-Manager doesn't use it +dependencies = ["seconohe"] [project.urls] Repository = "https://github.com/set-soft/ComfyUI-AudioBatch" diff --git a/src/requirements-dev.txt b/src/requirements-dev.txt index b0ccefc..0984b70 100644 --- a/src/requirements-dev.txt +++ b/src/requirements-dev.txt @@ -1,6 +1,6 @@ +mypy pytest tqdm seconohe -# mypy # flake8 # Note: torch and torchaudio are handled separately in the workflow for CPU installation. diff --git a/tools/check_versions.py b/tools/check_versions.py new file mode 100755 index 0000000..f10166c --- /dev/null +++ b/tools/check_versions.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +import re +import sys +from pathlib import Path + +# --- Configuration --- +# The path to your pyproject.toml file, relative to the project root +PYPROJECT_PATH = Path("pyproject.toml") +# The path to the Python file containing the __version__ string +SOURCE_VERSION_PATH = Path("src/nodes/__init__.py") +# --- End Configuration --- + + +def get_version_from_pyproject(file_path: Path) -> str | None: + """Extracts the version string from a pyproject.toml file.""" + try: + content = file_path.read_text() + # A simple regex to find `version = "..."` under the `[project]` table + match = re.search(r'^version\s*=\s*"(.*?)"', content, re.MULTILINE) + if match: + return match.group(1) + except FileNotFoundError: + print(f"Error: {file_path} not found.", file=sys.stderr) + except Exception as e: + print(f"Error reading or parsing {file_path}: {e}", file=sys.stderr) + return None + + +def get_version_from_source(file_path: Path) -> str | None: + """Extracts the __version__ string from a Python source file.""" + try: + content = file_path.read_text() + # A simple regex to find `__version__ = "..."` + match = re.search(r'^__version__\s*=\s*"(.*?)"', content, re.MULTILINE) + if match: + return match.group(1) + except FileNotFoundError: + print(f"Error: {file_path} not found.", file=sys.stderr) + except Exception as e: + print(f"Error reading or parsing {file_path}: {e}", file=sys.stderr) + return None + + +def main() -> int: + """ + Compares version strings from pyproject.toml and the source code. + Exits with a non-zero status code if they do not match. + """ + print("--- Checking version consistency ---") + + # Get versions + pyproject_version = get_version_from_pyproject(PYPROJECT_PATH) + source_version = get_version_from_source(SOURCE_VERSION_PATH) + + # Validate that we found both + if not pyproject_version: + print(f"Error: Could not find version in {PYPROJECT_PATH}", file=sys.stderr) + return 1 + + if not source_version: + print(f"Error: Could not find `__version__` in {SOURCE_VERSION_PATH}", file=sys.stderr) + return 1 + + print(f"Version in {PYPROJECT_PATH}: {pyproject_version}") + print(f"Version in {SOURCE_VERSION_PATH}: {source_version}") + + # Compare and exit + if pyproject_version == source_version: + print("āœ… Versions are consistent.") + return 0 + else: + print("\nāŒ Error: Version mismatch!", file=sys.stderr) + print(f" pyproject.toml has version '{pyproject_version}'", file=sys.stderr) + print(f" {SOURCE_VERSION_PATH} has version '{source_version}'", file=sys.stderr) + print(" Please ensure both versions are identical.", file=sys.stderr) + return 1 + + +if __name__ == "__main__": + sys.exit(main())