c56bef871b
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import ast
|
|
import hashlib
|
|
from collections.abc import Iterator
|
|
from pathlib import Path
|
|
|
|
|
|
def docstrings_checksum(python_files: Iterator[Path]) -> str:
|
|
"""
|
|
Calculate the checksum of the docstrings in the given Python files.
|
|
"""
|
|
files_content = (f.read_text() for f in python_files)
|
|
trees = (ast.parse(c) for c in files_content)
|
|
|
|
# Get all docstrings from async functions, functions,
|
|
# classes and modules definitions
|
|
docstrings = []
|
|
for tree in trees:
|
|
for node in ast.walk(tree):
|
|
if not isinstance(node, (ast.AsyncFunctionDef, ast.FunctionDef, ast.ClassDef, ast.Module)):
|
|
# Skip all node types that can't have docstrings to prevent failures
|
|
continue
|
|
docstring = ast.get_docstring(node)
|
|
if docstring:
|
|
docstrings.append(docstring)
|
|
|
|
# Sort them to be safe, since ast.walk() returns
|
|
# nodes in no specified order.
|
|
# See https://docs.python.org/3/library/ast.html#ast.walk
|
|
docstrings.sort()
|
|
|
|
return hashlib.md5(str(docstrings).encode("utf-8")).hexdigest()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--root", help="Haystack root folder", required=True, type=Path)
|
|
args = parser.parse_args()
|
|
|
|
# Get all Haystack and rest_api python files
|
|
root: Path = args.root.absolute()
|
|
haystack_files = root.glob("haystack/**/*.py")
|
|
|
|
md5 = docstrings_checksum(haystack_files)
|
|
print(md5)
|