python-quantumflow 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ """
2
+ Validation utilities for QuantumFlow.
3
+ """
4
+
5
+ import ast
6
+ import importlib
7
+ import inspect
8
+ import os
9
+ import sys
10
+ from typing import Any, Dict, List, Optional, Set, Tuple
11
+
12
+ def validate_flows():
13
+ """Validate all flow definitions in the current project."""
14
+ # Find all Python files
15
+ python_files = []
16
+ for root, _, files in os.walk("."):
17
+ for file in files:
18
+ if file.endswith(".py"):
19
+ python_files.append(os.path.join(root, file))
20
+
21
+ # Check each file for flow definitions
22
+ valid_flows = 0
23
+ invalid_flows = 0
24
+
25
+ for file_path in python_files:
26
+ try:
27
+ # Parse the file
28
+ with open(file_path, "r") as f:
29
+ content = f.read()
30
+
31
+ tree = ast.parse(content)
32
+
33
+ # Find all functions with @qflow decorator
34
+ for node in ast.walk(tree):
35
+ if isinstance(node, ast.FunctionDef):
36
+ has_qflow = False
37
+
38
+ # Check for @qflow decorator
39
+ for decorator in node.decorator_list:
40
+ if isinstance(decorator, ast.Name) and decorator.id == "qflow":
41
+ has_qflow = True
42
+ elif isinstance(decorator, ast.Call) and isinstance(decorator.func, ast.Name) and decorator.func.id == "qflow":
43
+ has_qflow = True
44
+
45
+ if has_qflow:
46
+ # Validate the flow
47
+ if validate_flow_definition(node):
48
+ valid_flows += 1
49
+ else:
50
+ invalid_flows += 1
51
+ print(f"Invalid flow definition in {file_path}: {node.name}")
52
+
53
+ except Exception as e:
54
+ print(f"Error processing file {file_path}: {e}")
55
+
56
+ print(f"Validation complete: {valid_flows} valid flows, {invalid_flows} invalid flows")
57
+
58
+ return invalid_flows == 0
59
+
60
+ def validate_flow_definition(node: ast.FunctionDef) -> bool:
61
+ """Validate a flow definition."""
62
+ # Check for type annotations
63
+ has_annotations = all(arg.annotation is not None for arg in node.args.args)
64
+
65
+ # Check for docstring
66
+ has_docstring = (len(node.body) > 0 and
67
+ isinstance(node.body[0], ast.Expr) and
68
+ isinstance(node.body[0].value, ast.Str))
69
+
70
+ # Check for return statement
71
+ has_return = any(isinstance(stmt, ast.Return) for stmt in ast.walk(node))
72
+
73
+ # Check for return type annotation
74
+ has_return_annotation = node.returns is not None
75
+
76
+ # All checks must pass
77
+ return has_annotations and has_docstring and has_return and has_return_annotation