From 6d58d71c3a6a82afd1e0b32db7f2b934aa993b0d Mon Sep 17 00:00:00 2001 From: 0verwrite <31691645+overwrite00@users.noreply.github.com> Date: Wed, 11 Nov 2026 08:47:51 +0100 Subject: [PATCH 1/5] chore: relicense to AGPL-3.0-or-later, download the Italian spaCy model on demand PyMuPDF is AGPL-3.0 or commercial, and it_core_news_md is CC BY-NC-SA 3.0, so the MIT licence and a bundled non-commercial model cannot both be true. The Italian pipeline is now downloaded after the user accepts its licence, verified by size and SHA-256, and excluded from the installer together with pymupdf4llm and pymupdf.layout. Third-party licences are documented and a test guards against bundling a non-commercial dependency. --- .github/workflows/beta-release.yml | 2 +- .github/workflows/build-linux.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/test_build.yml | 2 +- CHANGELOG.md | 5 + DEVELOPMENT.md | 21 ++- LICENSE | 281 ++++++++++++++++++++++++++--- NullifyPDF.py | 111 +++++++++++- README.md | 15 +- THIRD_PARTY_NOTICES.md | 30 +++ build_local.py | 10 +- requirements.txt | 3 + spacy_models.py | 193 ++++++++++++++++++++ tests/test_gui_flow.py | 40 ++++ tests/test_licences.py | 48 +++++ tests/test_spacy_models.py | 94 ++++++++++ 16 files changed, 816 insertions(+), 43 deletions(-) create mode 100644 spacy_models.py create mode 100644 tests/test_licences.py create mode 100644 tests/test_spacy_models.py diff --git a/.github/workflows/beta-release.yml b/.github/workflows/beta-release.yml index f71edb5..a298ec9 100644 --- a/.github/workflows/beta-release.yml +++ b/.github/workflows/beta-release.yml @@ -50,7 +50,7 @@ jobs: - name: Type Check (mypy) shell: bash - run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py + run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py - name: Resolve beta suffix from tag if: startsWith(github.ref, 'refs/tags/') diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 09c82b4..419375b 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -82,7 +82,7 @@ jobs: run: pytest tests/ -v - name: Type check (mypy) - run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py + run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py - name: Resolve beta suffix from tag if: inputs.is_beta && startsWith(github.ref, 'refs/tags/') diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9f5ec6c..22c0545 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -95,7 +95,7 @@ jobs: - name: Type Check (mypy) shell: bash - run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py + run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py - name: Build run: python build_local.py diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml index b3aa452..0de9e1d 100644 --- a/.github/workflows/test_build.yml +++ b/.github/workflows/test_build.yml @@ -55,7 +55,7 @@ jobs: - name: Type Check (mypy) shell: bash - run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py + run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py - name: Build run: python build_local.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 813a0ac..3bf344f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### 🔄 Changed + +- **New licence: AGPL-3.0-or-later** (previously MIT), because the program uses PyMuPDF, which is AGPL-3.0 or commercial. The program stays free and is not sold. Full third-party licence list in `THIRD_PARTY_NOTICES.md`. +- **Italian name-recognition model downloaded on demand**: its licence (CC BY-NC-SA 3.0, non-commercial) cannot be bundled in an AGPL installer, so the first Italian scan shows the licence and asks for consent, then downloads and verifies the model (SHA-256). Detection quality is unchanged once installed; if you decline, the scan continues with rules and dictionaries only and the log says so. + ### ✨ Added - **Local PII models**: optional, user-downloaded ONNX models from pinned Hugging Face revisions are stored under `~/.nullifypdf/models/`, verified file-by-file with SHA-256, and contribute suggestions only. The model dialog shows the source, license, revision and download progress; unverified experimental entries remain blocked. diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 67e2847..2615fda 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -151,14 +151,19 @@ NullifyPDF/ | **python-docx** | — | Not required; DOCX import uses the standard-library OOXML reader | | **pytest** | 9.2.0 | Testing framework | -### Language Models (Auto-Downloaded) - -| Model | Size | Purpose | -| ----------------- | ----- | ----------- | -| `en_core_web_md` | 40 MB | English NER | -| `it_core_news_md` | 45 MB | Italian NER | - -These are downloaded automatically by `setup_env.py`. +### Language Models + +| Model | Size | Purpose | Licence | In the installer | +| ----------------- | ----- | ----------- | ------- | ---------------- | +| `en_core_web_md` | 40 MB | English NER | MIT | yes | +| `it_core_news_md` | 45 MB | Italian NER | CC BY-NC-SA 3.0 | **no**, downloaded by the app on demand (`spacy_models.py`) | + +`setup_env.py` installs both in the development environment (the Italian tests +need it). The PyInstaller specs exclude `it_core_news_md`, `pymupdf4llm` and +`pymupdf.layout`. At run time the app asks for consent, downloads the Italian +pipeline from the publisher's release, checks its size and SHA-256 and stores it +under `~/.nullifypdf/spacy_models/`. If the user declines, a blank Italian +pipeline is used and only rule-based detection is available. --- diff --git a/LICENSE b/LICENSE index 749775e..2bf02f1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,260 @@ -MIT License - -Copyright (c) 2026 Graziano Mariella - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +NullifyPDF +Copyright (C) 2026 Graziano Mariella + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU Affero General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your option) any +later version (SPDX: AGPL-3.0-or-later). + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + +NullifyPDF is free of charge and is not sold by its author. + +Why AGPL: the program uses PyMuPDF/MuPDF (Artifex), which is available under +the GNU AGPL-3.0 or a commercial licence. Releases up to and including +v2.4.0-beta.4 were published under the MIT licence; copies already received +under those terms remain under them. Starting with the next release the +program is distributed under the licence below. Third-party components keep +their own licences, see THIRD_PARTY_NOTICES.md. + +Source code: https://github.com/overwrite00/NullifyPDF + +================================================================================ + +GNU AFFERO GENERAL PUBLIC LICENSE +Version 3, 19 November 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + + Preamble + +The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. + +A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. + +The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. + +An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. + +The precise terms and conditions for copying, distribution and modification follow. + + TERMS AND CONDITIONS + +0. Definitions. + +"This License" refers to version 3 of the GNU Affero General Public License. + +"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. + +To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. + +A "covered work" means either the unmodified Program or a work based on the Program. + +To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. + +1. Source Code. +The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. + +A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those +subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +2. Basic Permissions. +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. + +4. Conveying Verbatim Copies. +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". + + c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. + +6. Conveying Non-Source Forms. +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + + d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. + +7. Additional Terms. +"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + + e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. + +8. Termination. + +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. + +9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. + +11. Patents. + +A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". + +A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. + +13. Remote Network Interaction; Use with the GNU General Public License. + +Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. + +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. + +14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. + +15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. + +You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see . diff --git a/NullifyPDF.py b/NullifyPDF.py index f034698..5759006 100644 --- a/NullifyPDF.py +++ b/NullifyPDF.py @@ -28,6 +28,7 @@ QRadioButton, QCheckBox, QProgressBar, + QProgressDialog, QTextEdit, QGraphicsView, QGraphicsScene, @@ -100,6 +101,7 @@ save_enabled_groups, whole_word_rects, ) +import spacy_models import update_check from export_engine import ( build_audit_record, @@ -167,6 +169,27 @@ def run(self) -> None: self.error_sig.emit(f"{type(e).__name__}: {e}") +class SpacyModelInstallWorker(QThread): + """Download the optional Italian spaCy pipeline off the UI thread.""" + + progress_sig = Signal(int, int) + done_sig = Signal() + error_sig = Signal(str) + + def __init__(self, root: pathlib.Path) -> None: + super().__init__() + self._root = root + + def run(self) -> None: + try: + spacy_models.install_italian( + self._root, progress=lambda d, t: self.progress_sig.emit(d, t) + ) + self.done_sig.emit() + except Exception as e: + self.error_sig.emit(str(e)) + + class UpdateDownloadWorker(QThread): """Download a release asset into the user's Downloads folder.""" @@ -909,6 +932,10 @@ def __init__(self) -> None: super().__init__() self.analyzer: Optional[Any] = None self.loaded_langs: List[str] = [] + # Set by the window before a scan: package name or folder of the + # Italian pipeline (it is downloaded on demand, see spacy_models). + self.italian_model: str = spacy_models.ITALIAN_PACKAGE + self._loaded_italian = "" self.model_detectors: List[Tuple[str, OnnxTokenDetector]] = [] self._stop_requested = False @@ -980,7 +1007,11 @@ def run_scan(self, doc: Any, doc_mutex: Any, choice: str, target_langs = ["en", "it"] if choice == "BOTH" else [choice.lower()] ocr_language = ocr_language_for_choice(choice, tessdata_dir) - if not self.analyzer or sorted(self.loaded_langs) != sorted(target_langs): + if ( + not self.analyzer + or sorted(self.loaded_langs) != sorted(target_langs) + or self._loaded_italian != self.italian_model + ): self.log_sig.emit(f"Inizializzazione motore di rilevamento ({choice})...") from presidio_analyzer import AnalyzerEngine, RecognizerRegistry from presidio_analyzer.nlp_engine import NlpEngineProvider @@ -992,7 +1023,7 @@ def run_scan(self, doc: Any, doc_mutex: Any, choice: str, else [] ) if "it" in target_langs: - models.append({"lang_code": "it", "model_name": "it_core_news_md"}) + models.append({"lang_code": "it", "model_name": self.italian_model}) provider = NlpEngineProvider( nlp_configuration={"nlp_engine_name": "spacy", "models": models} ) @@ -1025,6 +1056,7 @@ def run_scan(self, doc: Any, doc_mutex: Any, choice: str, supported_languages=target_langs, ) self.loaded_langs = target_langs + self._loaded_italian = self.italian_model self.log_sig.emit("Scansione privacy in corso...") self._load_local_detectors() targets = list(enabled_types) @@ -2103,7 +2135,7 @@ def cmd_about(self) -> None: lbl_ver.setAlignment(Qt.AlignmentFlag.AlignCenter) lay.addWidget(lbl_ver) desc = QLabel( - "\nCensura e pseudonimizzazione PDF offline.\n\nSviluppato da: Graziano Mariella\nLicenza MIT" + "\nCensura e pseudonimizzazione PDF offline.\n\nSviluppato da: Graziano Mariella\nLicenza AGPL-3.0" ) desc.setAlignment(Qt.AlignmentFlag.AlignCenter) lay.addWidget(desc) @@ -2298,6 +2330,9 @@ def cmd_auto_ai(self) -> None: if self.rb_en.isChecked() else "IT" if self.rb_it.isChecked() else "BOTH" ) + if lang in ("IT", "BOTH") and not self._prepare_italian_model(): + self.btn_ai.setEnabled(True) + return use_ocr = self.chk_ocr.isChecked() tessdata_dir = find_tessdata_dir() if use_ocr else None if use_ocr and not tessdata_dir: @@ -2324,6 +2359,76 @@ def cmd_auto_ai(self) -> None: health_mode, ) + def _prepare_italian_model(self) -> bool: + """Make an Italian pipeline available; False if the user cancels. + + The statistical pipeline is not bundled (non-commercial licence): ask + once, show the licence, download and verify it. If the user declines, + the scan continues with rules only and the log says so. + """ + root = spacy_models.models_root(self.config_dir) + found = spacy_models.resolve_italian(root) + if found is not None: + self.ai_worker.italian_model = found.name + return True + box = QMessageBox(self) + box.setWindowTitle("Modello italiano") + box.setIcon(QMessageBox.Icon.Question) + box.setText("Per riconoscere i nomi in italiano serve un modello aggiuntivo.") + box.setInformativeText(spacy_models.licence_text()) + b_dl = box.addButton("Accetta e scarica", QMessageBox.ButtonRole.AcceptRole) + b_skip = box.addButton("Continua senza modello", QMessageBox.ButtonRole.DestructiveRole) + box.addButton("Annulla", QMessageBox.ButtonRole.RejectRole) + box.exec() + clicked = box.clickedButton() + if clicked is b_skip: + self.ai_worker.italian_model = spacy_models.blank_italian(root).name + self.write_log( + "Avviso: modello italiano non installato, riconoscimento nomi " + "solo con regole e dizionari (meno completo)." + ) + return True + if clicked is not b_dl: + return False + dlg = QProgressDialog("Download del modello italiano...", "Annulla", 0, 100, self) + dlg.setWindowTitle("Modello italiano") + dlg.setMinimumDuration(0) + dlg.setAutoClose(False) + dlg.setAutoReset(False) + dlg.setCancelButton(None) + worker = SpacyModelInstallWorker(root) + result: Dict[str, str] = {} + + def on_progress(done: int, total: int) -> None: + dlg.setValue(int(done * 100 / max(1, total))) + + def on_done() -> None: + result["ok"] = "1" + dlg.accept() + + def on_error(msg: str) -> None: + result["error"] = msg + dlg.accept() + + worker.progress_sig.connect(on_progress) + worker.done_sig.connect(on_done) + worker.error_sig.connect(on_error) + worker.start() + dlg.exec() + worker.wait() + if "ok" in result: + found = spacy_models.resolve_italian(root) + if found is not None: + self.ai_worker.italian_model = found.name + self.write_log("Modello italiano scaricato e verificato.") + return True + QMessageBox.warning( + self, + "Modello italiano", + "Download non riuscito: " + result.get("error", "errore sconosciuto"), + ) + return False + def _select_ai_entities(self) -> Optional[List[str]]: """Ask which data types the AI scan should look for. diff --git a/README.md b/README.md index be56a0e..2fc9fb6 100644 --- a/README.md +++ b/README.md @@ -253,11 +253,22 @@ See [SECURITY.md](./SECURITY.md) for responsible disclosure and privacy details. ## 📝 License -**MIT License** — Free to use, modify, and distribute +**GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later)** Copyright (c) 2026 Graziano Mariella -See [LICENSE](./LICENSE) for full text. +NullifyPDF is free of charge and is not sold by its author. It is AGPL-licensed +because it uses [PyMuPDF](https://pymupdf.readthedocs.io/), which is available +under the AGPL-3.0 or a commercial licence from Artifex. Anyone who distributes +the program, modified or not, must give the recipients the source code under the +same licence. Releases up to v2.4.0-beta.4 were published under the MIT licence. + +The Italian name-recognition model (spaCy `it_core_news_md`, CC BY-NC-SA 3.0, +non-commercial) is **not** part of the installer: the program offers to download +it, shows its licence and asks for consent first. Licences of all third-party +components are listed in [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md). + +See [LICENSE](./LICENSE) for the full text. --- diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 24950d6..a451d9a 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -26,3 +26,33 @@ Wikidata (items that have an article on the Italian Wikipedia). - The lists are small (a few hundred given names and about one thousand surnames) and are only used to *confirm* a name; a name missing from them never causes a hit to be rejected. + +## Licence of NullifyPDF and of the bundled components + +NullifyPDF is distributed under the GNU Affero General Public License v3.0 or +later (see `LICENSE`). Source code: https://github.com/overwrite00/NullifyPDF. +The information below was checked on 2026-11-11 against the package metadata of +the pinned versions in `requirements.txt` and the publishers' pages. + +| Component | Licence | Notes | +|---|---|---| +| PyMuPDF / MuPDF (Artifex) | AGPL-3.0 or Artifex commercial | NullifyPDF uses it under the AGPL-3.0, hence its own licence. | +| PySide6 / Qt for Python | LGPL-3.0 (or GPL-3.0, commercial) | Used under the LGPL-3.0. Qt libraries are shipped unmodified; the full source and the build scripts of NullifyPDF are public, so anyone can rebuild the program against a different Qt. | +| presidio-analyzer | MIT | | +| spaCy, thinc | MIT | | +| spaCy `en_core_web_md` 3.8.0 | MIT | Trained on OntoNotes 5, which the publisher (Explosion) declares as commercially licensed. | +| spaCy `it_core_news_md` 3.8.0 | CC BY-NC-SA 3.0 | **Not bundled.** Downloaded by the user on request after showing the licence (non-commercial, attribution, share-alike). Sources: UD Italian ISDT (CC BY-NC-SA 3.0), WikiNER (CC BY 4.0), fastText vectors (CC0). Publisher: Explosion, https://github.com/explosion/spacy-models | +| onnxruntime | MIT | | +| tokenizers | Apache-2.0 | | +| cryptography | Apache-2.0 or BSD-3-Clause | | +| keyring (Linux/macOS) | MIT | | +| tldextract, numpy | BSD-3-Clause | | +| Tesseract OCR and `tessdata_fast` (`eng`, `ita`) | Apache-2.0 | As stated by the Tesseract project. | +| PyInstaller (build tool, not distributed) | GPL-2.0 with the bootloader exception | The exception allows distributing the produced program under any licence. | +| `pymupdf4llm`, `pymupdf-layout` | not declared | Pulled in by PyMuPDF 2.1 but not used and **excluded** from the installer. | + +Local PII models downloaded by the user from Hugging Face are accepted only if +their licence is permissive (MIT, Apache-2.0 or BSD); the licence is part of the +pinned manifest and is shown before the download. + +This table is not legal advice. diff --git a/build_local.py b/build_local.py index 1ff6150..465b9b0 100644 --- a/build_local.py +++ b/build_local.py @@ -207,7 +207,7 @@ def build_rpm( Version: {version} Release: {rpm_release(prerelease)} Summary: PDF Anonymization Tool -License: MIT +License: AGPL-3.0-or-later URL: https://github.com/overwrite00/NullifyPDF BuildArch: x86_64 {requires} @@ -398,11 +398,11 @@ def build_app() -> None: datas = {datas_literal} binaries = [] hiddenimports = ['spacy', 'presidio_analyzer', 'lexicon_data_it', 'onnxruntime', 'tokenizers'] -for pkg in ['presidio_analyzer', 'spacy', 'tldextract', 'en_core_web_md', 'it_core_news_md', 'onnxruntime', 'tokenizers'] + (['keyring'] if sys.platform != 'win32' else []): +for pkg in ['presidio_analyzer', 'spacy', 'tldextract', 'en_core_web_md', 'onnxruntime', 'tokenizers'] + (['keyring'] if sys.platform != 'win32' else []): t = collect_all(pkg) datas += t[0]; binaries += t[1]; hiddenimports += t[2] -a = Analysis(['NullifyPDF.py'], datas=datas, hiddenimports=hiddenimports) +a = Analysis(['NullifyPDF.py'], datas=datas, hiddenimports=hiddenimports, excludes=['it_core_news_md', 'pymupdf4llm', 'pymupdf_layout', 'pymupdf.layout']) pyz = PYZ(a.pure) exe = EXE(pyz, a.scripts, [], exclude_binaries=True, name='NullifyPDF', debug=False, console=False, icon={icon_str}) coll = COLLECT(exe, a.binaries, a.datas, strip=False, upx=True, upx_exclude=[], name='NullifyPDF') @@ -415,11 +415,11 @@ def build_app() -> None: datas = {datas_literal} binaries = [] hiddenimports = ['spacy', 'presidio_analyzer', 'lexicon_data_it', 'onnxruntime', 'tokenizers'] -for pkg in ['presidio_analyzer', 'spacy', 'tldextract', 'en_core_web_md', 'it_core_news_md', 'onnxruntime', 'tokenizers'] + (['keyring'] if sys.platform != 'win32' else []): +for pkg in ['presidio_analyzer', 'spacy', 'tldextract', 'en_core_web_md', 'onnxruntime', 'tokenizers'] + (['keyring'] if sys.platform != 'win32' else []): t = collect_all(pkg) datas += t[0]; binaries += t[1]; hiddenimports += t[2] -a = Analysis(['NullifyPDF.py'], datas=datas, hiddenimports=hiddenimports) +a = Analysis(['NullifyPDF.py'], datas=datas, hiddenimports=hiddenimports, excludes=['it_core_news_md', 'pymupdf4llm', 'pymupdf_layout', 'pymupdf.layout']) pyz = PYZ(a.pure) exe = EXE(pyz, a.scripts, a.binaries, a.datas, name='NullifyPDF', debug=False, console=False, icon={icon_str}) """ diff --git a/requirements.txt b/requirements.txt index a779a6e..1ed3599 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,9 @@ keyring==25.7.0; sys_platform != "win32" # (spaCy 3.8.x <-> models 3.8.x). The models declare spacy>=3.8.0,<3.9.0. # These are cached by pip in GitHub Actions, significantly speeding up CI/CD en-core-web-md @ https://github.com/explosion/spacy-models/releases/download/en_core_web_md-3.8.0/en_core_web_md-3.8.0-py3-none-any.whl +# Development and CI only (tests of the Italian detectors). Licence CC BY-NC-SA 3.0: +# NOT bundled in the installer (excluded in the PyInstaller spec); the app +# downloads it on demand after the user accepts the licence (spacy_models.py). it-core-news-md @ https://github.com/explosion/spacy-models/releases/download/it_core_news_md-3.8.0/it_core_news_md-3.8.0-py3-none-any.whl # Build Tool (compatible with Python 3.13) diff --git a/spacy_models.py b/spacy_models.py new file mode 100644 index 0000000..676eb42 --- /dev/null +++ b/spacy_models.py @@ -0,0 +1,193 @@ +"""Optional spaCy pipelines that are downloaded on demand instead of bundled. + +The Italian pipeline ``it_core_news_md`` is published under CC BY-NC-SA 3.0 +(non-commercial, share-alike). NullifyPDF is AGPL-3.0, whose recipients may use +the program commercially, so that pipeline cannot be part of the installer. +It is downloaded only after the user has seen the licence and agreed, from the +publisher's release page, verified against a pinned size and SHA-256 and kept +in the user's configuration folder. Detection quality is the same as when it +was bundled. + +When the user declines, a blank Italian pipeline (MIT, part of spaCy itself) is +used so the rule-based detectors keep working; only the statistical name +recogniser is missing and the caller must say so. +""" + +from __future__ import annotations + +import hashlib +import os +import pathlib +import shutil +import tempfile +import urllib.request +import zipfile +from dataclasses import dataclass +from typing import Callable, Optional + +ITALIAN_PACKAGE = "it_core_news_md" +ITALIAN_VERSION = "3.8.0" +ITALIAN_URL = ( + "https://github.com/explosion/spacy-models/releases/download/" + f"{ITALIAN_PACKAGE}-{ITALIAN_VERSION}/{ITALIAN_PACKAGE}-{ITALIAN_VERSION}-py3-none-any.whl" +) +ITALIAN_SHA256 = "a731d2d8e7c5a7093ac42f88774ea2a2ad3d5809959eedee65632b3533f804ec" +ITALIAN_SIZE = 42389964 +ITALIAN_LICENSE = "CC BY-NC-SA 3.0" +ITALIAN_LICENSE_URL = "https://creativecommons.org/licenses/by-nc-sa/3.0/" +_MAX_UNPACKED = 120 * 1024 * 1024 +_PIPELINE_DIR = f"{ITALIAN_PACKAGE}/{ITALIAN_PACKAGE}-{ITALIAN_VERSION}/" + +ProgressFn = Callable[[int, int], None] + + +class ModelDownloadError(RuntimeError): + """The pipeline could not be downloaded or failed verification.""" + + +@dataclass(frozen=True) +class ResolvedModel: + name: str # what Presidio/spaCy should load: package name or folder path + statistical: bool # False for the blank fallback (no name recogniser) + + +def models_root(config_dir: pathlib.Path) -> pathlib.Path: + return pathlib.Path(config_dir) / "spacy_models" + + +def _installed_dir(root: pathlib.Path) -> pathlib.Path: + return root / f"{ITALIAN_PACKAGE}-{ITALIAN_VERSION}" + + +def italian_installed(root: pathlib.Path) -> bool: + d = _installed_dir(root) + return (d / "meta.json").is_file() and (d / "ner").is_dir() + + +def _is_package() -> bool: + import spacy + + return bool(spacy.util.is_package(ITALIAN_PACKAGE)) + + +def resolve_italian(root: pathlib.Path) -> Optional[ResolvedModel]: + """The Italian statistical pipeline if it is available locally, else None.""" + if _is_package(): # development checkouts and tests + return ResolvedModel(ITALIAN_PACKAGE, True) + if italian_installed(root): + return ResolvedModel(str(_installed_dir(root)), True) + return None + + +def blank_italian(root: pathlib.Path) -> ResolvedModel: + """Rules-only fallback: tokenizer and sentence splitter, no NER.""" + import spacy + + path = root / "blank_it" + if not (path / "meta.json").is_file(): + root.mkdir(parents=True, exist_ok=True) + nlp = spacy.blank("it") + nlp.add_pipe("sentencizer") + nlp.to_disk(path) + return ResolvedModel(str(path), False) + + +def _extract(wheel: pathlib.Path, target: pathlib.Path) -> None: + """Unpack only the pipeline folder; reject any path that escapes.""" + total = 0 + base = target.resolve() + with zipfile.ZipFile(wheel) as zf: + for info in zf.infolist(): + if not info.filename.startswith(_PIPELINE_DIR) or info.is_dir(): + continue + rel = pathlib.PurePosixPath(info.filename[len(_PIPELINE_DIR):]) + if rel.is_absolute() or ".." in rel.parts: + raise ModelDownloadError("percorso non sicuro nel pacchetto") + total += info.file_size + if total > _MAX_UNPACKED: + raise ModelDownloadError("pacchetto troppo grande") + dest = (base / pathlib.Path(*rel.parts)).resolve() + if base not in dest.parents: + raise ModelDownloadError("percorso non sicuro nel pacchetto") + dest.parent.mkdir(parents=True, exist_ok=True) + with zf.open(info) as src, open(dest, "wb") as out: + shutil.copyfileobj(src, out) + + +def install_italian( + root: pathlib.Path, + progress: Optional[ProgressFn] = None, + url: str = ITALIAN_URL, + sha256: str = ITALIAN_SHA256, + size: int = ITALIAN_SIZE, + timeout: float = 30.0, +) -> pathlib.Path: + """Download, verify and unpack the pipeline. Returns its folder.""" + if not url.lower().startswith("https://"): + raise ModelDownloadError("sono consentiti solo download HTTPS") + root.mkdir(parents=True, exist_ok=True) + fd, tmp_name = tempfile.mkstemp(suffix=".whl", dir=root) + os.close(fd) + tmp = pathlib.Path(tmp_name) + staging = pathlib.Path(tempfile.mkdtemp(prefix="unpack-", dir=root)) + try: + digest = hashlib.sha256() + done = 0 + try: + with urllib.request.urlopen(url, timeout=timeout) as resp, tmp.open("wb") as out: + while True: + chunk = resp.read(1024 * 256) + if not chunk: + break + done += len(chunk) + if done > size: + raise ModelDownloadError("il file scaricato è più grande del previsto") + digest.update(chunk) + out.write(chunk) + if progress: + progress(done, size) + except OSError as exc: + raise ModelDownloadError(f"download non riuscito: {exc}") from exc + if done != size or digest.hexdigest() != sha256: + raise ModelDownloadError("verifica di integrità fallita (dimensione o SHA-256)") + _extract(tmp, staging) + if not ((staging / "meta.json").is_file() and (staging / "ner").is_dir()): + raise ModelDownloadError("pacchetto incompleto") + final = _installed_dir(root) + if final.exists(): + shutil.rmtree(final) + os.replace(staging, final) + return final + finally: + tmp.unlink(missing_ok=True) + shutil.rmtree(staging, ignore_errors=True) + + +def remove_italian(root: pathlib.Path) -> None: + shutil.rmtree(_installed_dir(root), ignore_errors=True) + + +def licence_text() -> str: + return ( + "Il riconoscimento statistico dei nomi in italiano usa la pipeline spaCy " + f"«{ITALIAN_PACKAGE}» {ITALIAN_VERSION} (Explosion), distribuita con licenza " + f"{ITALIAN_LICENSE} ({ITALIAN_LICENSE_URL}): uso non commerciale, con " + "attribuzione e condivisione alle stesse condizioni. Non è inclusa " + "nell'installer perché NullifyPDF è AGPL-3.0 e consente l'uso commerciale.\n\n" + f"Verrà scaricata da GitHub ({ITALIAN_SIZE // (1024 * 1024)} MB), " + "verificata con SHA-256 e salvata solo sul tuo computer. " + "Accettando dichiari di usarla nel rispetto di quella licenza." + ) + + +__all__ = [ + "ModelDownloadError", + "ResolvedModel", + "blank_italian", + "install_italian", + "italian_installed", + "licence_text", + "models_root", + "remove_italian", + "resolve_italian", +] diff --git a/tests/test_gui_flow.py b/tests/test_gui_flow.py index b8c56ca..cb4898d 100644 --- a/tests/test_gui_flow.py +++ b/tests/test_gui_flow.py @@ -919,3 +919,43 @@ def spy(*a, **k): monkeypatch.setattr(app, "export_document", spy) w.cmd_export() assert seen["r"].surviving_glyphs == 0 and seen["r"].verification.ok + + +def test_italian_model_prompt_offers_consent_and_fallback(window, monkeypatch): + """Without the pipeline the window asks; declining keeps a rules-only scan.""" + import spacy_models + + monkeypatch.setattr(spacy_models, "_is_package", lambda: False) + w = window + root = spacy_models.models_root(w.config_dir) + + class FakeBox: + choice = "cancel" + + def __init__(self, *a, **k): + self.buttons = {} + + def __getattr__(self, name): + return lambda *a, **k: None + + def addButton(self, text, role): + self.buttons[text] = object() + return self.buttons[text] + + def exec(self): + return 0 + + def clickedButton(self): + return self.buttons.get(FakeBox.choice) + + for attr in ("Icon", "ButtonRole"): + setattr(FakeBox, attr, getattr(QMessageBox, attr)) + monkeypatch.setattr(app, "QMessageBox", FakeBox) + + FakeBox.choice = "Annulla" + assert w._prepare_italian_model() is False + + FakeBox.choice = "Continua senza modello" + assert w._prepare_italian_model() is True + assert w.ai_worker.italian_model.endswith("blank_it") + assert (root / "blank_it" / "meta.json").is_file() diff --git a/tests/test_licences.py b/tests/test_licences.py new file mode 100644 index 0000000..27968b8 --- /dev/null +++ b/tests/test_licences.py @@ -0,0 +1,48 @@ +"""Licence consistency: AGPL project, no non-commercial model in the installer.""" + +import pathlib +import re + +ROOT = pathlib.Path(__file__).resolve().parent.parent + + +def _read(name: str) -> str: + return (ROOT / name).read_text(encoding="utf8") + + +def test_license_file_is_agpl(): + text = _read("LICENSE") + assert "GNU AFFERO GENERAL PUBLIC LICENSE" in text and "Version 3, 19 November 2007" in text + assert "AGPL-3.0-or-later" in text + + +def test_installer_never_bundles_the_non_commercial_pipeline(): + src = _read("build_local.py") + for line in src.splitlines(): + if "collect_all" in line or line.startswith("for pkg in"): + assert "it_core_news_md" not in line + assert src.count("excludes=['it_core_news_md'") >= 2 + assert "pymupdf4llm" in src + + +def test_docs_state_the_licence(): + assert "AGPL" in _read("README.md") + notices = _read("THIRD_PARTY_NOTICES.md") + for name in ("PyMuPDF", "PySide6", "it_core_news_md", "Tesseract"): + assert name in notices + assert re.search(r"AGPL-3\.0-or-later", _read("build_local.py")) + + +def test_no_declared_non_commercial_dependency_is_bundled(): + """Every installed distribution that declares a non-commercial licence must + be on the (empty-by-default) list of components kept out of the installer.""" + from importlib import metadata + + kept_out = {"it-core-news-md", "it_core_news_md"} + offenders = [] + for dist in metadata.distributions(): + name = (dist.metadata["Name"] or "").lower().replace("_", "-") + lic = " ".join(filter(None, [dist.metadata.get("License"), dist.metadata.get("License-Expression")])) + if re.search(r"\bNC\b|non-?commercial", lic, re.I) and name not in kept_out: + offenders.append((name, lic)) + assert not offenders, offenders diff --git a/tests/test_spacy_models.py b/tests/test_spacy_models.py new file mode 100644 index 0000000..f323266 --- /dev/null +++ b/tests/test_spacy_models.py @@ -0,0 +1,94 @@ +"""Optional Italian pipeline: verified download, safe unpacking, fallback.""" + +import hashlib +import io +import pathlib +import zipfile + +import pytest + +import spacy_models as sm + + +def _wheel(path: pathlib.Path, names) -> bytes: + buf = io.BytesIO() + with zipfile.ZipFile(buf, "w") as zf: + for name in names: + zf.writestr(name, b"x") + data = buf.getvalue() + path.write_bytes(data) + return data + + +def _serve(monkeypatch, data: bytes): + monkeypatch.setattr(sm.urllib.request, "urlopen", lambda url, timeout=0: io.BytesIO(data)) + + +def test_rejects_non_https(tmp_path): + with pytest.raises(sm.ModelDownloadError): + sm.install_italian(tmp_path, url="http://example.com/x.whl") + + +def test_rejects_wrong_hash_and_leaves_nothing(tmp_path, monkeypatch): + data = _wheel(tmp_path / "w.whl", []) + _serve(monkeypatch, data) + root = tmp_path / "root" + with pytest.raises(sm.ModelDownloadError): + sm.install_italian(root, url="https://example.com/x.whl", sha256="0" * 64, size=len(data)) + assert not sm.italian_installed(root) + assert not list(root.glob("*.whl")) + + +def test_rejects_oversized_download(tmp_path, monkeypatch): + _serve(monkeypatch, b"a" * 100) + with pytest.raises(sm.ModelDownloadError): + sm.install_italian(tmp_path / "r", url="https://e.com/x", sha256="0" * 64, size=10) + + +def test_rejects_path_traversal(tmp_path, monkeypatch): + p = sm._PIPELINE_DIR + data = _wheel(tmp_path / "w.whl", [p + "../../evil.txt"]) + _serve(monkeypatch, data) + with pytest.raises(sm.ModelDownloadError): + sm.install_italian( + tmp_path / "r", url="https://e.com/x", + sha256=hashlib.sha256(data).hexdigest(), size=len(data), + ) + assert not (tmp_path / "evil.txt").exists() + + +def test_installs_valid_package(tmp_path, monkeypatch): + p = sm._PIPELINE_DIR + data = _wheel(tmp_path / "w.whl", [p + "meta.json", p + "ner/cfg", "other/ignored.txt"]) + _serve(monkeypatch, data) + root = tmp_path / "r" + seen = [] + folder = sm.install_italian( + root, progress=lambda d, t: seen.append((d, t)), url="https://e.com/x", + sha256=hashlib.sha256(data).hexdigest(), size=len(data), + ) + assert sm.italian_installed(root) and (folder / "ner" / "cfg").is_file() + assert not (folder / "ignored.txt").exists() and seen + sm.remove_italian(root) + assert not sm.italian_installed(root) + + +def test_blank_fallback_is_not_statistical(tmp_path): + blank = sm.blank_italian(tmp_path) + assert blank.statistical is False and (pathlib.Path(blank.name) / "meta.json").is_file() + + +def test_resolve_prefers_installed_package_then_folder(tmp_path, monkeypatch): + monkeypatch.setattr(sm, "_is_package", lambda: False) + assert sm.resolve_italian(tmp_path) is None + d = tmp_path / f"{sm.ITALIAN_PACKAGE}-{sm.ITALIAN_VERSION}" + (d / "ner").mkdir(parents=True) + (d / "meta.json").write_text("{}") + assert sm.resolve_italian(tmp_path).name == str(d) + monkeypatch.setattr(sm, "_is_package", lambda: True) + assert sm.resolve_italian(tmp_path).name == sm.ITALIAN_PACKAGE + + +def test_licence_text_names_licence_and_source(): + t = sm.licence_text() + assert "CC BY-NC-SA 3.0" in t and "SHA-256" in t From 7da1aad5b5960c7131d2d26e965eaecbd8ee8422 Mon Sep 17 00:00:00 2001 From: 0verwrite <31691645+overwrite00@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:12:26 +0100 Subject: [PATCH 2/5] feat: licence notice with official links in the Info window and README --- .github/workflows/beta-release.yml | 2 +- .github/workflows/build-linux.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/test_build.yml | 2 +- CHANGELOG.md | 1 + NullifyPDF.py | 15 ++++- README.md | 22 +++++++ licences_info.py | 99 ++++++++++++++++++++++++++++++ tests/test_gui_flow.py | 19 ++++++ tests/test_licences.py | 16 +++++ 10 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 licences_info.py diff --git a/.github/workflows/beta-release.yml b/.github/workflows/beta-release.yml index a298ec9..8ca5ce9 100644 --- a/.github/workflows/beta-release.yml +++ b/.github/workflows/beta-release.yml @@ -50,7 +50,7 @@ jobs: - name: Type Check (mypy) shell: bash - run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py + run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py licences_info.py - name: Resolve beta suffix from tag if: startsWith(github.ref, 'refs/tags/') diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 419375b..73518c3 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -82,7 +82,7 @@ jobs: run: pytest tests/ -v - name: Type check (mypy) - run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py + run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py licences_info.py - name: Resolve beta suffix from tag if: inputs.is_beta && startsWith(github.ref, 'refs/tags/') diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 22c0545..a9a6ed9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -95,7 +95,7 @@ jobs: - name: Type Check (mypy) shell: bash - run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py + run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py licences_info.py - name: Build run: python build_local.py diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml index 0de9e1d..11c372e 100644 --- a/.github/workflows/test_build.yml +++ b/.github/workflows/test_build.yml @@ -55,7 +55,7 @@ jobs: - name: Type Check (mypy) shell: bash - run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py + run: mypy NullifyPDF.py pii_detection.py privacy_core.py update_check.py PDF_Checker.py export_engine.py pdf_sanitize.py review_dialog.py lexicon_it.py secure_store.py word_lists.py dictionary_dialog.py help_guide.py spacy_models.py licences_info.py - name: Build run: python build_local.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bf344f..9a45ae5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 🔄 Changed - **New licence: AGPL-3.0-or-later** (previously MIT), because the program uses PyMuPDF, which is AGPL-3.0 or commercial. The program stays free and is not sold. Full third-party licence list in `THIRD_PARTY_NOTICES.md`. +- **Licence notice in the Info window and README**: the Info window now lists the licence of NullifyPDF and of every component and model it uses, with clickable links to the official texts. - **Italian name-recognition model downloaded on demand**: its licence (CC BY-NC-SA 3.0, non-commercial) cannot be bundled in an AGPL installer, so the first Italian scan shows the licence and asks for consent, then downloads and verifies the model (SHA-256). Detection quality is unchanged once installed; if you decline, the scan continues with rules and dictionaries only and the log says so. ### ✨ Added diff --git a/NullifyPDF.py b/NullifyPDF.py index 5759006..1f0b60f 100644 --- a/NullifyPDF.py +++ b/NullifyPDF.py @@ -101,6 +101,7 @@ save_enabled_groups, whole_word_rects, ) +import licences_info import spacy_models import update_check from export_engine import ( @@ -2112,7 +2113,7 @@ def cmd_about(self) -> None: """Show about dialog.""" d = QDialog(self) d.setWindowTitle("Info") - d.setFixedSize(340, 560) + d.setFixedSize(520, 820) lay = QVBoxLayout(d) lay.setAlignment(Qt.AlignmentFlag.AlignCenter) ip = resource_path(os.path.join("images", "NullifyPDF_icon.png")) @@ -2146,7 +2147,17 @@ def cmd_about(self) -> None: lbl_repo.setOpenExternalLinks(True) lbl_repo.setAlignment(Qt.AlignmentFlag.AlignCenter) lay.addWidget(lbl_repo) - lay.addSpacing(10) + lay.addSpacing(6) + lic_view = QTextBrowser() + lic_view.setObjectName("about_licences") + lic_view.setOpenExternalLinks(True) + lic_view.setHtml(licences_info.about_html()) + lic_view.setMinimumHeight(200) + lic_view.setToolTip( + "Licenza del programma e dei componenti usati, con i collegamenti ai testi ufficiali." + ) + lay.addWidget(lic_view, 1) + lay.addSpacing(6) btn_upd = QPushButton("Controlla aggiornamenti") lay.addWidget(btn_upd) chk_auto = QCheckBox("Controlla ad ogni avvio") diff --git a/README.md b/README.md index 2fc9fb6..4e7ea6d 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,28 @@ non-commercial) is **not** part of the installer: the program offers to download it, shows its licence and asks for consent first. Licences of all third-party components are listed in [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md). +**Notice.** NullifyPDF is free software, distributed under the AGPL-3.0-or-later. Every component and model it uses remains under its own licence, listed below with a link to the official text; using the program means respecting those conditions. The Italian spaCy model is for non-commercial use only and is downloaded only after your consent. + +| Component | Licence | Used for | +|---|---|---| +| [NullifyPDF](https://github.com/overwrite00/NullifyPDF/blob/main/LICENSE) | AGPL-3.0-or-later | this program | +| [PyMuPDF / MuPDF](https://pymupdf.readthedocs.io/en/latest/about.html) | AGPL-3.0 or commercial (Artifex) | PDF reading and redaction | +| [PySide6 / Qt](https://opensource.org/license/lgpl-3-0) | LGPL-3.0 | graphical interface | +| [Presidio](https://github.com/microsoft/presidio/blob/main/LICENSE) | MIT | personal-data detection | +| [spaCy](https://github.com/explosion/spaCy/blob/master/LICENSE) | MIT | language processing | +| [spaCy en_core_web_md](https://github.com/explosion/spacy-models/releases/tag/en_core_web_md-3.8.0) | MIT | English model | +| [spaCy it_core_news_md](https://creativecommons.org/licenses/by-nc-sa/3.0/) | CC BY-NC-SA 3.0 (non-commercial use only) | Italian model, downloaded after consent | +| [onnxruntime](https://github.com/microsoft/onnxruntime/blob/main/LICENSE) | MIT | running local models | +| [tokenizers](https://github.com/huggingface/tokenizers/blob/main/LICENSE) | Apache-2.0 | tokenizing for local models | +| [cryptography](https://github.com/pyca/cryptography/blob/main/LICENSE) | Apache-2.0 or BSD-3-Clause | encryption | +| [keyring](https://github.com/jaraco/keyring) | MIT | key storage (Linux/macOS) | +| [tldextract](https://github.com/john-kurkowski/tldextract/blob/master/LICENSE) | BSD-3-Clause | URL recognition | +| [NumPy](https://github.com/numpy/numpy/blob/main/LICENSE.txt) | BSD-3-Clause | numerical computing | +| [Tesseract OCR](https://github.com/tesseract-ocr/tesseract/blob/main/LICENSE) | Apache-2.0 | OCR of scanned documents | +| [tessdata_fast (eng, ita)](https://github.com/tesseract-ocr/tessdata_fast/blob/main/LICENSE) | Apache-2.0 | OCR language data | +| [ISTAT, elenco dei comuni](https://creativecommons.org/licenses/by/4.0/) | CC BY 4.0 | place names | +| [Wikidata](https://creativecommons.org/publicdomain/zero/1.0/) | CC0 1.0 | given names and surnames | + See [LICENSE](./LICENSE) for the full text. --- diff --git a/licences_info.py b/licences_info.py new file mode 100644 index 0000000..b67cd09 --- /dev/null +++ b/licences_info.py @@ -0,0 +1,99 @@ +"""Licences of NullifyPDF and of the components it uses, with official links. + +Single source for the "Info" window and for the README table (a test keeps the +README in step). Informational only: each component remains under its own +licence, which is what the notice says. +""" + +from __future__ import annotations + +import html +from typing import List, NamedTuple + +REPO = "https://github.com/overwrite00/NullifyPDF" +AGPL_URL = "https://opensource.org/license/agpl-v3" +LGPL_URL = "https://opensource.org/license/lgpl-3-0" +CC_NC_SA_URL = "https://creativecommons.org/licenses/by-nc-sa/3.0/" + +APP_LICENCE = "AGPL-3.0-or-later" +NOTICE = ( + "NullifyPDF è software libero e gratuito, distribuito con licenza " + f"{APP_LICENCE}. Ogni componente e ogni modello usati dal programma restano " + "soggetti alla propria licenza, indicata qui sotto con il collegamento al testo " + "ufficiale: usando il programma se ne rispettano le condizioni. Il modello " + "italiano di spaCy è per solo uso non commerciale e viene scaricato solo dopo " + "il tuo consenso." +) + + +class Component(NamedTuple): + name: str + licence: str + url: str # official page or licence text + role: str + role_en: str = "" + licence_en: str = "" + + +COMPONENTS: List[Component] = [ + Component("NullifyPDF", APP_LICENCE, f"{REPO}/blob/main/LICENSE", "questo programma", "this program"), + Component("PyMuPDF / MuPDF", "AGPL-3.0 o commerciale (Artifex)", + "https://pymupdf.readthedocs.io/en/latest/about.html", "lettura e redazione dei PDF", "PDF reading and redaction", + "AGPL-3.0 or commercial (Artifex)"), + Component("PySide6 / Qt", "LGPL-3.0", LGPL_URL, "interfaccia grafica", "graphical interface"), + Component("Presidio", "MIT", "https://github.com/microsoft/presidio/blob/main/LICENSE", + "riconoscimento dei dati personali", "personal-data detection"), + Component("spaCy", "MIT", "https://github.com/explosion/spaCy/blob/master/LICENSE", + "elaborazione del linguaggio", "language processing"), + Component("spaCy en_core_web_md", "MIT", + "https://github.com/explosion/spacy-models/releases/tag/en_core_web_md-3.8.0", + "modello inglese", "English model"), + Component("spaCy it_core_news_md", "CC BY-NC-SA 3.0 (solo uso non commerciale)", CC_NC_SA_URL, + "modello italiano, scaricato dopo il consenso", "Italian model, downloaded after consent", + "CC BY-NC-SA 3.0 (non-commercial use only)"), + Component("onnxruntime", "MIT", "https://github.com/microsoft/onnxruntime/blob/main/LICENSE", + "esecuzione dei modelli locali", "running local models"), + Component("tokenizers", "Apache-2.0", "https://github.com/huggingface/tokenizers/blob/main/LICENSE", + "tokenizzazione dei modelli locali", "tokenizing for local models"), + Component("cryptography", "Apache-2.0 o BSD-3-Clause", + "https://github.com/pyca/cryptography/blob/main/LICENSE", "cifratura", "encryption", + "Apache-2.0 or BSD-3-Clause"), + Component("keyring", "MIT", "https://github.com/jaraco/keyring", "archivio chiavi (Linux/macOS)", "key storage (Linux/macOS)"), + Component("tldextract", "BSD-3-Clause", + "https://github.com/john-kurkowski/tldextract/blob/master/LICENSE", "riconoscimento URL", "URL recognition"), + Component("NumPy", "BSD-3-Clause", "https://github.com/numpy/numpy/blob/main/LICENSE.txt", + "calcolo numerico", "numerical computing"), + Component("Tesseract OCR", "Apache-2.0", "https://github.com/tesseract-ocr/tesseract/blob/main/LICENSE", + "OCR dei documenti scansionati", "OCR of scanned documents"), + Component("tessdata_fast (eng, ita)", "Apache-2.0", + "https://github.com/tesseract-ocr/tessdata_fast/blob/main/LICENSE", "dati OCR", "OCR language data"), + Component("ISTAT, elenco dei comuni", "CC BY 4.0", "https://creativecommons.org/licenses/by/4.0/", + "nomi dei luoghi", "place names"), + Component("Wikidata", "CC0 1.0", "https://creativecommons.org/publicdomain/zero/1.0/", + "nomi e cognomi", "given names and surnames"), +] + +EXTRA_LINKS = [ + ("LICENSE", f"{REPO}/blob/main/LICENSE"), + ("THIRD_PARTY_NOTICES", f"{REPO}/blob/main/THIRD_PARTY_NOTICES.md"), +] + + +def about_html() -> str: + """HTML for the scrollable licence area of the Info window.""" + rows = "".join( + f"
  • {html.escape(c.name)}" + f" — {html.escape(c.licence)} ({html.escape(c.role)})
  • " + for c in COMPONENTS + ) + extra = " · ".join( + f"{html.escape(n)}" for n, u in EXTRA_LINKS + ) + return f"

    {html.escape(NOTICE)}

      {rows}

    {extra}

    " + + +def readme_markdown() -> str: + lines = ["| Component | Licence | Used for |", "|---|---|---|"] + for c in COMPONENTS: + lines.append(f"| [{c.name}]({c.url}) | {c.licence_en or c.licence} | {c.role_en} |") + return "\n".join(lines) diff --git a/tests/test_gui_flow.py b/tests/test_gui_flow.py index cb4898d..c8d6ebd 100644 --- a/tests/test_gui_flow.py +++ b/tests/test_gui_flow.py @@ -959,3 +959,22 @@ def clickedButton(self): assert w._prepare_italian_model() is True assert w.ai_worker.italian_model.endswith("blank_it") assert (root / "blank_it" / "meta.json").is_file() + + +def test_about_dialog_shows_licence_notice_with_links(window, monkeypatch): + from PySide6.QtWidgets import QTextBrowser + + import licences_info + + seen = {} + + def fake_exec(self): + view = self.findChild(QTextBrowser, "about_licences") + seen["html"] = view.toHtml() + seen["links"] = view.toPlainText() + return 0 + + monkeypatch.setattr(app.QDialog, "exec", fake_exec) + window.cmd_about() + assert "AGPL-3.0-or-later" in seen["links"] and "PyMuPDF" in seen["links"] + assert all(c.url in seen["html"] for c in licences_info.COMPONENTS) diff --git a/tests/test_licences.py b/tests/test_licences.py index 27968b8..2cea023 100644 --- a/tests/test_licences.py +++ b/tests/test_licences.py @@ -46,3 +46,19 @@ def test_no_declared_non_commercial_dependency_is_bundled(): if re.search(r"\bNC\b|non-?commercial", lic, re.I) and name not in kept_out: offenders.append((name, lic)) assert not offenders, offenders + + +def test_component_list_is_https_complete_and_in_readme(): + import licences_info as li + + readme = _read("README.md") + names = {c.name for c in li.COMPONENTS} + assert {"PyMuPDF / MuPDF", "PySide6 / Qt", "spaCy it_core_news_md", "Tesseract OCR"} <= names + for c in li.COMPONENTS: + assert c.url.startswith("https://"), c + assert c.url in readme, c.name + assert c.role_en, c.name + assert li.readme_markdown() in readme + html_text = li.about_html() + assert all(c.url in html_text for c in li.COMPONENTS) + assert "non commerciale" in li.NOTICE From 5b5bf071025dd51e6a7e02be0a16940e7d9e3597 Mon Sep 17 00:00:00 2001 From: 0verwrite <31691645+overwrite00@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:21:47 +0100 Subject: [PATCH 3/5] fix: show model download progress inside the button and download off the UI thread --- CHANGELOG.md | 1 + model_dialog.py | 160 +++++++++++++++++++++++++++---------- tests/test_model_dialog.py | 114 ++++++++++++++++++++++++++ 3 files changed, 234 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a45ae5..f87b9a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 🔄 Changed +- **Model download progress in the button**: in the local-models window the "Scarica modello" button now fills like a progress bar with the percentage, a second click cancels, the list and the Close button are locked while downloading, and the download no longer blocks the window. The empty grey button of the old progress window is gone. - **New licence: AGPL-3.0-or-later** (previously MIT), because the program uses PyMuPDF, which is AGPL-3.0 or commercial. The program stays free and is not sold. Full third-party licence list in `THIRD_PARTY_NOTICES.md`. - **Licence notice in the Info window and README**: the Info window now lists the licence of NullifyPDF and of every component and model it uses, with clickable links to the official texts. - **Italian name-recognition model downloaded on demand**: its licence (CC BY-NC-SA 3.0, non-commercial) cannot be bundled in an AGPL installer, so the first Italian scan shows the licence and asks for consent, then downloads and verifies the model (SHA-256). Detection quality is unchanged once installed; if you decline, the scan continues with rules and dictionaries only and the log says so. diff --git a/model_dialog.py b/model_dialog.py index 613eefd..72ab95a 100644 --- a/model_dialog.py +++ b/model_dialog.py @@ -4,9 +4,8 @@ from typing import Any, Iterable, Optional -from PySide6.QtCore import Qt +from PySide6.QtCore import QThread, Qt, Signal from PySide6.QtWidgets import ( - QApplication, QDialog, QDialogButtonBox, QLabel, @@ -14,7 +13,6 @@ QListWidgetItem, QMessageBox, QPushButton, - QProgressDialog, QTextBrowser, QVBoxLayout, ) @@ -23,6 +21,52 @@ from model_manager import ModelCandidate, ModelManifest, ModelStore +class ModelDownloadWorker(QThread): + """Download and verify every file of a manifest off the UI thread.""" + + progress_sig = Signal(int) # whole-model percentage + done_sig = Signal() + error_sig = Signal(str) + cancelled_sig = Signal() + + def __init__(self, store: ModelStore, manifest: ModelManifest) -> None: + super().__init__() + self._store = store + self._manifest = manifest + self._cancel = False + self._completed = 0 + self._total = max(1, manifest.total_size) + + def cancel(self) -> None: + self._cancel = True + + def _on_bytes(self, done: int, total: int) -> None: + if self._cancel: + raise InterruptedError("download annullato") + value = int(((self._completed + min(done, total)) / self._total) * 100) + self.progress_sig.emit(min(100, value)) + + def run(self) -> None: + try: + for item in self._manifest.files: + url = ( + f"https://huggingface.co/{self._manifest.repo_id}/resolve/" + f"{self._manifest.revision}/{item.name}?download=true" + ) + self._store.install_file( + self._manifest, item, url, timeout=120.0, progress=self._on_bytes + ) + self._completed += item.size + self.progress_sig.emit(min(100, int(self._completed * 100 / self._total))) + if not self._store.is_installed(self._manifest): + raise RuntimeError("verifica finale del modello fallita") + self.done_sig.emit() + except InterruptedError: + self.cancelled_sig.emit() + except Exception as exc: + self.error_sig.emit(str(exc)) + + class ModelDialog(QDialog): """Show the reviewed model shortlist and its verification state.""" @@ -68,9 +112,10 @@ def __init__( "Il download è attivo solo per modelli con revisione, file, licenza e SHA-256 verificati." ) lay.addWidget(self.btn_download) - buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Close) - buttons.rejected.connect(self.reject) - lay.addWidget(buttons) + self._buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Close) + self._buttons.rejected.connect(self.reject) + lay.addWidget(self._buttons) + self._worker: Optional[ModelDownloadWorker] = None self.list.currentItemChanged.connect(self._show_details) self.btn_download.clicked.connect(self._download_selected) if self.list.count(): @@ -122,7 +167,46 @@ def _show_details(self, current: Optional[QListWidgetItem], _previous: Any) -> N "Download HTTPS da Hugging Face alla revisione fissata nel manifest." ) + # -- download with progress shown inside the button ------------------- + def _set_button_progress(self, percent: int) -> None: + """Fill the button from the left like a progress bar and show the %.""" + p = min(max(percent, 0), 100) / 100.0 + edge = min(p, 0.998) + self.btn_download.setText(f"Download in corso… {percent}% (clic per annullare)") + self.btn_download.setStyleSheet( + "QPushButton#model_download { background: qlineargradient(" + "x1:0, y1:0, x2:1, y2:0, " + f"stop:0 #0284c7, stop:{edge:.3f} #0284c7, " + f"stop:{edge + 0.001:.3f} #334155, stop:1 #334155); }}" + ) + + def _set_downloading(self, on: bool) -> None: + self.list.setEnabled(not on) + close = self._buttons.button(QDialogButtonBox.StandardButton.Close) + if close is not None: + close.setEnabled(not on) + if not on: + self.btn_download.setStyleSheet("") + + def is_downloading(self) -> bool: + return self._worker is not None + + def reject(self) -> None: + if self._worker is None: + super().reject() + + def closeEvent(self, event: Any) -> None: + if self._worker is not None: + event.ignore() + else: + super().closeEvent(event) + def _download_selected(self) -> None: + if self._worker is not None: # second click while downloading: cancel + self._worker.cancel() + self.btn_download.setText("Annullamento…") + self.btn_download.setEnabled(False) + return current = self.list.currentItem() if current is None or self._store is None: return @@ -142,41 +226,35 @@ def _download_selected(self) -> None: ) if answer != QMessageBox.StandardButton.Yes: return - progress = QProgressDialog("Download modello...", "", 0, 100, self) - progress.setWindowTitle("Download modello") - progress.setAutoClose(False) - progress.setAutoReset(False) - progress.setMinimumDuration(0) - progress.setValue(0) - progress.show() - total_size = max(1, manifest.total_size) - completed = 0 - - def on_progress(done: int, total: int) -> None: - value = int(((completed + min(done, total)) / total_size) * 100) - progress.setValue(min(100, value)) - QApplication.processEvents() + self._set_downloading(True) + self._set_button_progress(0) + worker = ModelDownloadWorker(self._store, manifest) + # Bound methods, not lambdas capturing self (no reference cycle). + worker.progress_sig.connect(self._set_button_progress) + worker.done_sig.connect(self._on_download_done) + worker.error_sig.connect(self._on_download_error) + worker.cancelled_sig.connect(self._on_download_cancelled) + self._worker = worker + worker.start() - try: - for item in manifest.files: - url = ( - f"https://huggingface.co/{manifest.repo_id}/resolve/" - f"{manifest.revision}/{item.name}?download=true" - ) - self._store.install_file( - manifest, item, url, timeout=120.0, progress=on_progress - ) - completed += item.size - progress.setValue(min(100, int(completed * 100 / total_size))) - QApplication.processEvents() - if not self._store.is_installed(manifest): - raise RuntimeError("verifica finale del modello fallita") - except Exception as exc: - progress.close() - QMessageBox.critical(self, "Download non riuscito", str(exc)) - return - progress.setValue(100) - progress.close() + def _finish_worker(self) -> None: + worker = self._worker + self._worker = None + if worker is not None: + worker.wait() + self.btn_download.setEnabled(True) + self._set_downloading(False) + + def _on_download_done(self) -> None: + self._finish_worker() QMessageBox.information(self, "Download completato", "Il modello è stato verificato e installato.") - self._show_details(current, None) + self._show_details(self.list.currentItem(), None) + + def _on_download_error(self, message: str) -> None: + self._finish_worker() + self._show_details(self.list.currentItem(), None) + QMessageBox.critical(self, "Download non riuscito", message) + def _on_download_cancelled(self) -> None: + self._finish_worker() + self._show_details(self.list.currentItem(), None) diff --git a/tests/test_model_dialog.py b/tests/test_model_dialog.py index 4b5be9d..59e135a 100644 --- a/tests/test_model_dialog.py +++ b/tests/test_model_dialog.py @@ -16,3 +16,117 @@ def test_model_dialog_lists_only_curated_candidates(): assert dialog.details.toPlainText() dialog.close() app.processEvents() + + +# --- download progress lives inside the button -------------------------------- + +import time # noqa: E402 + +import pytest # noqa: E402 +from PySide6.QtWidgets import QMessageBox # noqa: E402 + +from model_manager import ModelFile, ModelManifest # noqa: E402 + + +def _manifest(): + return ModelManifest( + model_id="fake-model", repo_id="owner/fake", revision="a" * 40, license="MIT", + runtime="onnx", labels=("PER",), + files=(ModelFile("model.onnx", 1000, "b" * 64),), + ) + + +class FakeStore: + def __init__(self, behaviour): + self.behaviour = behaviour + self.installed = False + + def is_installed(self, manifest): + return self.installed + + def install_file(self, manifest, item, url, *, timeout=30.0, progress=None): + self.behaviour(self, progress, item) + + +def _dialog(store, qapp): + manifest = _manifest() + dlg = ModelDialog(MODEL_CANDIDATES, manifests=[manifest], store=store) + dlg._manifests = {c.model_id: manifest for c in MODEL_CANDIDATES} + dlg.list.setCurrentRow(0) + dlg.btn_download.setEnabled(True) + return dlg + + +def _wait(qapp, cond, timeout=5.0): + end = time.time() + timeout + while time.time() < end and not cond(): + qapp.processEvents() + time.sleep(0.01) + return cond() + + +@pytest.fixture() +def qapp(): + return QApplication.instance() or QApplication([]) + + +@pytest.fixture() +def boxes(monkeypatch): + seen = [] + monkeypatch.setattr(QMessageBox, "question", lambda *a, **k: QMessageBox.StandardButton.Yes) + monkeypatch.setattr(QMessageBox, "information", lambda *a, **k: seen.append("info")) + monkeypatch.setattr(QMessageBox, "critical", lambda *a, **k: seen.append(("error", a[2]))) + return seen + + +def test_download_progress_is_in_the_button_and_ui_is_locked(qapp, boxes): + gate = {"go": False} + + def slow(store, progress, item): + progress(500, item.size) + while not gate["go"]: + time.sleep(0.01) + progress(1000, item.size) + store.installed = True + + dlg = _dialog(FakeStore(slow), qapp) + dlg.btn_download.click() + assert dlg.is_downloading() + assert _wait(qapp, lambda: "50%" in dlg.btn_download.text()) + assert "qlineargradient" in dlg.btn_download.styleSheet() + assert not dlg.list.isEnabled() + dlg.reject() # closing is refused while downloading + assert dlg.is_downloading() + gate["go"] = True + assert _wait(qapp, lambda: not dlg.is_downloading()) + assert boxes == ["info"] and dlg.list.isEnabled() and dlg.btn_download.styleSheet() == "" + dlg.close() + + +def test_second_click_cancels_and_restores_button(qapp, boxes): + def endless(store, progress, item): + while True: + progress(1, item.size) # raises InterruptedError once cancelled + time.sleep(0.01) + + dlg = _dialog(FakeStore(endless), qapp) + dlg.btn_download.click() + assert _wait(qapp, lambda: dlg.is_downloading() and dlg.btn_download.text().startswith("Download")) + dlg.btn_download.click() + assert _wait(qapp, lambda: not dlg.is_downloading()) + assert boxes == [] # cancelling is silent + assert dlg.btn_download.isEnabled() and dlg.list.isEnabled() + assert dlg.btn_download.text() == "Scarica modello" + dlg.close() + + +def test_failed_download_reports_error_and_unlocks(qapp, boxes): + def broken(store, progress, item): + raise RuntimeError("hash non corrispondente") + + dlg = _dialog(FakeStore(broken), qapp) + dlg.btn_download.click() + assert _wait(qapp, lambda: not dlg.is_downloading()) + assert boxes and boxes[0][0] == "error" and "hash" in boxes[0][1] + assert dlg.list.isEnabled() and dlg.btn_download.styleSheet() == "" + dlg.close() From 2e03144fca2f84da4c64885cb67767c9ffb0a43d Mon Sep 17 00:00:00 2001 From: 0verwrite <31691645+overwrite00@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:29:17 +0100 Subject: [PATCH 4/5] feat: Italian only, remove the English model and the language selector --- ARCHITECTURE.md | 7 ++--- CHANGELOG.md | 1 + DEVELOPMENT.md | 1 - NullifyPDF.py | 58 +++++++++++++--------------------------- README.md | 3 +-- THIRD_PARTY_NOTICES.md | 1 - TROUBLESHOOTING.md | 16 +++-------- USER_GUIDE.md | 12 +++------ build_local.py | 4 +-- help_guide.py | 7 ++--- licences_info.py | 3 --- requirements.txt | 1 - setup_env.py | 3 +-- tests/test_gui_flow.py | 6 ++--- tests/test_validation.py | 10 +++---- 15 files changed, 41 insertions(+), 92 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 27ab7ca..f9e324d 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -104,7 +104,7 @@ Export pipeline writes a cleaned PDF copy ### 🤖 AI Scan 1. User clicks **Auto Redact** and, in a dialog, picks which data types to look for (names, locations, email, phone, IBAN, cards, crypto, fiscal code, VAT, licence, ID card, passport). The selection is remembered in `~/.nullifypdf/ai_entities.json`. -2. User selects language (`EN`, `IT`, or `BOTH`) and optionally enables: +2. The language is always Italian (`IT`); the user optionally enables: - `OCR PDF scansionati` - `Oscura Immagini` 3. `cmd_auto_ai()` checks OCR configuration if OCR is enabled. @@ -224,10 +224,7 @@ Runtime behavior: - bundled `ocr/tessdata` via `resource_path()` - PyMuPDF's `fitz.get_tessdata()` - common platform locations -2. `ocr_language_for_choice()` maps UI language to Tesseract codes: - - `EN` -> `eng` - - `IT` -> `ita` - - `BOTH` -> `eng+ita` +2. `ocr_language_for_choice()` returns the Tesseract codes: `ita`, plus `eng` when its data is installed (so English words inside Italian documents are read well). 3. `AIWorker._page_needs_ocr()` runs OCR only when text extraction is missing or very poor. 4. OCR text is used for Presidio detection. 5. OCR search rectangles are used to place redactions on scanned pages. diff --git a/CHANGELOG.md b/CHANGELOG.md index f87b9a1..2f9290c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 🔄 Changed +- **Italian only**: the English model and the EN/IT/BOTH selector are gone. The program analyses Italian documents; the sidebar shows "Lingua dei documenti: italiano". The English OCR data is still used, when installed, only to read English words inside Italian pages. - **Model download progress in the button**: in the local-models window the "Scarica modello" button now fills like a progress bar with the percentage, a second click cancels, the list and the Close button are locked while downloading, and the download no longer blocks the window. The empty grey button of the old progress window is gone. - **New licence: AGPL-3.0-or-later** (previously MIT), because the program uses PyMuPDF, which is AGPL-3.0 or commercial. The program stays free and is not sold. Full third-party licence list in `THIRD_PARTY_NOTICES.md`. - **Licence notice in the Info window and README**: the Info window now lists the licence of NullifyPDF and of every component and model it uses, with clickable links to the official texts. diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 2615fda..a474b1a 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -155,7 +155,6 @@ NullifyPDF/ | Model | Size | Purpose | Licence | In the installer | | ----------------- | ----- | ----------- | ------- | ---------------- | -| `en_core_web_md` | 40 MB | English NER | MIT | yes | | `it_core_news_md` | 45 MB | Italian NER | CC BY-NC-SA 3.0 | **no**, downloaded by the app on demand (`spacy_models.py`) | `setup_env.py` installs both in the development environment (the Italian tests diff --git a/NullifyPDF.py b/NullifyPDF.py index 1f0b60f..cae2dbb 100644 --- a/NullifyPDF.py +++ b/NullifyPDF.py @@ -25,7 +25,6 @@ QHBoxLayout, QLabel, QPushButton, - QRadioButton, QCheckBox, QProgressBar, QProgressDialog, @@ -36,7 +35,6 @@ QDialog, QDialogButtonBox, QLineEdit, - QButtonGroup, QGraphicsRectItem, QMessageBox, QInputDialog, @@ -55,7 +53,6 @@ QDropEvent, ) from PySide6.QtCore import ( - QLocale, Qt, QThread, QObject, @@ -866,15 +863,19 @@ def find_tessdata_dir() -> Optional[str]: def ocr_language_for_choice(choice: str, tessdata_dir: Optional[str]) -> str: - """Map the UI language choice to installed Tesseract language codes.""" - requested = ["eng", "ita"] if choice == "BOTH" else ["ita" if choice == "IT" else "eng"] + """Tesseract languages for the scan: Italian, plus English data if installed. + + The program analyses Italian documents only; the English OCR data is kept + just so that English words and Latin-script terms inside them are read + well. `choice` is kept for API stability and must be "IT". + """ if not tessdata_dir: - return "+".join(requested) + return "ita" available = [ - lang for lang in requested + lang for lang in ("ita", "eng") if (pathlib.Path(tessdata_dir) / f"{lang}.traineddata").exists() ] - return "+".join(available or requested) + return "+".join(available or ["ita"]) STYLESHEET = """ @@ -975,7 +976,7 @@ def run_scan(self, doc: Any, doc_mutex: Any, choice: str, Args: doc: PyMuPDF document (shared with UI thread, mutex-protected). doc_mutex: QMutex serializing access to `doc`. - choice: Language choice: 'EN', 'IT', or 'BOTH'. + choice: Language of the document; only 'IT' is supported. compiled_allowlist: Pre-compiled regex patterns to skip redaction. allowlist_set: Set of allowlist entries (lowercase) for O(1) exact-match fast-path lookup before regex any() scan. @@ -993,7 +994,7 @@ def run_scan(self, doc: Any, doc_mutex: Any, choice: str, self.finished_sig.emit() return - if choice not in ("EN", "IT", "BOTH"): + if choice != "IT": self.log_sig.emit(f"ERRORE: Scelta lingua non valida: {choice}") self.finished_sig.emit() return @@ -1006,7 +1007,7 @@ def run_scan(self, doc: Any, doc_mutex: Any, choice: str, if not isinstance(allowlist_set, set): allowlist_set = set() - target_langs = ["en", "it"] if choice == "BOTH" else [choice.lower()] + target_langs = ["it"] ocr_language = ocr_language_for_choice(choice, tessdata_dir) if ( not self.analyzer @@ -1018,13 +1019,7 @@ def run_scan(self, doc: Any, doc_mutex: Any, choice: str, from presidio_analyzer.nlp_engine import NlpEngineProvider from presidio_analyzer.predefined_recognizers import PhoneRecognizer - models = ( - [{"lang_code": "en", "model_name": "en_core_web_md"}] - if "en" in target_langs - else [] - ) - if "it" in target_langs: - models.append({"lang_code": "it", "model_name": self.italian_model}) + models = [{"lang_code": "it", "model_name": self.italian_model}] provider = NlpEngineProvider( nlp_configuration={"nlp_engine_name": "spacy", "models": models} ) @@ -1540,22 +1535,9 @@ def build_ui(self) -> None: btn_open.clicked.connect(self.cmd_open) s_lay.addWidget(btn_open) s_lay.addSpacing(20) - s_lay.addWidget(QLabel("Modello lingua:")) - lang_lay = QHBoxLayout() - self.rb_en = QRadioButton("EN") - self.rb_it = QRadioButton("IT") - self.rb_both = QRadioButton("BOTH") - # Default to the interface language: running the English model on - # Italian text only adds false positives. - if QLocale.system().language() == QLocale.Language.Italian: - self.rb_it.setChecked(True) - else: - self.rb_both.setChecked(True) - self.lang_grp = QButtonGroup(self) - for rb in (self.rb_en, self.rb_it, self.rb_both): - self.lang_grp.addButton(rb) - lang_lay.addWidget(rb) - s_lay.addLayout(lang_lay) + self.lbl_lang = QLabel("Lingua dei documenti: italiano") + self.lbl_lang.setObjectName("language_label") + s_lay.addWidget(self.lbl_lang) s_lay.addSpacing(10) self.chk_img = QCheckBox("Oscura Immagini") s_lay.addWidget(self.chk_img) @@ -2336,12 +2318,8 @@ def cmd_auto_ai(self) -> None: c_allow = [ (a, re.compile(r"\b" + re.escape(a) + r"\b")) for a in self.allowlist ] - lang = ( - "EN" - if self.rb_en.isChecked() - else "IT" if self.rb_it.isChecked() else "BOTH" - ) - if lang in ("IT", "BOTH") and not self._prepare_italian_model(): + lang = "IT" + if not self._prepare_italian_model(): self.btn_ai.setEnabled(True) return use_ocr = self.chk_ocr.isChecked() diff --git a/README.md b/README.md index 4e7ea6d..86aa59a 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ python setup_env.py - Detects OS (Windows/macOS/Linux) - Creates `.venv` with Python 3.13 - Installs `requirements.txt` dependencies -- Downloads spaCy models (English, Italian, both) +- Installs the Italian spaCy model for development (the installer does not bundle it) **Automatic OS detection:** - Windows: Uses `py -3.13` launcher @@ -277,7 +277,6 @@ components are listed in [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md). | [PySide6 / Qt](https://opensource.org/license/lgpl-3-0) | LGPL-3.0 | graphical interface | | [Presidio](https://github.com/microsoft/presidio/blob/main/LICENSE) | MIT | personal-data detection | | [spaCy](https://github.com/explosion/spaCy/blob/master/LICENSE) | MIT | language processing | -| [spaCy en_core_web_md](https://github.com/explosion/spacy-models/releases/tag/en_core_web_md-3.8.0) | MIT | English model | | [spaCy it_core_news_md](https://creativecommons.org/licenses/by-nc-sa/3.0/) | CC BY-NC-SA 3.0 (non-commercial use only) | Italian model, downloaded after consent | | [onnxruntime](https://github.com/microsoft/onnxruntime/blob/main/LICENSE) | MIT | running local models | | [tokenizers](https://github.com/huggingface/tokenizers/blob/main/LICENSE) | Apache-2.0 | tokenizing for local models | diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index a451d9a..3a92a62 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -40,7 +40,6 @@ the pinned versions in `requirements.txt` and the publishers' pages. | PySide6 / Qt for Python | LGPL-3.0 (or GPL-3.0, commercial) | Used under the LGPL-3.0. Qt libraries are shipped unmodified; the full source and the build scripts of NullifyPDF are public, so anyone can rebuild the program against a different Qt. | | presidio-analyzer | MIT | | | spaCy, thinc | MIT | | -| spaCy `en_core_web_md` 3.8.0 | MIT | Trained on OntoNotes 5, which the publisher (Explosion) declares as commercially licensed. | | spaCy `it_core_news_md` 3.8.0 | CC BY-NC-SA 3.0 | **Not bundled.** Downloaded by the user on request after showing the licence (non-commercial, attribution, share-alike). Sources: UD Italian ISDT (CC BY-NC-SA 3.0), WikiNER (CC BY 4.0), fastText vectors (CC0). Publisher: Explosion, https://github.com/explosion/spacy-models | | onnxruntime | MIT | | | tokenizers | Apache-2.0 | | diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index c5088c2..6102577 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -156,18 +156,9 @@ Names, emails, or other PII should be detected but aren't highlighted. ### Solution -**Check 1 — Language Selection** +**Check 1 — Language and model** -Open sidebar. Is the correct language selected? - -| Language | Best For | -| -------- | -------------------------------- | -| **EN** | English text only | -| **IT** | Italian text only | -| **BOTH** | Mixed English + Italian (slower) | - -> [!WARNING] -> Wrong language = **zero detection**. Test with a clear English name if unsure. +NullifyPDF supports Italian documents only. Names are found by the Italian model, which is downloaded after your consent on the first Auto Redact. If you declined the download, only rules and dictionaries run and names may be missed: run Auto Redact again and accept the download. **Check 2 — Is It Searchable Text?** @@ -219,7 +210,6 @@ The scan proposes plain words ("Certifico", "Prescrivo", section headings) or fr ### Solution -- Use the **IT** language model (or **BOTH**) for Italian documents; the English model adds false hits on Italian text. - Uncertain hits appear in **Rivedi suggerimenti** instead of being applied: leave them unticked to discard them. - Add words you never want redacted to the allowlist (**Dizionari**); matching is by whole word. - If black boxes cover parts of the lines above or below the redacted word, update to a build that includes rectangle trimming and re-run the scan. With very tight line spacing (roughly half the font size or less) no safe band exists: a warning "interlinea molto stretta" is shown and neighbouring words can be damaged, never left unredacted. @@ -486,5 +476,5 @@ The more details, the faster we can fix it! 🚀 --- -*Last updated: 2026-11-08* +*Last updated: 2026-11-11* *← [User Guide](./USER_GUIDE.md) | [Development →](./DEVELOPMENT.md)* diff --git a/USER_GUIDE.md b/USER_GUIDE.md index e68321e..53a1ca0 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -40,18 +40,12 @@ Only entries with a complete application manifest can be downloaded. The manifes --- -## Step 2️⃣ — Configure AI Language +## Step 2️⃣ — Language -**Before scanning**, select your document's language from the left sidebar: - -| 🌐 Language | Use When | -| ---------- | --------------------------------- | -| **EN** | Document is entirely in English | -| **IT** | Document is entirely in Italian | -| **BOTH** | Document contains mixed languages | +NullifyPDF analyses **Italian** documents only; there is no language selector. The Italian name-recognition model is not part of the installer (its licence is non-commercial): the first time you run **Auto Redact** the program shows the licence, asks for your consent and downloads it. If you decline, the scan continues with rules and dictionaries only, which finds fewer names. > [!WARNING] -> Wrong language = missed detections. Choose the exact language of your document. +> Documents in other languages are not supported: names and places in them will be missed. --- diff --git a/build_local.py b/build_local.py index 465b9b0..9098ec0 100644 --- a/build_local.py +++ b/build_local.py @@ -398,7 +398,7 @@ def build_app() -> None: datas = {datas_literal} binaries = [] hiddenimports = ['spacy', 'presidio_analyzer', 'lexicon_data_it', 'onnxruntime', 'tokenizers'] -for pkg in ['presidio_analyzer', 'spacy', 'tldextract', 'en_core_web_md', 'onnxruntime', 'tokenizers'] + (['keyring'] if sys.platform != 'win32' else []): +for pkg in ['presidio_analyzer', 'spacy', 'tldextract', 'onnxruntime', 'tokenizers'] + (['keyring'] if sys.platform != 'win32' else []): t = collect_all(pkg) datas += t[0]; binaries += t[1]; hiddenimports += t[2] @@ -415,7 +415,7 @@ def build_app() -> None: datas = {datas_literal} binaries = [] hiddenimports = ['spacy', 'presidio_analyzer', 'lexicon_data_it', 'onnxruntime', 'tokenizers'] -for pkg in ['presidio_analyzer', 'spacy', 'tldextract', 'en_core_web_md', 'onnxruntime', 'tokenizers'] + (['keyring'] if sys.platform != 'win32' else []): +for pkg in ['presidio_analyzer', 'spacy', 'tldextract', 'onnxruntime', 'tokenizers'] + (['keyring'] if sys.platform != 'win32' else []): t = collect_all(pkg) datas += t[0]; binaries += t[1]; hiddenimports += t[2] diff --git a/help_guide.py b/help_guide.py index 56cf597..df13bc4 100644 --- a/help_guide.py +++ b/help_guide.py @@ -40,10 +40,7 @@ TOOLTIPS: Dict[str, str] = { # Sidebar "Apri PDF": "Apre un file PDF da elaborare. Puoi anche trascinarlo sulla finestra.", - "Modello lingua:": "Lingua dei modelli di riconoscimento dei dati personali.", - "EN": "Usa il modello inglese. Adatto a documenti in inglese.", - "IT": "Usa il modello italiano. Consigliato per documenti in italiano: il modello inglese aggiunge falsi positivi.", - "BOTH": "Usa entrambi i modelli (inglese e italiano). Più lento; utile per documenti misti.", + "Lingua dei documenti: italiano": "NullifyPDF analizza documenti in italiano. Il modello italiano viene scaricato, dopo il tuo consenso, al primo utilizzo.", "Oscura Immagini": "Oscura anche tutte le immagini della pagina (loghi, firme, foto) quando applichi Auto Redact.", "OCR PDF scansionati": "Legge con l'OCR le pagine scansionate e le immagini incorporate, così anche il testo nelle immagini viene analizzato.", "Mostra suggerimenti": "Contorna in arancione, nell'anteprima, i suggerimenti ancora da rivedere. Servono solo a video: non finiscono nel file esportato.", @@ -256,7 +253,7 @@ def widgets_without_tooltip(root: QWidget) -> List[str]: """), ("Lingua e opzioni", """

    Lingua e opzioni

    -

    Modello lingua: IT per documenti italiani (consigliato: il modello inglese su testo italiano aggiunge falsi positivi), EN per l'inglese, BOTH per documenti misti. All'avvio viene scelto IT se il sistema è in italiano.

    +

    Lingua: il programma analizza documenti in italiano. Il modello italiano non è incluso nell'installer (licenza non commerciale): al primo utilizzo il programma mostra la licenza e chiede il consenso per scaricarlo.

    • Oscura Immagini: censura anche tutte le immagini (loghi, foto, firme) quando applichi Auto Redact.
    • OCR PDF scansionati: legge con l'OCR le pagine scansionate e le immagini incorporate nelle pagine di testo. Richiede i dati di Tesseract (inclusi nei pacchetti).
    • diff --git a/licences_info.py b/licences_info.py index b67cd09..6686e2c 100644 --- a/licences_info.py +++ b/licences_info.py @@ -45,9 +45,6 @@ class Component(NamedTuple): "riconoscimento dei dati personali", "personal-data detection"), Component("spaCy", "MIT", "https://github.com/explosion/spaCy/blob/master/LICENSE", "elaborazione del linguaggio", "language processing"), - Component("spaCy en_core_web_md", "MIT", - "https://github.com/explosion/spacy-models/releases/tag/en_core_web_md-3.8.0", - "modello inglese", "English model"), Component("spaCy it_core_news_md", "CC BY-NC-SA 3.0 (solo uso non commerciale)", CC_NC_SA_URL, "modello italiano, scaricato dopo il consenso", "Italian model, downloaded after consent", "CC BY-NC-SA 3.0 (non-commercial use only)"), diff --git a/requirements.txt b/requirements.txt index 1ed3599..8b36a1c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,6 @@ keyring==25.7.0; sys_platform != "win32" # IMPORTANT: model minor version MUST match the spaCy core minor version # (spaCy 3.8.x <-> models 3.8.x). The models declare spacy>=3.8.0,<3.9.0. # These are cached by pip in GitHub Actions, significantly speeding up CI/CD -en-core-web-md @ https://github.com/explosion/spacy-models/releases/download/en_core_web_md-3.8.0/en_core_web_md-3.8.0-py3-none-any.whl # Development and CI only (tests of the Italian detectors). Licence CC BY-NC-SA 3.0: # NOT bundled in the installer (excluded in the PyInstaller spec); the app # downloads it on demand after the user accepts the licence (spacy_models.py). diff --git a/setup_env.py b/setup_env.py index 377acd6..1643233 100644 --- a/setup_env.py +++ b/setup_env.py @@ -113,9 +113,8 @@ def setup_environment() -> None: logger.error(f"Errore durante l'installazione dipendenze: {e}") sys.exit(1) - logger.info("Download modelli linguistici spaCy (EN & IT)") + logger.info("Download modello linguistico spaCy (IT)") spacy_models = [ - "https://github.com/explosion/spacy-models/releases/download/en_core_web_md-3.8.0/en_core_web_md-3.8.0-py3-none-any.whl", "https://github.com/explosion/spacy-models/releases/download/it_core_news_md-3.8.0/it_core_news_md-3.8.0-py3-none-any.whl" ] try: diff --git a/tests/test_gui_flow.py b/tests/test_gui_flow.py index c8d6ebd..3dfeaf8 100644 --- a/tests/test_gui_flow.py +++ b/tests/test_gui_flow.py @@ -261,9 +261,9 @@ def test_wipe_local_data(window, monkeypatch): assert not (w.config_dir / "audit").exists() -def test_default_language_follows_system_locale(window): - assert window.rb_it.isChecked() or window.rb_both.isChecked() - assert not window.rb_en.isChecked() +def test_only_italian_is_offered(window): + assert not hasattr(window, "rb_en") and not hasattr(window, "rb_both") + assert "italiano" in window.lbl_lang.text() def test_worker_scan_end_to_end_with_real_italian_model(tmp_path, monkeypatch): diff --git a/tests/test_validation.py b/tests/test_validation.py index 843c530..dee3e68 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -94,15 +94,15 @@ def test_resource_path_not_empty(self): class TestOcrConfiguration: """Test OCR configuration helpers.""" - def test_ocr_language_without_tessdata_uses_requested_languages(self): - assert ocr_language_for_choice("EN", None) == "eng" + def test_ocr_language_without_tessdata_is_italian(self): assert ocr_language_for_choice("IT", None) == "ita" - assert ocr_language_for_choice("BOTH", None) == "eng+ita" def test_ocr_language_filters_to_installed_languages(self, tmp_path): + assert ocr_language_for_choice("IT", str(tmp_path)) == "ita" (tmp_path / "eng.traineddata").write_text("placeholder", encoding="utf-8") - - assert ocr_language_for_choice("BOTH", str(tmp_path)) == "eng" + assert ocr_language_for_choice("IT", str(tmp_path)) == "eng" + (tmp_path / "ita.traineddata").write_text("placeholder", encoding="utf-8") + assert ocr_language_for_choice("IT", str(tmp_path)) == "ita+eng" def test_find_tessdata_dir_reads_environment(self, tmp_path, monkeypatch): (tmp_path / "ita.traineddata").write_text("placeholder", encoding="utf-8") From 46d7aa40faf66f35536429dddcaf146954810d5b Mon Sep 17 00:00:00 2001 From: 0verwrite <31691645+overwrite00@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:35:14 +0100 Subject: [PATCH 5/5] docs: align guides with AGPL and Italian-only, version 2.4.0-beta.5 --- CONTRIBUTING.md | 6 +++++- DEVELOPMENT.md | 4 ++-- NullifyPDF.py | 2 +- README.md | 2 +- help_guide.py | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 018130e..5f101e2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -379,5 +379,9 @@ Every contribution — code, docs, bug reports, ideas — helps make NullifyPDF --- -*Last updated: 2026-11-08* +*Last updated: 2026-11-11* *← [Back to README](./README.md) | [Architecture →](./ARCHITECTURE.md)* + +## Licence of contributions + +NullifyPDF is licensed under the AGPL-3.0-or-later (see [LICENSE](./LICENSE)). By submitting a contribution you agree that it is released under the same licence. diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index a474b1a..36287ac 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -16,7 +16,7 @@ Before starting, verify you have: | **Python 3.13** | 150 MB | [Download](https://www.python.org/downloads/) | | **Git** | 50 MB | [Download](https://git-scm.com/) | | **Virtual Environment** | 2 GB | `.venv/` auto-created by setup script | -| **Disk Space** | 3 GB | Dependencies + spaCy models | +| **Disk Space** | 3 GB | Dependencies + Italian model | | **RAM** | 4 GB | 8 GB recommended | --- @@ -51,7 +51,7 @@ python setup_env.py This automatically: - ✅ Creates `.venv/` virtual environment - ✅ Installs dependencies -- ✅ Downloads spaCy models (EN + IT) +- ✅ Installs the Italian spaCy model (development only) ### 4️⃣ Activate Virtual Environment diff --git a/NullifyPDF.py b/NullifyPDF.py index cae2dbb..945a73e 100644 --- a/NullifyPDF.py +++ b/NullifyPDF.py @@ -138,7 +138,7 @@ PDF_REDACT_IMAGE_PIXELS: int = fitz.PDF_REDACT_IMAGE_PIXELS # type: ignore[attr-defined] __version__ = "2.4.0" -__version_prerelease__ = "beta.4" +__version_prerelease__ = "beta.5" APP_VERSION = ( f"{__version__}-{__version_prerelease__}" if __version_prerelease__ diff --git a/README.md b/README.md index 86aa59a..57f2912 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ No installation needed on Windows/macOS - just run or unzip. Linux users can ins This script automatically: - Creates isolated virtual environment (`.venv`) - Installs all dependencies - - Downloads spaCy language models (EN/IT) + - Installs the Italian spaCy model for development (the installer downloads it on demand) 4. **Activate environment & launch** diff --git a/help_guide.py b/help_guide.py index df13bc4..b1a5342 100644 --- a/help_guide.py +++ b/help_guide.py @@ -363,7 +363,7 @@ def widgets_without_tooltip(root: QWidget) -> List[str]: """), ("Info e aggiornamenti", """

      Info e aggiornamenti

      -

      La finestra Info mostra la versione e il collegamento al repository. Controlla aggiornamenti interroga le release pubblicate su GitHub; con Controlla ad ogni avvio (disattivato di default) il controllo è eseguito all'avvio e mostra qualcosa solo se esiste una versione più recente.

      +

      La finestra Info mostra la versione e il collegamento al repository. Elenca anche la licenza del programma (AGPL-3.0-or-later) e quella di ogni componente e modello usato, con i collegamenti ai testi ufficiali. Controlla aggiornamenti interroga le release pubblicate su GitHub; con Controlla ad ogni avvio (disattivato di default) il controllo è eseguito all'avvio e mostra qualcosa solo se esiste una versione più recente.

      """), ("Scorciatoie", """

      Scorciatoie