zyppcli 0.3.0__tar.gz → 0.4.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.
- {zyppcli-0.3.0 → zyppcli-0.4.0}/PKG-INFO +72 -11
- {zyppcli-0.3.0 → zyppcli-0.4.0}/README.md +70 -10
- {zyppcli-0.3.0 → zyppcli-0.4.0}/plans/anonymize-plan.md +43 -17
- {zyppcli-0.3.0 → zyppcli-0.4.0}/pyproject.toml +2 -1
- {zyppcli-0.3.0 → zyppcli-0.4.0}/tests/conftest.py +3 -1
- {zyppcli-0.3.0 → zyppcli-0.4.0}/tests/test_anonymize.py +104 -7
- zyppcli-0.4.0/tests/test_integration.py +355 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/tests/test_pdf.py +41 -0
- zyppcli-0.4.0/tests/test_recognizers.py +55 -0
- zyppcli-0.4.0/tests/test_synthetic.py +62 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/uv.lock +15 -1
- {zyppcli-0.3.0 → zyppcli-0.4.0}/zyppcli/anonymization/pdf.py +75 -17
- zyppcli-0.4.0/zyppcli/anonymization/recognizers.py +42 -0
- zyppcli-0.4.0/zyppcli/anonymization/synthetic.py +72 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/zyppcli/anonymization/text.py +75 -6
- {zyppcli-0.3.0 → zyppcli-0.4.0}/zyppcli/commands/anonymize.py +78 -14
- zyppcli-0.3.0/tests/test_integration.py +0 -129
- {zyppcli-0.3.0 → zyppcli-0.4.0}/.github/workflows/ci.yaml +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/.github/workflows/publish.yaml +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/.gitignore +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/.pre-commit-config.yaml +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/plans/zyppcli-plan.md +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/tests/test_tabular.py +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/zyppcli/__init__.py +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/zyppcli/__main__.py +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/zyppcli/anonymization/__init__.py +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/zyppcli/anonymization/tabular.py +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/zyppcli/commands/__init__.py +0 -0
- {zyppcli-0.3.0 → zyppcli-0.4.0}/zyppcli/commands/keyvault.py +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: zyppcli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Internal CLI for Zypp
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Requires-Dist: azure-identity>=1.17.0
|
|
7
7
|
Requires-Dist: azure-keyvault-secrets>=4.8.0
|
|
8
8
|
Requires-Dist: azure-mgmt-keyvault>=10.0.0
|
|
9
9
|
Requires-Dist: certifi>=2026.10.18
|
|
10
|
+
Requires-Dist: faker>=40.63.0
|
|
10
11
|
Requires-Dist: openpyxl>=3.1.5
|
|
11
12
|
Requires-Dist: pandas>=3.1.1
|
|
12
13
|
Requires-Dist: pillow>=13.0.0
|
|
@@ -88,16 +89,65 @@ zypp anonymize ./client-files --output ./review-copy
|
|
|
88
89
|
```
|
|
89
90
|
|
|
90
91
|
Dutch is the default. Processing uses local Presidio/spaCy/Tesseract engines;
|
|
91
|
-
client files are not sent to cloud services.
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
client files are not sent to cloud services. By default, detected values are
|
|
93
|
+
replaced with synthetic data: fake names, example-domain emails, generated bank
|
|
94
|
+
accounts and other values of the detected type. The same entity type and exact
|
|
95
|
+
value receive the same replacement within one run; the in-memory mapping is not
|
|
96
|
+
saved. Different runs generate new data.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Default: fill detected fields with bogus data
|
|
100
|
+
zypp anonymize report.pdf
|
|
101
|
+
|
|
102
|
+
# Previous behavior: black PDF boxes and entity-label replacements in text/Excel
|
|
103
|
+
zypp anonymize report.pdf --redact
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
PDF originals are removed before replacement text is drawn, including text in
|
|
107
|
+
images. Unaffected native text stays selectable. Long fake values may use smaller
|
|
108
|
+
text or be abbreviated to fit the original field. No original text is left hidden
|
|
109
|
+
under the replacement. A synthetic PDF field is not an editable form widget.
|
|
110
|
+
|
|
111
|
+
Detection is broad by default: organization names, locations and dates are included,
|
|
112
|
+
as well as personal identifiers. For business documents where you want to keep
|
|
113
|
+
those categories, opt into the narrower personal profile:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
zypp anonymize report.pdf --profile personal
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This profile targets people, email addresses, phone numbers, Dutch BSNs, IBANs and
|
|
120
|
+
credit cards. It leaves organization names, locations and dates alone, including
|
|
121
|
+
birth dates. It reduces false positives on ordinary Dutch business terms that the
|
|
122
|
+
language model mistakes for organizations or places. It does not prevent all
|
|
123
|
+
incorrect detections of person names.
|
|
124
|
+
|
|
125
|
+
For more specific tuning:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Choose exactly which Presidio entity types to detect (overrides the profile)
|
|
129
|
+
zypp anonymize report.pdf --entities PERSON EMAIL_ADDRESS PHONE_NUMBER NL_BSN IBAN_CODE
|
|
130
|
+
|
|
131
|
+
# Discard detections below a Presidio score of 0.7
|
|
132
|
+
zypp anonymize report.pdf --profile personal --score-threshold 0.7
|
|
133
|
+
|
|
134
|
+
# Keep an exact detected phrase; repeat the option for more phrases
|
|
135
|
+
zypp anonymize report.pdf --allow-list Vakantiebijslag --allow-list Onregelmatigheids-
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Settings apply to native PDF text, OCR, Excel, CSV and text/JSON alike. Allow-list
|
|
139
|
+
matches are exact and case-sensitive. The default score threshold remains `0`,
|
|
140
|
+
preserving the original broad behavior. Raising it is not a universal fix: spaCy
|
|
141
|
+
name/location/organization detections commonly share the same fixed score, so a
|
|
142
|
+
high threshold can discard real names as well as false positives. Start by choosing
|
|
143
|
+
the categories your use case needs; use an allow-list for known-safe exact phrases.
|
|
94
144
|
|
|
95
145
|
| Format | Result |
|
|
96
146
|
| --- | --- |
|
|
97
|
-
| `.pdf` | Preserves unaffected selectable text on native and mixed pages. Scans use OCR for detection and remain image content. Detected characters are deleted and matching image pixels are blanked. Interactive forms, annotations, links and original document metadata are removed. |
|
|
147
|
+
| `.pdf` | Preserves unaffected selectable text on native and mixed pages. Scans use OCR for detection and remain image content. Detected characters are deleted and matching image pixels are blanked before synthetic text is inserted; `--redact` uses black fills. Interactive forms, annotations, links and original document metadata are removed. |
|
|
98
148
|
| `.xlsx` | Fresh values-only workbook. All worksheets and hidden cells are processed; output tabs are named `Sheet1`, `Sheet2`, etc. Formulas, formatting, comments, links, drawings and original metadata are omitted. |
|
|
99
149
|
| `.csv`, `.tsv` | Properly quoted UTF-8 data with cell-level replacements. CSV uses commas; TSV uses tabs. |
|
|
100
|
-
| `.txt`, `.md`, `.log` | UTF-8 text with entity
|
|
150
|
+
| `.txt`, `.md`, `.log` | UTF-8 text with synthetic values, or entity labels with `--redact`. |
|
|
101
151
|
| `.json`, `.jsonl` | Valid JSON with processed keys and values. Colliding or duplicate keys are rejected. |
|
|
102
152
|
|
|
103
153
|
Excel formulas use the results saved by Excel. If a formula has no saved result,
|
|
@@ -107,11 +157,22 @@ Unmatched values retain their types, and text leading zeroes are preserved.
|
|
|
107
157
|
Custom Excel display formats such as `000000000` are not retained. Excel drawings
|
|
108
158
|
and embedded objects are omitted with a warning, rather than processed as images.
|
|
109
159
|
|
|
110
|
-
Originals are preserved
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
160
|
+
Originals are preserved. Rerunning replaces matching output files automatically;
|
|
161
|
+
you do not need to delete earlier output first. Replacement is atomic: a failed
|
|
162
|
+
rerun keeps the previous completed output. Folder reruns keep unrelated existing
|
|
163
|
+
files. Source/output overlap and symbolic links are refused.
|
|
164
|
+
|
|
165
|
+
For folders, unsupported files are skipped. Failed new files have no final output,
|
|
166
|
+
and completed files are retained. A skipped or failed file makes the command exit
|
|
167
|
+
with status `1` and report a partial run. Temporary files and new output use
|
|
168
|
+
owner-only permissions where supported.
|
|
169
|
+
|
|
170
|
+
Dutch invoice coverage includes an IBAN-field fallback for OCR spacing/character
|
|
171
|
+
confusion and a targeted name recognizer for initials and a
|
|
172
|
+
surname after `T.a.v.` or `Ter attentie van`, plus Dutch VAT ID format detection
|
|
173
|
+
(`NL_VAT`) in broad mode. The personal profile includes the name recognizer but
|
|
174
|
+
omits VAT IDs unless explicitly selected through `--entities`. These focused rules
|
|
175
|
+
help with invoice fields; arbitrary names and addresses can still be missed.
|
|
115
176
|
|
|
116
177
|
**Review output before sharing.** Detection and OCR can miss personal data or
|
|
117
178
|
replace harmless text. Faces, signatures, indirect identifiers and every kind of
|
|
@@ -68,16 +68,65 @@ zypp anonymize ./client-files --output ./review-copy
|
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
Dutch is the default. Processing uses local Presidio/spaCy/Tesseract engines;
|
|
71
|
-
client files are not sent to cloud services.
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
client files are not sent to cloud services. By default, detected values are
|
|
72
|
+
replaced with synthetic data: fake names, example-domain emails, generated bank
|
|
73
|
+
accounts and other values of the detected type. The same entity type and exact
|
|
74
|
+
value receive the same replacement within one run; the in-memory mapping is not
|
|
75
|
+
saved. Different runs generate new data.
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Default: fill detected fields with bogus data
|
|
79
|
+
zypp anonymize report.pdf
|
|
80
|
+
|
|
81
|
+
# Previous behavior: black PDF boxes and entity-label replacements in text/Excel
|
|
82
|
+
zypp anonymize report.pdf --redact
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
PDF originals are removed before replacement text is drawn, including text in
|
|
86
|
+
images. Unaffected native text stays selectable. Long fake values may use smaller
|
|
87
|
+
text or be abbreviated to fit the original field. No original text is left hidden
|
|
88
|
+
under the replacement. A synthetic PDF field is not an editable form widget.
|
|
89
|
+
|
|
90
|
+
Detection is broad by default: organization names, locations and dates are included,
|
|
91
|
+
as well as personal identifiers. For business documents where you want to keep
|
|
92
|
+
those categories, opt into the narrower personal profile:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
zypp anonymize report.pdf --profile personal
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
This profile targets people, email addresses, phone numbers, Dutch BSNs, IBANs and
|
|
99
|
+
credit cards. It leaves organization names, locations and dates alone, including
|
|
100
|
+
birth dates. It reduces false positives on ordinary Dutch business terms that the
|
|
101
|
+
language model mistakes for organizations or places. It does not prevent all
|
|
102
|
+
incorrect detections of person names.
|
|
103
|
+
|
|
104
|
+
For more specific tuning:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Choose exactly which Presidio entity types to detect (overrides the profile)
|
|
108
|
+
zypp anonymize report.pdf --entities PERSON EMAIL_ADDRESS PHONE_NUMBER NL_BSN IBAN_CODE
|
|
109
|
+
|
|
110
|
+
# Discard detections below a Presidio score of 0.7
|
|
111
|
+
zypp anonymize report.pdf --profile personal --score-threshold 0.7
|
|
112
|
+
|
|
113
|
+
# Keep an exact detected phrase; repeat the option for more phrases
|
|
114
|
+
zypp anonymize report.pdf --allow-list Vakantiebijslag --allow-list Onregelmatigheids-
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Settings apply to native PDF text, OCR, Excel, CSV and text/JSON alike. Allow-list
|
|
118
|
+
matches are exact and case-sensitive. The default score threshold remains `0`,
|
|
119
|
+
preserving the original broad behavior. Raising it is not a universal fix: spaCy
|
|
120
|
+
name/location/organization detections commonly share the same fixed score, so a
|
|
121
|
+
high threshold can discard real names as well as false positives. Start by choosing
|
|
122
|
+
the categories your use case needs; use an allow-list for known-safe exact phrases.
|
|
74
123
|
|
|
75
124
|
| Format | Result |
|
|
76
125
|
| --- | --- |
|
|
77
|
-
| `.pdf` | Preserves unaffected selectable text on native and mixed pages. Scans use OCR for detection and remain image content. Detected characters are deleted and matching image pixels are blanked. Interactive forms, annotations, links and original document metadata are removed. |
|
|
126
|
+
| `.pdf` | Preserves unaffected selectable text on native and mixed pages. Scans use OCR for detection and remain image content. Detected characters are deleted and matching image pixels are blanked before synthetic text is inserted; `--redact` uses black fills. Interactive forms, annotations, links and original document metadata are removed. |
|
|
78
127
|
| `.xlsx` | Fresh values-only workbook. All worksheets and hidden cells are processed; output tabs are named `Sheet1`, `Sheet2`, etc. Formulas, formatting, comments, links, drawings and original metadata are omitted. |
|
|
79
128
|
| `.csv`, `.tsv` | Properly quoted UTF-8 data with cell-level replacements. CSV uses commas; TSV uses tabs. |
|
|
80
|
-
| `.txt`, `.md`, `.log` | UTF-8 text with entity
|
|
129
|
+
| `.txt`, `.md`, `.log` | UTF-8 text with synthetic values, or entity labels with `--redact`. |
|
|
81
130
|
| `.json`, `.jsonl` | Valid JSON with processed keys and values. Colliding or duplicate keys are rejected. |
|
|
82
131
|
|
|
83
132
|
Excel formulas use the results saved by Excel. If a formula has no saved result,
|
|
@@ -87,11 +136,22 @@ Unmatched values retain their types, and text leading zeroes are preserved.
|
|
|
87
136
|
Custom Excel display formats such as `000000000` are not retained. Excel drawings
|
|
88
137
|
and embedded objects are omitted with a warning, rather than processed as images.
|
|
89
138
|
|
|
90
|
-
Originals are preserved
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
139
|
+
Originals are preserved. Rerunning replaces matching output files automatically;
|
|
140
|
+
you do not need to delete earlier output first. Replacement is atomic: a failed
|
|
141
|
+
rerun keeps the previous completed output. Folder reruns keep unrelated existing
|
|
142
|
+
files. Source/output overlap and symbolic links are refused.
|
|
143
|
+
|
|
144
|
+
For folders, unsupported files are skipped. Failed new files have no final output,
|
|
145
|
+
and completed files are retained. A skipped or failed file makes the command exit
|
|
146
|
+
with status `1` and report a partial run. Temporary files and new output use
|
|
147
|
+
owner-only permissions where supported.
|
|
148
|
+
|
|
149
|
+
Dutch invoice coverage includes an IBAN-field fallback for OCR spacing/character
|
|
150
|
+
confusion and a targeted name recognizer for initials and a
|
|
151
|
+
surname after `T.a.v.` or `Ter attentie van`, plus Dutch VAT ID format detection
|
|
152
|
+
(`NL_VAT`) in broad mode. The personal profile includes the name recognizer but
|
|
153
|
+
omits VAT IDs unless explicitly selected through `--entities`. These focused rules
|
|
154
|
+
help with invoice fields; arbitrary names and addresses can still be missed.
|
|
95
155
|
|
|
96
156
|
**Review output before sharing.** Detection and OCR can miss personal data or
|
|
97
157
|
replace harmless text. Faces, signatures, indirect identifiers and every kind of
|
|
@@ -50,8 +50,8 @@ can miss personal data; generated files still need review before sharing.
|
|
|
50
50
|
copies a DataFrame and replaces unique values in explicitly mapped columns
|
|
51
51
|
using Faker. Its README, converter and tests contain no Excel reader/writer.
|
|
52
52
|
Retain the non-destructive approach; do not depend on the package or port its
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
generalization logic. A subsequent user request adds Faker through Presidio
|
|
54
|
+
custom operators, with in-memory consistency for exact repeated values.
|
|
55
55
|
5. Follow [Zypp's Python/uv conventions](https://github.com/zypp-io/zypp-knowledge-base/blob/main/concepts/tech-stack-overview.md).
|
|
56
56
|
The [credential-hygiene guidance](https://github.com/zypp-io/zypp-knowledge-base/blob/main/concepts/credential-hygiene.md)
|
|
57
57
|
provides existing CLI context, but is not a personal-data detection standard.
|
|
@@ -75,13 +75,14 @@ zypp anonymize report.pdf --language en
|
|
|
75
75
|
- Positional `path`; optional `-o/--output`; `--language {nl,en}`, default `nl`.
|
|
76
76
|
- Initially support `.pdf`, `.xlsx`, `.csv`, `.tsv`, `.txt`, `.md`, `.log`,
|
|
77
77
|
`.json` and `.jsonl`. Do not add separate image/DICOM commands in v1.
|
|
78
|
-
-
|
|
78
|
+
- Replace existing generated output on reruns. Refuse source/destination overlap and symbolic links.
|
|
79
79
|
Do not follow directory symlinks. Do not allow output inside the source tree.
|
|
80
80
|
- For a folder, process supported regular files sequentially. Report unsupported
|
|
81
81
|
files as skipped, without copying their originals. Return nonzero if any file
|
|
82
82
|
was skipped or failed; retain completed outputs and identify the run as partial.
|
|
83
|
-
- Publish each output only after that file is complete
|
|
84
|
-
temporary output on failure
|
|
83
|
+
- Publish each output only after that file is complete, using atomic replacement.
|
|
84
|
+
Remove temporary output on failure and keep any previous completed output.
|
|
85
|
+
Folder reruns replace matching paths and retain other existing files.
|
|
85
86
|
- Show file counts and safe error categories, not cell text, OCR results or entity
|
|
86
87
|
values. File paths may themselves identify people; avoid unnecessary logging.
|
|
87
88
|
- Filesystem names remain unchanged except for the output suffix. Tell users to
|
|
@@ -98,9 +99,16 @@ text, batch and image engines. Check dependencies and selected model before
|
|
|
98
99
|
processing; report installation instructions instead of triggering model downloads
|
|
99
100
|
while handling client data. There is no language auto-detection in v1.
|
|
100
101
|
|
|
101
|
-
Use
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
Use Faker-based synthetic values by default through Presidio custom operators.
|
|
103
|
+
Keep `--redact` for entity labels in text/tabular data and black PDF boxes. Cache
|
|
104
|
+
replacements by entity type and exact source value for one invocation; never write
|
|
105
|
+
the mapping to disk. No remote recognizers or reversible mapping files.
|
|
106
|
+
|
|
107
|
+
For PDF synthesis, let Presidio resolve overlapping detections. Map its resulting
|
|
108
|
+
operator items back to source ranges, validating the mapping before output. Remove
|
|
109
|
+
original characters/image pixels, then insert synthetic text in the detected
|
|
110
|
+
rectangles. Shrink or abbreviate long replacements to fit. Reuse Presidio's OCR
|
|
111
|
+
box mapping and avoid duplicate native/OCR replacement text on mixed pages.
|
|
104
112
|
Use the bundled public-suffix snapshot for email validation rather than fetching
|
|
105
113
|
suffix lists during anonymization.
|
|
106
114
|
|
|
@@ -111,6 +119,22 @@ one small PatternRecognizer with a nine-digit pattern and eleven-test checksum.
|
|
|
111
119
|
Test that addition independently. Do not claim arbitrary addresses, health facts,
|
|
112
120
|
faces, signatures or indirect identifiers are comprehensively detected.
|
|
113
121
|
|
|
122
|
+
## Detection tuning added after v0.3.0
|
|
123
|
+
|
|
124
|
+
Keep broad detection as the default, as requested. Add `--profile personal` to
|
|
125
|
+
target PERSON, EMAIL_ADDRESS/EMAIL, PHONE_NUMBER, NL_BSN, IBAN_CODE and CREDIT_CARD.
|
|
126
|
+
This deliberately excludes organizations, locations and dates, including birth
|
|
127
|
+
dates. Add `--entities` for an explicit selection, `--score-threshold` for a score
|
|
128
|
+
cutoff and repeatable `--allow-list` for exact case-sensitive phrases. Entity
|
|
129
|
+
selection overrides the profile. Apply the same settings to native text, batch
|
|
130
|
+
processing and OCR.
|
|
131
|
+
|
|
132
|
+
Dutch business terms can be recognized as organizations or locations at the same
|
|
133
|
+
0.85 score as valid names. Category selection is therefore more useful than
|
|
134
|
+
raising the threshold globally. OCR can also merge adjacent lines into false
|
|
135
|
+
person spans; known-safe words can need an explicit allow-list. Regression checks
|
|
136
|
+
cover the reported terms while ensuring email addresses and BSNs are still masked.
|
|
137
|
+
|
|
114
138
|
## Excel and CSV adapter
|
|
115
139
|
|
|
116
140
|
Keep this as workbook I/O plus Presidio batch calls, not a spreadsheet editor.
|
|
@@ -195,9 +219,9 @@ no identifying information; warn that such pages require review.
|
|
|
195
219
|
## Dependencies and code changes
|
|
196
220
|
|
|
197
221
|
Include Presidio analyzer, anonymizer and image-redactor, pandas, openpyxl,
|
|
198
|
-
PyMuPDF and
|
|
222
|
+
PyMuPDF, Pillow and Faker in the normal dependencies. Pin spaCy to the 3.8 series used by
|
|
199
223
|
the model wheels. Keep pdfminer.six, pypdfium2 and reportlab as test dependencies.
|
|
200
|
-
|
|
224
|
+
Add Faker for synthetic operators; do not add presidio-structured. Keep imports lazy.
|
|
201
225
|
|
|
202
226
|
PyPI does not accept external-wheel URL dependencies. Instead, provide
|
|
203
227
|
`zypp anonymize --setup` to install both official spaCy 3.8.0 model wheels into the
|
|
@@ -213,6 +237,8 @@ zyppcli/commands/anonymize.py # argparse, traversal, dispatch, output/errors
|
|
|
213
237
|
zyppcli/anonymization/text.py # shared Presidio initialization and text/JSON
|
|
214
238
|
zyppcli/anonymization/tabular.py # Excel/CSV file I/O and batch calls
|
|
215
239
|
zyppcli/anonymization/pdf.py # native coordinates, page rendering and image engine
|
|
240
|
+
zyppcli/anonymization/recognizers.py # focused Dutch invoice fallback patterns
|
|
241
|
+
zyppcli/anonymization/synthetic.py # Faker operators and per-run replacement consistency
|
|
216
242
|
tests/ # synthetic fixtures and focused behavior tests
|
|
217
243
|
```
|
|
218
244
|
|
|
@@ -224,7 +250,7 @@ background service, parallel workers or config file for v1.
|
|
|
224
250
|
|
|
225
251
|
1. Reconcile the existing untested draft command and optional dependencies with
|
|
226
252
|
this plan. Preserve the existing Key Vault behavior. Add command registration,
|
|
227
|
-
traversal,
|
|
253
|
+
traversal, original-file protection and per-file atomic replacement.
|
|
228
254
|
2. Implement shared Dutch/English engines and the Excel/CSV adapter. Verify two
|
|
229
255
|
sheets, headers, hidden data, mixed text, numeric identifiers, blanks, leading
|
|
230
256
|
zeroes, cached formulas, missing caches and literal formula-like strings. Reopen
|
|
@@ -245,8 +271,8 @@ background service, parallel workers or config file for v1.
|
|
|
245
271
|
harmless native text remains selectable and attachments/metadata are absent. Re-OCR known redacted regions and check the expected synthetic values
|
|
246
272
|
are absent; an empty text extraction alone cannot validate pixel redaction.
|
|
247
273
|
7. Check a single PDF, a single workbook and a mixed folder through the actual CLI.
|
|
248
|
-
Original hashes must remain unchanged;
|
|
249
|
-
failed
|
|
274
|
+
Original hashes must remain unchanged; reruns must replace generated output;
|
|
275
|
+
failed reruns must retain previous output; partial runs must return nonzero.
|
|
250
276
|
8. Document the setup and practical losses explicitly: values-only workbooks,
|
|
251
277
|
native-text preservation and scanned-page OCR, detection misses, unchanged filesystem names and required
|
|
252
278
|
human review. Leave unrelated security policies and KB pages unchanged.
|
|
@@ -255,13 +281,13 @@ background service, parallel workers or config file for v1.
|
|
|
255
281
|
|
|
256
282
|
Legacy `.xls`, `.xlsb`, macro-enabled Office files, Word/PowerPoint, Parquet,
|
|
257
283
|
standalone images/DICOM, cloud OCR, automatic language detection, face/signature
|
|
258
|
-
recognition, formula recalculation,
|
|
284
|
+
recognition, formula recalculation, cross-run identity mappings, reversible
|
|
259
285
|
pseudonyms, and perfect visual/structural preservation of every document variant.
|
|
260
286
|
|
|
261
287
|
## Verification result
|
|
262
288
|
|
|
263
|
-
Implemented following user approval. Local checks passed:
|
|
264
|
-
|
|
289
|
+
Implemented following user approval. Local checks passed: 85 focused tests and
|
|
290
|
+
26 real Dutch/English integration tests, Ruff and pre-commit checks, lockfile
|
|
265
291
|
validation, and source/wheel builds. Visually inspected native, scanned and mixed
|
|
266
292
|
PDF outputs. Rotation/crop, formula-cache, hidden-cell, failure-cleanup and
|
|
267
|
-
|
|
293
|
+
rerun replacement and original-file protection are covered. CI jobs have been added.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "zyppcli"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "Internal CLI for Zypp"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
@@ -13,6 +13,7 @@ dependencies = [
|
|
|
13
13
|
"azure-keyvault-secrets>=4.8.0",
|
|
14
14
|
"azure-mgmt-keyvault>=10.0.0",
|
|
15
15
|
"certifi>=2026.10.18",
|
|
16
|
+
"faker>=40.63.0",
|
|
16
17
|
"openpyxl>=3.1.5",
|
|
17
18
|
"pandas>=3.1.1",
|
|
18
19
|
"pillow>=13.0.0",
|
|
@@ -6,9 +6,11 @@ import pytest
|
|
|
6
6
|
|
|
7
7
|
class FakeEngines:
|
|
8
8
|
language = "en"
|
|
9
|
+
redact = True
|
|
9
10
|
|
|
10
|
-
def __init__(self, language="en"):
|
|
11
|
+
def __init__(self, language="en", **options):
|
|
11
12
|
self.language = language
|
|
13
|
+
self.analysis_options = options
|
|
12
14
|
|
|
13
15
|
def analyze(self, text):
|
|
14
16
|
return [
|
|
@@ -25,8 +25,11 @@ def test_originals_and_partial_folder(tmp_path, fake_cli, caplog):
|
|
|
25
25
|
assert not list(destination.rglob(".zypp-anonymize-*"))
|
|
26
26
|
assert "secret@example.org" not in caplog.text
|
|
27
27
|
assert (destination / "nested" / "data.txt").stat().st_mode & 0o777 == 0o600
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
(source / "nested" / "data.txt").write_text("Updated test@example.org")
|
|
29
|
+
repeated, completed, failed = anonymize.anonymize_path(source)
|
|
30
|
+
assert repeated == destination
|
|
31
|
+
assert (completed, failed) == (1, 3)
|
|
32
|
+
assert (destination / "nested" / "data.txt").read_text() == "Updated <EMAIL_ADDRESS>"
|
|
30
33
|
|
|
31
34
|
|
|
32
35
|
def test_destinations_and_symlinks(tmp_path, fake_cli):
|
|
@@ -41,18 +44,18 @@ def test_destinations_and_symlinks(tmp_path, fake_cli):
|
|
|
41
44
|
anonymize.anonymize_path(link)
|
|
42
45
|
target = tmp_path / "target"
|
|
43
46
|
target.symlink_to(tmp_path / "missing")
|
|
44
|
-
with pytest.raises(AnonymizeError, match="
|
|
47
|
+
with pytest.raises(AnonymizeError, match="Symbolic"):
|
|
45
48
|
anonymize.anonymize_path(source, target)
|
|
46
49
|
|
|
47
50
|
|
|
48
|
-
def
|
|
51
|
+
def test_publication_replaces_output_atomically(tmp_path, fake_engines):
|
|
49
52
|
source = tmp_path / "input.txt"
|
|
50
53
|
source.write_text("test@example.org")
|
|
51
54
|
destination = tmp_path / "existing.txt"
|
|
52
55
|
destination.write_text("keep me")
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
assert
|
|
56
|
+
anonymize._process(source, destination, fake_engines)
|
|
57
|
+
assert destination.read_text() == "<EMAIL_ADDRESS>"
|
|
58
|
+
assert source.read_text() == "test@example.org"
|
|
56
59
|
assert not list(tmp_path.glob(".zypp-anonymize-*"))
|
|
57
60
|
|
|
58
61
|
|
|
@@ -198,3 +201,97 @@ def test_failed_handler_cleans_temporary_output(tmp_path, fake_cli, monkeypatch)
|
|
|
198
201
|
assert (completed, failed) == (0, 1)
|
|
199
202
|
assert not destination.exists()
|
|
200
203
|
assert not list(tmp_path.glob(".zypp-anonymize-*"))
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def test_failed_rerun_retains_previous_output(tmp_path, fake_cli, monkeypatch):
|
|
207
|
+
source = tmp_path / "input.txt"
|
|
208
|
+
source.write_text("test@example.org")
|
|
209
|
+
destination = source.with_name("input.anonymized.txt")
|
|
210
|
+
destination.write_text("previous successful output")
|
|
211
|
+
|
|
212
|
+
def failing_handler(source, destination, engines):
|
|
213
|
+
destination.write_text("partial output")
|
|
214
|
+
raise RuntimeError("failure")
|
|
215
|
+
|
|
216
|
+
monkeypatch.setattr("zyppcli.anonymization.text.anonymize_text", failing_handler)
|
|
217
|
+
assert anonymize.anonymize_path(source)[1:] == (0, 1)
|
|
218
|
+
assert destination.read_text() == "previous successful output"
|
|
219
|
+
assert not list(tmp_path.glob(".zypp-anonymize-*"))
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def test_rerun_never_replaces_original_or_follows_output_symlinks(tmp_path, fake_cli):
|
|
223
|
+
source = tmp_path / "input.txt"
|
|
224
|
+
source.write_text("original")
|
|
225
|
+
with pytest.raises(AnonymizeError, match="original"):
|
|
226
|
+
anonymize.anonymize_path(source, source)
|
|
227
|
+
folder = tmp_path / "folder"
|
|
228
|
+
(folder / "nested").mkdir(parents=True)
|
|
229
|
+
(folder / "nested" / "input.txt").write_text("test@example.org")
|
|
230
|
+
output = tmp_path / "folder.anonymized"
|
|
231
|
+
output.mkdir()
|
|
232
|
+
(output / "nested").symlink_to(folder / "nested")
|
|
233
|
+
assert anonymize.anonymize_path(folder, output)[1:] == (0, 1)
|
|
234
|
+
assert (folder / "nested" / "input.txt").read_text() == "test@example.org"
|
|
235
|
+
assert source.read_text() == "original"
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@pytest.mark.parametrize("value", ["-0.1", "1.1", "nan", "inf", "-inf"])
|
|
239
|
+
def test_invalid_score_threshold_rejected(value):
|
|
240
|
+
parser = argparse.ArgumentParser()
|
|
241
|
+
anonymize.register(parser.add_subparsers(dest="command"))
|
|
242
|
+
with pytest.raises(SystemExit) as error:
|
|
243
|
+
parser.parse_args(["anonymize", "input.txt", "--score-threshold=" + value])
|
|
244
|
+
assert error.value.code == 2
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def test_cli_detection_settings_reach_adapters(tmp_path, monkeypatch):
|
|
248
|
+
from conftest import FakeEngines
|
|
249
|
+
|
|
250
|
+
source = tmp_path / "sample.txt"
|
|
251
|
+
source.write_text("test@example.org")
|
|
252
|
+
seen = {}
|
|
253
|
+
|
|
254
|
+
class CaptureEngines(FakeEngines):
|
|
255
|
+
def __init__(self, language, **settings):
|
|
256
|
+
super().__init__(language, **settings)
|
|
257
|
+
seen.update(settings)
|
|
258
|
+
|
|
259
|
+
monkeypatch.setattr(anonymize, "Engines", CaptureEngines)
|
|
260
|
+
parser = argparse.ArgumentParser()
|
|
261
|
+
anonymize.register(parser.add_subparsers(dest="command"))
|
|
262
|
+
args = parser.parse_args(
|
|
263
|
+
[
|
|
264
|
+
"anonymize",
|
|
265
|
+
str(source),
|
|
266
|
+
"--profile",
|
|
267
|
+
"personal",
|
|
268
|
+
"--entities",
|
|
269
|
+
"EMAIL_ADDRESS",
|
|
270
|
+
"--score-threshold",
|
|
271
|
+
"0.7",
|
|
272
|
+
"--allow-list",
|
|
273
|
+
"Vakantiebijslag",
|
|
274
|
+
"--allow-list",
|
|
275
|
+
"Onregelmatigheids-",
|
|
276
|
+
]
|
|
277
|
+
)
|
|
278
|
+
anonymize.run(args)
|
|
279
|
+
assert seen == {
|
|
280
|
+
"profile": "personal",
|
|
281
|
+
"entities": ["EMAIL_ADDRESS"],
|
|
282
|
+
"score_threshold": 0.7,
|
|
283
|
+
"allow_list": ["Vakantiebijslag", "Onregelmatigheids-"],
|
|
284
|
+
"redact": False,
|
|
285
|
+
}
|
|
286
|
+
assert source.with_name("sample.anonymized.txt").read_text() == "<EMAIL_ADDRESS>"
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def test_broad_detection_remains_default():
|
|
290
|
+
parser = argparse.ArgumentParser()
|
|
291
|
+
anonymize.register(parser.add_subparsers(dest="command"))
|
|
292
|
+
args = parser.parse_args(["anonymize", "input.pdf"])
|
|
293
|
+
assert args.profile == "all"
|
|
294
|
+
assert args.entities is None
|
|
295
|
+
assert args.score_threshold == 0
|
|
296
|
+
assert args.allow_list == []
|
|
297
|
+
assert args.redact is False
|