MCPcopy Create free account
hub / github.com/FastLED/FastLED / demo_basic_usage

Function demo_basic_usage

ci/examples/fingerprint_cache_demo.py:23–71  ·  view source on GitHub ↗

Demonstrate basic fingerprint cache usage.

()

Source from the content-addressed store, hash-verified

21
22
23def demo_basic_usage() -> None:
24 """Demonstrate basic fingerprint cache usage."""
25 print("=== Basic Fingerprint Cache Demo ===")
26
27 with tempfile.TemporaryDirectory() as temp_dir:
28 temp_path = Path(temp_dir)
29 cache_file = temp_path / "demo_cache.json"
30 cache = FingerprintCache(cache_file)
31
32 # Create a source file
33 source_file = temp_path / "example.cpp"
34 with open(source_file, "w") as f:
35 f.write("#include <iostream>\nint main() { return 0; }")
36
37 baseline_time = time.time() - 3600 # 1 hour ago
38 current_modtime = os.path.getmtime(source_file)
39
40 print(f"Source file: {source_file}")
41 print(f"Baseline time: {baseline_time}")
42 print(f"Current modtime: {current_modtime}")
43
44 # First check - file is newer than baseline
45 changed = cache.has_changed(source_file, baseline_time)
46 print(f"First check (vs baseline): {changed} (expected: True)")
47
48 # Second check - same modtime
49 changed = cache.has_changed(source_file, current_modtime)
50 print(f"Second check (same modtime): {changed} (expected: False)")
51
52 # Touch file (change modtime but not content)
53 time.sleep(0.01)
54 source_file.touch()
55
56 # Third check - modtime changed but content same
57 changed = cache.has_changed(source_file, current_modtime)
58 print(
59 f"Third check (touched file): {changed} (expected: False - content unchanged)"
60 )
61
62 # Actually modify content
63 time.sleep(0.01)
64 with open(source_file, "w") as f:
65 f.write(
66 '#include <iostream>\nint main() { std::cout << "Hello"; return 0; }'
67 )
68
69 # Fourth check - content actually changed
70 changed = cache.has_changed(source_file, current_modtime)
71 print(f"Fourth check (content changed): {changed} (expected: True)")
72
73
74def demo_build_system_workflow() -> None:

Callers 1

Calls 5

has_changedMethod · 0.95
FingerprintCacheClass · 0.90
timeMethod · 0.80
printFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected