face-claim-audit 0.1.0__tar.gz

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.
Files changed (27) hide show
  1. face_claim_audit-0.1.0/LICENSE +21 -0
  2. face_claim_audit-0.1.0/MANIFEST.in +2 -0
  3. face_claim_audit-0.1.0/PKG-INFO +137 -0
  4. face_claim_audit-0.1.0/README.md +127 -0
  5. face_claim_audit-0.1.0/face_claim_audit/__init__.py +1 -0
  6. face_claim_audit-0.1.0/face_claim_audit/__main__.py +3 -0
  7. face_claim_audit-0.1.0/face_claim_audit/audit.py +177 -0
  8. face_claim_audit-0.1.0/face_claim_audit/phrases.py +3 -0
  9. face_claim_audit-0.1.0/face_claim_audit.egg-info/PKG-INFO +137 -0
  10. face_claim_audit-0.1.0/face_claim_audit.egg-info/SOURCES.txt +25 -0
  11. face_claim_audit-0.1.0/face_claim_audit.egg-info/dependency_links.txt +1 -0
  12. face_claim_audit-0.1.0/face_claim_audit.egg-info/entry_points.txt +2 -0
  13. face_claim_audit-0.1.0/face_claim_audit.egg-info/top_level.txt +1 -0
  14. face_claim_audit-0.1.0/pyproject.toml +17 -0
  15. face_claim_audit-0.1.0/setup.cfg +4 -0
  16. face_claim_audit-0.1.0/tests/__init__.py +0 -0
  17. face_claim_audit-0.1.0/tests/cases.py +35 -0
  18. face_claim_audit-0.1.0/tests/fixtures/.env +1 -0
  19. face_claim_audit-0.1.0/tests/fixtures/bad/README.md +1 -0
  20. face_claim_audit-0.1.0/tests/fixtures/bad/app.py +1 -0
  21. face_claim_audit-0.1.0/tests/fixtures/good/README.md +1 -0
  22. face_claim_audit-0.1.0/tests/fixtures/good/app.py +2 -0
  23. face_claim_audit-0.1.0/tests/fixtures/no-face/README.md +1 -0
  24. face_claim_audit-0.1.0/tests/fixtures/no-face/app.py +2 -0
  25. face_claim_audit-0.1.0/tests/fixtures/testonly/README.md +1 -0
  26. face_claim_audit-0.1.0/tests/fixtures/testonly/tests/test_impl.py +2 -0
  27. face_claim_audit-0.1.0/tests/test_audit.py +155 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 face-claim-audit contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include README.md LICENSE
2
+ recursive-include tests *.py *.md .env
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.4
2
+ Name: face-claim-audit
3
+ Version: 0.1.0
4
+ Summary: Offline audit of documented picture-face claims against Python source
5
+ License: MIT
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # face-claim-audit 0.1.0
12
+
13
+ Offline static audit of documented picture-face claims against Python source.
14
+ Audited code is parsed with AST and never executed. Runtime dependencies: none.
15
+ Requires Python >=3.9.
16
+
17
+ ## Usage
18
+
19
+ ```sh
20
+ python3 -m pip install .
21
+ face-claim-audit /path/to/project
22
+ python3 -m face_claim_audit /path/to/project --json --verbose
23
+ python3 -m face_claim_audit /path/to/project --ignore 'docs/old/*' --fail-on MEDIUM
24
+ python3 -m unittest discover
25
+ python3 -m build
26
+ ```
27
+
28
+ The root README.md and Markdown files with a docs path component supply claims.
29
+ Fenced blocks are excluded; inline code counts. Paragraph lines are joined,
30
+ case is folded, contractions expanded, hyphens replaced with spaces, and
31
+ whitespace collapsed. Exact templates use word boundaries, longest first;
32
+ negative spans are removed before positive matching.
33
+
34
+ Production evidence comes from imported, alias-resolved calls in Python files.
35
+ The supported providers are face_recognition, dlib, cv2, and mediapipe.
36
+ The first provider supports four operations, dlib its frontal detector factory,
37
+ cv2 a literal face-cascade construction paired with a bound scan method,
38
+ and mediapipe its specified detector construction or bound process method.
39
+ Assignments, self attributes, context targets, and chained calls are supported.
40
+ Local definitions shadow imports. Bare imports and strings are insufficient.
41
+ Tests, fixtures, docs, examples, and symlinked files are excluded from production.
42
+ Test evidence produces a MEDIUM finding; absence of production evidence produces
43
+ HIGH. Conflicting negative prose produces HIGH. Each family yields at most one
44
+ finding. With no claims, the result is PASS regardless of source.
45
+
46
+ Rules: `documented-face-claim-false`, `documented-no-face-claim-false`.
47
+ Default threshold HIGH reports MEDIUM without failing; --fail-on MEDIUM fails
48
+ on either severity. Exits: 0 PASS, 2 FAIL, 1 invalid or unreadable root.
49
+ JSON includes verdict, findings (rule, severity, message), and files_scanned.
50
+
51
+ ## Limitations
52
+
53
+ Only the exact templates below count. A bare face or faces, eyes alone,
54
+ age or gender estimation, person or body detection, privacy blurring,
55
+ camera capture, and image opening are outside claim scope.
56
+ A shell call to a system face finder is not counted: a command name in a
57
+ string literal is never evidence. Other face stacks, including phone-camera
58
+ SDKs, cloud picture-face APIs, and handwriting-specific engines, are out of
59
+ scope; only the Python routes described above are counted. Non-literal cascade
60
+ paths (variables, joins, or computed expressions) are not counted.
61
+ This is module-local static analysis, not runtime or cross-module proof;
62
+ syntax-invalid files provide no evidence. No optional provider is imported.
63
+ The scanner never opens .env files.
64
+
65
+ ## Exact templates
66
+
67
+ ```text
68
+ recognizes faces in photos
69
+ recognize faces in photos
70
+ recognises faces in photos
71
+ recognise faces in photos
72
+ recognizes faces in images
73
+ recognize faces in images
74
+ recognises faces in images
75
+ recognise faces in images
76
+ detects faces in photos
77
+ detect faces in photos
78
+ detects faces in images
79
+ detect faces in images
80
+ identifies faces in photos
81
+ identify faces in photos
82
+ identifies faces in images
83
+ identify faces in images
84
+ detects faces in video
85
+ detect faces in video
86
+ supports facial recognition
87
+ support facial recognition
88
+ supports face recognition
89
+ support face recognition
90
+ facial recognition support
91
+ face recognition support
92
+ recognizes faces
93
+ recognize faces
94
+ recognises faces
95
+ recognise faces
96
+ detects faces
97
+ detect faces
98
+ identifies faces
99
+ identify faces
100
+ recognizes a face
101
+ recognize a face
102
+ recognises a face
103
+ recognise a face
104
+ detects a face
105
+ detect a face
106
+ identifies a face
107
+ identify a face
108
+ face recognition
109
+ facial recognition
110
+ face detection
111
+ face identification
112
+ does not support facial recognition
113
+ does not support face recognition
114
+ does not recognize faces in photos
115
+ does not recognise faces in photos
116
+ does not recognize faces in images
117
+ does not recognise faces in images
118
+ does not detect faces in photos
119
+ does not detect faces in images
120
+ does not identify faces in photos
121
+ does not identify faces in images
122
+ does not recognize faces
123
+ does not recognise faces
124
+ does not detect faces
125
+ does not identify faces
126
+ facial recognition not supported
127
+ face recognition not supported
128
+ face detection not supported
129
+ no facial recognition
130
+ without facial recognition
131
+ no face recognition
132
+ without face recognition
133
+ no face detection
134
+ without face detection
135
+ no face identification
136
+ without face identification
137
+ ```
@@ -0,0 +1,127 @@
1
+ # face-claim-audit 0.1.0
2
+
3
+ Offline static audit of documented picture-face claims against Python source.
4
+ Audited code is parsed with AST and never executed. Runtime dependencies: none.
5
+ Requires Python >=3.9.
6
+
7
+ ## Usage
8
+
9
+ ```sh
10
+ python3 -m pip install .
11
+ face-claim-audit /path/to/project
12
+ python3 -m face_claim_audit /path/to/project --json --verbose
13
+ python3 -m face_claim_audit /path/to/project --ignore 'docs/old/*' --fail-on MEDIUM
14
+ python3 -m unittest discover
15
+ python3 -m build
16
+ ```
17
+
18
+ The root README.md and Markdown files with a docs path component supply claims.
19
+ Fenced blocks are excluded; inline code counts. Paragraph lines are joined,
20
+ case is folded, contractions expanded, hyphens replaced with spaces, and
21
+ whitespace collapsed. Exact templates use word boundaries, longest first;
22
+ negative spans are removed before positive matching.
23
+
24
+ Production evidence comes from imported, alias-resolved calls in Python files.
25
+ The supported providers are face_recognition, dlib, cv2, and mediapipe.
26
+ The first provider supports four operations, dlib its frontal detector factory,
27
+ cv2 a literal face-cascade construction paired with a bound scan method,
28
+ and mediapipe its specified detector construction or bound process method.
29
+ Assignments, self attributes, context targets, and chained calls are supported.
30
+ Local definitions shadow imports. Bare imports and strings are insufficient.
31
+ Tests, fixtures, docs, examples, and symlinked files are excluded from production.
32
+ Test evidence produces a MEDIUM finding; absence of production evidence produces
33
+ HIGH. Conflicting negative prose produces HIGH. Each family yields at most one
34
+ finding. With no claims, the result is PASS regardless of source.
35
+
36
+ Rules: `documented-face-claim-false`, `documented-no-face-claim-false`.
37
+ Default threshold HIGH reports MEDIUM without failing; --fail-on MEDIUM fails
38
+ on either severity. Exits: 0 PASS, 2 FAIL, 1 invalid or unreadable root.
39
+ JSON includes verdict, findings (rule, severity, message), and files_scanned.
40
+
41
+ ## Limitations
42
+
43
+ Only the exact templates below count. A bare face or faces, eyes alone,
44
+ age or gender estimation, person or body detection, privacy blurring,
45
+ camera capture, and image opening are outside claim scope.
46
+ A shell call to a system face finder is not counted: a command name in a
47
+ string literal is never evidence. Other face stacks, including phone-camera
48
+ SDKs, cloud picture-face APIs, and handwriting-specific engines, are out of
49
+ scope; only the Python routes described above are counted. Non-literal cascade
50
+ paths (variables, joins, or computed expressions) are not counted.
51
+ This is module-local static analysis, not runtime or cross-module proof;
52
+ syntax-invalid files provide no evidence. No optional provider is imported.
53
+ The scanner never opens .env files.
54
+
55
+ ## Exact templates
56
+
57
+ ```text
58
+ recognizes faces in photos
59
+ recognize faces in photos
60
+ recognises faces in photos
61
+ recognise faces in photos
62
+ recognizes faces in images
63
+ recognize faces in images
64
+ recognises faces in images
65
+ recognise faces in images
66
+ detects faces in photos
67
+ detect faces in photos
68
+ detects faces in images
69
+ detect faces in images
70
+ identifies faces in photos
71
+ identify faces in photos
72
+ identifies faces in images
73
+ identify faces in images
74
+ detects faces in video
75
+ detect faces in video
76
+ supports facial recognition
77
+ support facial recognition
78
+ supports face recognition
79
+ support face recognition
80
+ facial recognition support
81
+ face recognition support
82
+ recognizes faces
83
+ recognize faces
84
+ recognises faces
85
+ recognise faces
86
+ detects faces
87
+ detect faces
88
+ identifies faces
89
+ identify faces
90
+ recognizes a face
91
+ recognize a face
92
+ recognises a face
93
+ recognise a face
94
+ detects a face
95
+ detect a face
96
+ identifies a face
97
+ identify a face
98
+ face recognition
99
+ facial recognition
100
+ face detection
101
+ face identification
102
+ does not support facial recognition
103
+ does not support face recognition
104
+ does not recognize faces in photos
105
+ does not recognise faces in photos
106
+ does not recognize faces in images
107
+ does not recognise faces in images
108
+ does not detect faces in photos
109
+ does not detect faces in images
110
+ does not identify faces in photos
111
+ does not identify faces in images
112
+ does not recognize faces
113
+ does not recognise faces
114
+ does not detect faces
115
+ does not identify faces
116
+ facial recognition not supported
117
+ face recognition not supported
118
+ face detection not supported
119
+ no facial recognition
120
+ without facial recognition
121
+ no face recognition
122
+ without face recognition
123
+ no face detection
124
+ without face detection
125
+ no face identification
126
+ without face identification
127
+ ```
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ from .audit import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,177 @@
1
+ """Offline documentation and AST checks; audited code is never executed."""
2
+ import argparse
3
+ import ast
4
+ import fnmatch
5
+ import json
6
+ import os
7
+ import re
8
+ from pathlib import Path
9
+
10
+ from . import __version__
11
+ from .phrases import FACE, NOFACE
12
+
13
+
14
+ def normalize(text):
15
+ return re.sub(r'\s+', ' ', text.lower().replace("n't", ' not').replace('-', ' '))
16
+
17
+
18
+ def claims(text):
19
+ lines = []
20
+ fence = None
21
+ for line in text.splitlines():
22
+ match = re.match(r'^\s{0,3}(`{3,}|~{3,})', line)
23
+ if match:
24
+ marker = match.group(1)
25
+ if fence is None:
26
+ fence = marker
27
+ elif marker[0] == fence[0] and len(marker) >= len(fence):
28
+ fence = None
29
+ lines.append('')
30
+ elif fence is None:
31
+ lines.append(line)
32
+ positive = negative = False
33
+ for paragraph in re.split(r'\n\s*\n', '\n'.join(lines)):
34
+ paragraph = normalize(paragraph)
35
+ for phrase in sorted(NOFACE, key=len, reverse=True):
36
+ paragraph, count = re.subn(r'\b' + re.escape(phrase) + r'\b', ' ', paragraph)
37
+ negative |= bool(count)
38
+ positive |= any(re.search(r'\b' + re.escape(p) + r'\b', paragraph) for p in FACE)
39
+ return positive, negative
40
+
41
+
42
+ def evidence(source):
43
+ try:
44
+ tree = ast.parse(source)
45
+ except SyntaxError:
46
+ return False
47
+ aliases = {}
48
+ shadows = {n.name for n in ast.walk(tree) if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef))}
49
+ for node in ast.walk(tree):
50
+ if isinstance(node, ast.Import):
51
+ for item in node.names:
52
+ aliases[item.asname or item.name.split('.')[0]] = item.name if item.asname else item.name.split('.')[0]
53
+ elif isinstance(node, ast.ImportFrom) and node.module:
54
+ for item in node.names:
55
+ aliases[item.asname or item.name] = node.module + '.' + item.name
56
+
57
+ def resolve(node):
58
+ if isinstance(node, ast.Name):
59
+ return '' if node.id in shadows else aliases.get(node.id, '')
60
+ if isinstance(node, ast.Attribute):
61
+ base = resolve(node.value)
62
+ return base + '.' + node.attr if base else ''
63
+ return ''
64
+
65
+ def construction(node):
66
+ if not isinstance(node, ast.Call):
67
+ return None
68
+ path = resolve(node.func)
69
+ if path == 'cv2.CascadeClassifier' and any(isinstance(a, ast.Constant) and isinstance(a.value, str) and 'face' in a.value.lower() for a in node.args):
70
+ return 'cascade'
71
+ if path.endswith('.face_detection.FaceDetection'):
72
+ return 'media'
73
+ return None
74
+
75
+ def key(node):
76
+ if isinstance(node, ast.Name):
77
+ return node.id
78
+ if isinstance(node, ast.Attribute):
79
+ base = key(node.value)
80
+ return base + '.' + node.attr if base else None
81
+ return None
82
+
83
+ bound = {}
84
+ for node in ast.walk(tree):
85
+ if isinstance(node, (ast.Assign, ast.AnnAssign)):
86
+ kind = construction(node.value)
87
+ if kind:
88
+ targets = node.targets if isinstance(node, ast.Assign) else [node.target]
89
+ for target in targets:
90
+ bound[key(target)] = kind
91
+ elif isinstance(node, (ast.With, ast.AsyncWith)):
92
+ for item in node.items:
93
+ kind = construction(item.context_expr)
94
+ if kind and item.optional_vars:
95
+ bound[key(item.optional_vars)] = kind
96
+ for node in ast.walk(tree):
97
+ if not isinstance(node, ast.Call):
98
+ continue
99
+ path = resolve(node.func)
100
+ if path in {'face_recognition.' + name for name in ('face_locations', 'face_encodings', 'compare_faces', 'face_distance')} or path == 'dlib.get_frontal_face_detector':
101
+ return True
102
+ if construction(node) == 'media':
103
+ return True
104
+ if isinstance(node.func, ast.Attribute):
105
+ kind = construction(node.func.value) or bound.get(key(node.func.value))
106
+ if (node.func.attr, kind) in {('detectMultiScale', 'cascade'), ('process', 'media')}:
107
+ return True
108
+ return False
109
+
110
+
111
+ def audit(root, ignore=(), fail_on='HIGH'):
112
+ root = Path(root)
113
+ if not root.is_dir() or not os.access(root, os.R_OK | os.X_OK):
114
+ raise ValueError('Root must be a readable directory')
115
+ pos = neg = prod = test = False
116
+ scanned = 0
117
+ for directory, dirs, files in os.walk(root, followlinks=False):
118
+ dirs[:] = sorted(d for d in dirs if not Path(directory, d).is_symlink())
119
+ for name in sorted(files):
120
+ path = Path(directory, name)
121
+ rel = path.relative_to(root)
122
+ if path.is_symlink() or any(fnmatch.fnmatch(rel.as_posix(), g) for g in ignore):
123
+ continue
124
+ parts = rel.parts[:-1]
125
+ is_doc = rel.as_posix() == 'README.md' or ('docs' in parts and path.suffix.lower() == '.md')
126
+ if not is_doc and path.suffix != '.py':
127
+ continue
128
+ try:
129
+ text = path.read_text(encoding='utf-8')
130
+ except (OSError, UnicodeError) as exc:
131
+ raise ValueError('Cannot read ' + rel.as_posix()) from exc
132
+ scanned += 1
133
+ if is_doc:
134
+ p, n = claims(text)
135
+ pos |= p
136
+ neg |= n
137
+ elif not any(p in {'fixtures', 'docs', 'examples'} for p in parts):
138
+ found = evidence(text)
139
+ if 'tests' in parts or name.startswith('test_') or name.endswith('_test.py'):
140
+ test |= found
141
+ else:
142
+ prod |= found
143
+ findings = []
144
+ if pos and not prod:
145
+ findings.append({'rule': 'documented-face-claim-false', 'severity': 'MEDIUM' if test else 'HIGH', 'message': 'Documented picture-face capability lacks production evidence.'})
146
+ if neg and prod:
147
+ findings.append({'rule': 'documented-no-face-claim-false', 'severity': 'HIGH', 'message': 'Documented absence conflicts with production evidence.'})
148
+ failed = any(f['severity'] == 'HIGH' or fail_on == 'MEDIUM' for f in findings)
149
+ return {'verdict': 'FAIL' if failed else 'PASS', 'findings': findings, 'files_scanned': scanned}
150
+
151
+
152
+ def main(argv=None):
153
+ parser = argparse.ArgumentParser(description='Check documented picture-face claims against Python source.')
154
+ parser.add_argument('root', nargs='?', default='.')
155
+ parser.add_argument('--json', action='store_true')
156
+ parser.add_argument('--verbose', action='store_true')
157
+ parser.add_argument('--ignore', action='append', default=[])
158
+ parser.add_argument('--fail-on', choices=('HIGH', 'MEDIUM'), default='HIGH')
159
+ parser.add_argument('--version', action='version', version=__version__)
160
+ args = parser.parse_args(argv)
161
+ try:
162
+ result = audit(args.root, args.ignore, args.fail_on)
163
+ except (ValueError, OSError) as exc:
164
+ if args.json:
165
+ print(json.dumps({'error': str(exc)}))
166
+ else:
167
+ print(str(exc))
168
+ return 1
169
+ if args.json:
170
+ print(json.dumps(result))
171
+ else:
172
+ print(result['verdict'])
173
+ for finding in result['findings']:
174
+ print('{severity} {rule}: {message}'.format(**finding))
175
+ if args.verbose:
176
+ print('Scanned {} files'.format(result['files_scanned']))
177
+ return 2 if result['verdict'] == 'FAIL' else 0
@@ -0,0 +1,3 @@
1
+ """Exact documented claim templates."""
2
+ FACE = ('supports facial recognition', 'recognizes faces in photos', 'recognises faces in photos', 'recognizes faces in images', 'recognises faces in images', 'identifies faces in photos', 'identifies faces in images', 'support facial recognition', 'facial recognition support', 'recognize faces in photos', 'recognise faces in photos', 'recognize faces in images', 'recognise faces in images', 'supports face recognition', 'identify faces in photos', 'identify faces in images', 'support face recognition', 'face recognition support', 'detects faces in photos', 'detects faces in images', 'detect faces in photos', 'detect faces in images', 'detects faces in video', 'detect faces in video', 'face identification', 'facial recognition', 'recognizes a face', 'recognises a face', 'identifies a face', 'recognizes faces', 'recognises faces', 'identifies faces', 'recognize a face', 'recognise a face', 'face recognition', 'recognize faces', 'recognise faces', 'identify a face', 'identify faces', 'detects a face', 'face detection', 'detects faces', 'detect a face', 'detect faces')
3
+ NOFACE = ('does not support facial recognition', 'does not recognize faces in photos', 'does not recognise faces in photos', 'does not recognize faces in images', 'does not recognise faces in images', 'does not support face recognition', 'does not identify faces in photos', 'does not identify faces in images', 'facial recognition not supported', 'does not detect faces in photos', 'does not detect faces in images', 'face recognition not supported', 'face detection not supported', 'without face identification', 'without facial recognition', 'does not recognize faces', 'does not recognise faces', 'without face recognition', 'does not identify faces', 'without face detection', 'no face identification', 'does not detect faces', 'no facial recognition', 'no face recognition', 'no face detection')
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.4
2
+ Name: face-claim-audit
3
+ Version: 0.1.0
4
+ Summary: Offline audit of documented picture-face claims against Python source
5
+ License: MIT
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # face-claim-audit 0.1.0
12
+
13
+ Offline static audit of documented picture-face claims against Python source.
14
+ Audited code is parsed with AST and never executed. Runtime dependencies: none.
15
+ Requires Python >=3.9.
16
+
17
+ ## Usage
18
+
19
+ ```sh
20
+ python3 -m pip install .
21
+ face-claim-audit /path/to/project
22
+ python3 -m face_claim_audit /path/to/project --json --verbose
23
+ python3 -m face_claim_audit /path/to/project --ignore 'docs/old/*' --fail-on MEDIUM
24
+ python3 -m unittest discover
25
+ python3 -m build
26
+ ```
27
+
28
+ The root README.md and Markdown files with a docs path component supply claims.
29
+ Fenced blocks are excluded; inline code counts. Paragraph lines are joined,
30
+ case is folded, contractions expanded, hyphens replaced with spaces, and
31
+ whitespace collapsed. Exact templates use word boundaries, longest first;
32
+ negative spans are removed before positive matching.
33
+
34
+ Production evidence comes from imported, alias-resolved calls in Python files.
35
+ The supported providers are face_recognition, dlib, cv2, and mediapipe.
36
+ The first provider supports four operations, dlib its frontal detector factory,
37
+ cv2 a literal face-cascade construction paired with a bound scan method,
38
+ and mediapipe its specified detector construction or bound process method.
39
+ Assignments, self attributes, context targets, and chained calls are supported.
40
+ Local definitions shadow imports. Bare imports and strings are insufficient.
41
+ Tests, fixtures, docs, examples, and symlinked files are excluded from production.
42
+ Test evidence produces a MEDIUM finding; absence of production evidence produces
43
+ HIGH. Conflicting negative prose produces HIGH. Each family yields at most one
44
+ finding. With no claims, the result is PASS regardless of source.
45
+
46
+ Rules: `documented-face-claim-false`, `documented-no-face-claim-false`.
47
+ Default threshold HIGH reports MEDIUM without failing; --fail-on MEDIUM fails
48
+ on either severity. Exits: 0 PASS, 2 FAIL, 1 invalid or unreadable root.
49
+ JSON includes verdict, findings (rule, severity, message), and files_scanned.
50
+
51
+ ## Limitations
52
+
53
+ Only the exact templates below count. A bare face or faces, eyes alone,
54
+ age or gender estimation, person or body detection, privacy blurring,
55
+ camera capture, and image opening are outside claim scope.
56
+ A shell call to a system face finder is not counted: a command name in a
57
+ string literal is never evidence. Other face stacks, including phone-camera
58
+ SDKs, cloud picture-face APIs, and handwriting-specific engines, are out of
59
+ scope; only the Python routes described above are counted. Non-literal cascade
60
+ paths (variables, joins, or computed expressions) are not counted.
61
+ This is module-local static analysis, not runtime or cross-module proof;
62
+ syntax-invalid files provide no evidence. No optional provider is imported.
63
+ The scanner never opens .env files.
64
+
65
+ ## Exact templates
66
+
67
+ ```text
68
+ recognizes faces in photos
69
+ recognize faces in photos
70
+ recognises faces in photos
71
+ recognise faces in photos
72
+ recognizes faces in images
73
+ recognize faces in images
74
+ recognises faces in images
75
+ recognise faces in images
76
+ detects faces in photos
77
+ detect faces in photos
78
+ detects faces in images
79
+ detect faces in images
80
+ identifies faces in photos
81
+ identify faces in photos
82
+ identifies faces in images
83
+ identify faces in images
84
+ detects faces in video
85
+ detect faces in video
86
+ supports facial recognition
87
+ support facial recognition
88
+ supports face recognition
89
+ support face recognition
90
+ facial recognition support
91
+ face recognition support
92
+ recognizes faces
93
+ recognize faces
94
+ recognises faces
95
+ recognise faces
96
+ detects faces
97
+ detect faces
98
+ identifies faces
99
+ identify faces
100
+ recognizes a face
101
+ recognize a face
102
+ recognises a face
103
+ recognise a face
104
+ detects a face
105
+ detect a face
106
+ identifies a face
107
+ identify a face
108
+ face recognition
109
+ facial recognition
110
+ face detection
111
+ face identification
112
+ does not support facial recognition
113
+ does not support face recognition
114
+ does not recognize faces in photos
115
+ does not recognise faces in photos
116
+ does not recognize faces in images
117
+ does not recognise faces in images
118
+ does not detect faces in photos
119
+ does not detect faces in images
120
+ does not identify faces in photos
121
+ does not identify faces in images
122
+ does not recognize faces
123
+ does not recognise faces
124
+ does not detect faces
125
+ does not identify faces
126
+ facial recognition not supported
127
+ face recognition not supported
128
+ face detection not supported
129
+ no facial recognition
130
+ without facial recognition
131
+ no face recognition
132
+ without face recognition
133
+ no face detection
134
+ without face detection
135
+ no face identification
136
+ without face identification
137
+ ```
@@ -0,0 +1,25 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ face_claim_audit/__init__.py
6
+ face_claim_audit/__main__.py
7
+ face_claim_audit/audit.py
8
+ face_claim_audit/phrases.py
9
+ face_claim_audit.egg-info/PKG-INFO
10
+ face_claim_audit.egg-info/SOURCES.txt
11
+ face_claim_audit.egg-info/dependency_links.txt
12
+ face_claim_audit.egg-info/entry_points.txt
13
+ face_claim_audit.egg-info/top_level.txt
14
+ tests/__init__.py
15
+ tests/cases.py
16
+ tests/test_audit.py
17
+ tests/fixtures/.env
18
+ tests/fixtures/bad/README.md
19
+ tests/fixtures/bad/app.py
20
+ tests/fixtures/good/README.md
21
+ tests/fixtures/good/app.py
22
+ tests/fixtures/no-face/README.md
23
+ tests/fixtures/no-face/app.py
24
+ tests/fixtures/testonly/README.md
25
+ tests/fixtures/testonly/tests/test_impl.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ face-claim-audit = face_claim_audit.audit:main
@@ -0,0 +1 @@
1
+ face_claim_audit
@@ -0,0 +1,17 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "face-claim-audit"
7
+ version = "0.1.0"
8
+ description = "Offline audit of documented picture-face claims against Python source"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = {text = "MIT"}
12
+
13
+ [project.scripts]
14
+ face-claim-audit = "face_claim_audit.audit:main"
15
+
16
+ [tool.setuptools.packages.find]
17
+ include = ["face_claim_audit*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,35 @@
1
+ GOOD = [
2
+ 'from face_recognition import face_locations\nface_locations(img)',
3
+ 'import face_recognition\nface_recognition.face_encodings(img)',
4
+ 'from face_recognition import compare_faces\ncompare_faces(a,b)',
5
+ 'import dlib\ndlib.get_frontal_face_detector()',
6
+ 'import cv2\nc = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")\nc.detectMultiScale(img)',
7
+ 'import cv2\ncv2.CascadeClassifier("face.xml").detectMultiScale(img)',
8
+ 'import mediapipe as mp\nmp.solutions.face_detection.FaceDetection()',
9
+ 'from mediapipe.solutions.face_detection import FaceDetection as FD\nc=FD()\nc.process(img)',
10
+ 'from face_recognition import face_distance as fd\nfd(a,b)',
11
+ 'from dlib import get_frontal_face_detector as detector\ndetector()',
12
+ 'from cv2 import CascadeClassifier as CC\nself.c=CC("FACE.xml")\nself.c.detectMultiScale(img)',
13
+ 'import cv2 as cv\nwith cv.CascadeClassifier("face.xml") as c:\n c.detectMultiScale(img)',
14
+ 'import mediapipe as mp\nwith mp.solutions.face_detection.FaceDetection() as c:\n c.process(img)',
15
+ ]
16
+ BAD = [
17
+ 'pass', 'import face_recognition', 'from PIL import Image\nImage.open("x")',
18
+ 'import cv2\ncv2.VideoCapture(0)',
19
+ 'import face_recognition\nface_recognition.load_image_file("x")',
20
+ 'import cv2\nc=cv2.CascadeClassifier("haarcascade_eye.xml")\nc.detectMultiScale(img)',
21
+ 'import cv2\nc=cv2.CascadeClassifier("face.xml")',
22
+ 'c.detectMultiScale(img)', 'c.process(img)', 'name="Ada"',
23
+ 'def face_locations(x): pass\nface_locations(img)',
24
+ 'class FaceDetection: pass\nFaceDetection()',
25
+ 'def get_frontal_face_detector(): pass\nget_frontal_face_detector()',
26
+ 'import cv2\ncv2.imread("x")',
27
+ '@app.get("/")\ndef home(): pass',
28
+ 'import cv2\nc=cv2.CascadeClassifier(path)\nc.detectMultiScale(img)',
29
+ 'from face_recognition import face_locations\ndef face_locations(x): pass\nface_locations(img)',
30
+ 'from mediapipe.solutions.face_detection import FaceDetection\nclass FaceDetection: pass\nFaceDetection()',
31
+ 'import dlib\nclass dlib: pass\ndlib.get_frontal_face_detector()',
32
+ 'import subprocess\nsubprocess.run("face-finder")',
33
+ '"face_locations(img)"', '# face_locations(img)',
34
+ ]
35
+ NOCLAIM = ['detects eyes', 'detects people and bodies', 'face', 'faces', 'estimates age and gender', 'blurs faces for privacy', 'captures camera frames', 'opens images']
@@ -0,0 +1 @@
1
+ MARKER_ONLY
@@ -0,0 +1 @@
1
+ detects faces
@@ -0,0 +1 @@
1
+ name = "Ada"
@@ -0,0 +1 @@
1
+ detects faces
@@ -0,0 +1,2 @@
1
+ from face_recognition import face_locations
2
+ face_locations(img)
@@ -0,0 +1 @@
1
+ no face recognition
@@ -0,0 +1,2 @@
1
+ from face_recognition import face_locations
2
+ face_locations(img)
@@ -0,0 +1 @@
1
+ detects faces
@@ -0,0 +1,2 @@
1
+ from face_recognition import face_locations
2
+ face_locations(img)
@@ -0,0 +1,155 @@
1
+ import json
2
+ from pathlib import Path
3
+ import re
4
+ import subprocess
5
+ import sys
6
+ import tempfile
7
+ import unittest
8
+ from unittest.mock import patch
9
+
10
+ from face_claim_audit.audit import audit, claims, evidence
11
+ from face_claim_audit.phrases import FACE, NOFACE
12
+ from tests.cases import GOOD, BAD, NOCLAIM
13
+
14
+ ROOT = Path(__file__).resolve().parents[1]
15
+
16
+ class AuditTests(unittest.TestCase):
17
+ def project(self, doc='detects faces', code=None, filename='app.py'):
18
+ temp = tempfile.TemporaryDirectory()
19
+ self.addCleanup(temp.cleanup)
20
+ root = Path(temp.name)
21
+ (root/'README.md').write_text(doc)
22
+ if code is not None:
23
+ p = root/filename
24
+ p.parent.mkdir(parents=True, exist_ok=True)
25
+ p.write_text(code)
26
+ return root
27
+
28
+ def check_result(self, result, severity=None, rule='documented-face-claim-false', verdict=None):
29
+ self.assertEqual(result['verdict'], verdict or ('FAIL' if severity == 'HIGH' else 'PASS'))
30
+ self.assertEqual(len(result['findings']), 1 if severity else 0)
31
+ if severity:
32
+ self.assertEqual(result['findings'][0]['severity'], severity)
33
+ self.assertEqual(result['findings'][0]['rule'], rule)
34
+
35
+ def cli(self, *args):
36
+ return subprocess.run([sys.executable, '-m', 'face_claim_audit', *map(str,args)], capture_output=True, text=True)
37
+
38
+ def test_testonly(self):
39
+ for filename in ['tests/check.py', 'test_impl.py', 'impl_test.py']:
40
+ with self.subTest(filename=filename):
41
+ root = self.project(code=GOOD[0], filename=filename)
42
+ self.check_result(audit(root), 'MEDIUM')
43
+ self.check_result(audit(root, fail_on='MEDIUM'), 'MEDIUM', verdict='FAIL')
44
+ self.assertEqual(self.cli(root).returncode, 0)
45
+ self.assertEqual(self.cli(root,'--fail-on','MEDIUM').returncode, 2)
46
+
47
+ def test_no_source(self):
48
+ self.check_result(audit(self.project()), 'HIGH')
49
+ self.check_result(audit(self.project('no face recognition')))
50
+
51
+ def test_fences_inline_paragraphs(self):
52
+ for doc in ['```text\ndetects faces\n```', '~~~\ndetects faces\n~~~']:
53
+ self.check_result(audit(self.project(doc)))
54
+ for doc in ['`detects faces`', 'DETECTS-\nFACES', 'detects\nfaces']:
55
+ self.check_result(audit(self.project(doc)), 'HIGH')
56
+ self.assertEqual(claims('detects\n\nfaces'), (False,False))
57
+ self.assertEqual(claims("doesn't detect faces"), (False,True))
58
+ self.assertEqual(claims('predetects faces'), (False,False))
59
+
60
+ def test_docs_scope_ignore(self):
61
+ root=self.project('neutral')
62
+ (root/'docs').mkdir()
63
+ (root/'docs/nested.md').write_text('detects faces')
64
+ self.check_result(audit(root), 'HIGH')
65
+ self.check_result(audit(root, ['docs/*']))
66
+ self.assertEqual(self.cli(root,'--ignore','docs/*').returncode, 0)
67
+ (root/'docs/nested.md').unlink()
68
+ (root/'OTHER.md').write_text('detects faces')
69
+ self.check_result(audit(root))
70
+
71
+ def test_excluded_sources(self):
72
+ for name in ['docs/a.py','examples/a.py','fixtures/a.py']:
73
+ self.check_result(audit(self.project(code=GOOD[0],filename=name)), 'HIGH')
74
+ root=self.project()
75
+ outside=self.project(code=GOOD[0])
76
+ (root/'link.py').symlink_to(outside/'app.py')
77
+ (root/'linked').symlink_to(outside, target_is_directory=True)
78
+ self.check_result(audit(root), 'HIGH')
79
+
80
+ def test_env_never_read(self):
81
+ root=self.project('neutral')
82
+ (root/'.env').write_text('MARKER_ONLY')
83
+ original=Path.read_text
84
+ def guarded(path,*args,**kwargs):
85
+ self.assertNotEqual(path.name,'.env')
86
+ return original(path,*args,**kwargs)
87
+ with patch.object(Path,'read_text',guarded):
88
+ self.check_result(audit(root))
89
+
90
+ def test_self_audit(self):
91
+ self.assertEqual(claims((ROOT/'README.md').read_text()), (False,False))
92
+ self.check_result(audit(ROOT))
93
+
94
+ def test_cli(self):
95
+ self.assertEqual(self.cli('--version').stdout.strip(),'0.1.0')
96
+ self.assertEqual(self.cli('/nonexistent/face-audit-path').returncode,1)
97
+ root=self.project(code='pass')
98
+ run=self.cli(root,'--json','--verbose')
99
+ self.assertEqual(run.returncode,2)
100
+ self.check_result(json.loads(run.stdout),'HIGH')
101
+ self.assertIn('Scanned',self.cli(root,'--verbose').stdout)
102
+
103
+ def test_packaging(self):
104
+ for name in ['LICENSE','README.md','MANIFEST.in','pyproject.toml']:
105
+ self.assertTrue((ROOT/name).is_file())
106
+ metadata=(ROOT/'pyproject.toml').read_text()
107
+ self.assertIn('face-claim-audit = "face_claim_audit.audit:main"',metadata)
108
+ self.assertIn('recursive-include tests', (ROOT/'MANIFEST.in').read_text())
109
+ self.assertIn('MIT License',(ROOT/'LICENSE').read_text())
110
+ for path in list((ROOT/'face_claim_audit').glob('*.py'))+[ROOT/'README.md']:
111
+ text=path.read_text()
112
+ self.assertIsNone(re.search(r'\bpython\s+(?:-m|[^\s]+\.py)',text))
113
+ for secret in ['AKIA'+'0123456789ABCDEF', '-----BEGIN '+'PRIVATE KEY-----']:
114
+ self.assertNotIn(secret,text)
115
+
116
+ def test_max_two(self):
117
+ self.check_result(audit(self.project('detects faces. no face recognition',GOOD[0])), 'HIGH','documented-no-face-claim-false')
118
+
119
+ def test_imported_dotted_face_detection_provider(self):
120
+ code = 'from vendor.face_detection import FaceDetection as FD\nFD()'
121
+ self.check_result(audit(self.project(code=code)))
122
+
123
+ def test_syntax_error(self):
124
+ self.assertFalse(evidence('def !'))
125
+
126
+
127
+ def add_case(name, fn):
128
+ setattr(AuditTests, name, fn)
129
+
130
+ for i, code in enumerate(GOOD):
131
+ def test(self, code=code):
132
+ self.check_result(audit(self.project(code=code)))
133
+ add_case('test_good_%02d'%i,test)
134
+ for i, code in enumerate(BAD):
135
+ def test(self, code=code):
136
+ self.check_result(audit(self.project(code=code)), 'HIGH')
137
+ add_case('test_bad_%02d'%i,test)
138
+ for i, phrase in enumerate(FACE):
139
+ def test(self, phrase=phrase):
140
+ self.assertEqual(claims(phrase),(True,False))
141
+ self.check_result(audit(self.project(phrase)), 'HIGH')
142
+ add_case('test_face_phrase_%02d'%i,test)
143
+ for i, phrase in enumerate(NOFACE):
144
+ def test(self, phrase=phrase):
145
+ self.assertEqual(claims(phrase),(False,True))
146
+ self.check_result(audit(self.project(phrase)))
147
+ root=self.project(phrase,GOOD[0])
148
+ self.check_result(audit(root),'HIGH','documented-no-face-claim-false')
149
+ self.assertEqual(self.cli(root).returncode,2)
150
+ add_case('test_negative_phrase_%02d'%i,test)
151
+ for i, phrase in enumerate(NOCLAIM):
152
+ def test(self, phrase=phrase):
153
+ self.check_result(audit(self.project(phrase)))
154
+ self.check_result(audit(self.project(phrase,GOOD[0])))
155
+ add_case('test_no_claim_%02d'%i,test)