lintvoice 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lintvoice-0.1.0/.gitignore +6 -0
- lintvoice-0.1.0/Dockerfile +7 -0
- lintvoice-0.1.0/LICENSE +21 -0
- lintvoice-0.1.0/PKG-INFO +142 -0
- lintvoice-0.1.0/README.fr.md +25 -0
- lintvoice-0.1.0/README.md +112 -0
- lintvoice-0.1.0/THIRD_PARTY_NOTICES.md +20 -0
- lintvoice-0.1.0/pyproject.toml +72 -0
- lintvoice-0.1.0/src/lintvoice/__init__.py +3 -0
- lintvoice-0.1.0/src/lintvoice/__main__.py +5 -0
- lintvoice-0.1.0/src/lintvoice/cli.py +205 -0
- lintvoice-0.1.0/src/lintvoice/document.py +166 -0
- lintvoice-0.1.0/src/lintvoice/engine.py +292 -0
- lintvoice-0.1.0/src/lintvoice/report.py +168 -0
- lintvoice-0.1.0/src/lintvoice/rulepacks.py +193 -0
- lintvoice-0.1.0/tests/conftest.py +78 -0
- lintvoice-0.1.0/tests/invoices.py +296 -0
- lintvoice-0.1.0/tests/test_check_cii.py +181 -0
- lintvoice-0.1.0/tests/test_check_ubl.py +52 -0
- lintvoice-0.1.0/tests/test_cli.py +97 -0
- lintvoice-0.1.0/tests/test_corpus.py +32 -0
- lintvoice-0.1.0/tests/test_hostile_inputs.py +114 -0
- lintvoice-0.1.0/tests/test_inputs.py +107 -0
- lintvoice-0.1.0/tests/test_invoice_examples.py +46 -0
- lintvoice-0.1.0/tests/test_offline.py +82 -0
- lintvoice-0.1.0/tests/test_output.py +59 -0
- lintvoice-0.1.0/tests/test_packaging.py +38 -0
- lintvoice-0.1.0/tests/test_rule_set_failure.py +69 -0
- lintvoice-0.1.0/tests/test_rulepacks.py +64 -0
- lintvoice-0.1.0/tests/test_wording.py +27 -0
- lintvoice-0.1.0/third_party/licenses/EUPL-1.2.txt +190 -0
- lintvoice-0.1.0/third_party/licenses/MPL-2.0.txt +373 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
FROM python:3.13.18-slim-trixie
|
|
2
|
+
ENV LINTVOICE_RULES_DIR=/opt/lintvoice/rules
|
|
3
|
+
RUN --mount=type=bind,source=dist,target=/dist pip install --no-cache-dir /dist/*.whl && lintvoice rules install && pip uninstall -y -q pip
|
|
4
|
+
COPY LICENSE THIRD_PARTY_NOTICES.md third_party/licenses /usr/share/doc/lintvoice/
|
|
5
|
+
USER 10001
|
|
6
|
+
WORKDIR /work
|
|
7
|
+
ENTRYPOINT ["lintvoice"]
|
lintvoice-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AllGood Services SAS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
lintvoice-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: lintvoice
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline e-invoice validator: EN 16931, Factur-X and the French BR-FR rules
|
|
5
|
+
Project-URL: Homepage, https://lintvoice.com
|
|
6
|
+
Project-URL: Source, https://github.com/lintvoice/lintvoice
|
|
7
|
+
Project-URL: Issues, https://github.com/lintvoice/lintvoice/issues
|
|
8
|
+
Author: AllGood Services SAS
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: br-fr,ci,cii,e-invoice,en16931,factur-x,linter,ubl,validator,xrechnung,zugferd
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Office/Business :: Financial :: Accounting
|
|
23
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
24
|
+
Classifier: Topic :: Text Processing :: Markup :: XML
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: lxml>=6.1
|
|
27
|
+
Requires-Dist: pypdf>=6.21.4
|
|
28
|
+
Requires-Dist: saxonche<14,>=13.1
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# lintvoice checks your e-invoices against official rules and standards
|
|
32
|
+
|
|
33
|
+
[Lire en français](README.fr.md)
|
|
34
|
+
|
|
35
|
+
It starts with the European standard, then adds each country's own rules. It works **offline**: your invoices are never sent anywhere. Today it runs:
|
|
36
|
+
|
|
37
|
+
- **EN 16931** (the European e-invoicing standard), for CII and UBL;
|
|
38
|
+
- **Factur-X 1.09.2** profile rules, for Factur-X PDFs;
|
|
39
|
+
- **BR-FR**, the French reform rules published by FNFE-MPE (France_RFE), when the seller is in France.
|
|
40
|
+
|
|
41
|
+
lintvoice reads CII XML, UBL XML (invoices and credit notes) and Factur-X / ZUGFeRD PDFs. Results are grouped by rule (e.g. one missing VAT number shows up once, not for every faulty invoice line).
|
|
42
|
+
|
|
43
|
+
> Status: 0.1.0, the first release. Options and the JSON output may still change before 1.0.
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
uvx lintvoice rules install # once: downloads the pinned rule packs
|
|
49
|
+
uvx lintvoice check invoice.pdf
|
|
50
|
+
uvx lintvoice check invoices/ --format json
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or `pip install lintvoice` (Python 3.10 or later). Each release also ships its wheel and sdist on [GitHub Releases](https://github.com/lintvoice/lintvoice/releases), if PyPI is out of reach: `pip install lintvoice-<version>-py3-none-any.whl`.
|
|
54
|
+
|
|
55
|
+
In a container, with the rule packs inside the image:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
docker build -t lintvoice . # after `uv build`, from a checkout
|
|
59
|
+
docker run --rm -v "$PWD:/work" lintvoice check invoices/
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The image runs as an unprivileged user (UID 10001).
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
✗ demo.pdf
|
|
66
|
+
Factur-X EN 16931 · CII · PDF (factur-x.xml)
|
|
67
|
+
BR-FR rules applied: the seller's country is FR.
|
|
68
|
+
7 errors in 6 rules.
|
|
69
|
+
|
|
70
|
+
error BR-FR-16_BT-152 ×2
|
|
71
|
+
BT-152: Le taux de TVA (BT-152) doit être exprimé en pourcentage … Taux fourni : "21".
|
|
72
|
+
at /CrossIndustryInvoice/SupplyChainTradeTransaction/IncludedSupplyChainTradeLineItem/… (+1 more)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Rule packs: what lintvoice downloads, and why
|
|
76
|
+
|
|
77
|
+
lintvoice ships no rule files. `lintvoice rules install` downloads each pack once, from its upstream source, at a pinned version:
|
|
78
|
+
- **What:** the official validation artefacts: Schematron sources, the XSLT compiled from them, and the XML schemas.
|
|
79
|
+
- **Why:** you get the exact official rules, under their own licences. lintvoice follows the official releases instead of rewriting rules.
|
|
80
|
+
- **When:**
|
|
81
|
+
- only when you run `lintvoice rules install`;
|
|
82
|
+
- never when the package is installed or imported, and never during a check;
|
|
83
|
+
- after that, every check runs offline.
|
|
84
|
+
- **How it is checked:**
|
|
85
|
+
- over https only;
|
|
86
|
+
- the EN 16931 archives against their SHA-256;
|
|
87
|
+
- France_RFE, which GitHub archives on the fly, against a SHA-256 of the 207 files kept;
|
|
88
|
+
- a changed file, or an archive entry outside the pack folder, stops the install.
|
|
89
|
+
- **Not downloaded into the packs:** France_RFE's folders that hold AFNOR documents (`Z.notes_&_docs/`, `Z.example/`) are never extracted.
|
|
90
|
+
- **No other network use:** a checked file cannot make lintvoice fetch anything, since a file that declares a DOCTYPE is refused.
|
|
91
|
+
|
|
92
|
+
| Pack | Version | Source | Licence |
|
|
93
|
+
| --- | --- | --- | --- |
|
|
94
|
+
| EN 16931 validation artefacts | 1.3.17 | [ConnectingEurope/eInvoicing-EN16931](https://github.com/ConnectingEurope/eInvoicing-EN16931/releases/tag/validation-1.3.17) (SHA-256 pinned) | EUPL-1.2 |
|
|
95
|
+
| France_RFE (BR-FR, Factur-X 1.09.2) | 1.4.0.04 | [fnfempe/France_RFE @ 97ba0f3](https://github.com/fnfempe/France_RFE/tree/97ba0f3d4ef2abed5780e9490d5c3a2be832ab1d) (content SHA-256 pinned) | Apache-2.0 (repository), EUPL (file headers) |
|
|
96
|
+
|
|
97
|
+
Packs go to `~/.cache/lintvoice/rules` (or `$XDG_CACHE_HOME`, `$LINTVOICE_RULES_DIR`, `--rules-dir`). `lintvoice rules list` shows what is installed.
|
|
98
|
+
|
|
99
|
+
## What runs on which file
|
|
100
|
+
|
|
101
|
+
| File | Schema | Rules |
|
|
102
|
+
| --- | --- | --- |
|
|
103
|
+
| Factur-X PDF, or CII with a Factur-X profile id | Factur-X 1.09.2 (BASIC WL, EN 16931, EXTENDED) | EN 16931 (except MINIMUM, BASIC WL), Factur-X profile rules, BR-FR (except MINIMUM) |
|
|
104
|
+
| CII XML with `urn:cen.eu:en16931:2017` | CII D22B | EN 16931, BR-FR |
|
|
105
|
+
| UBL invoice or credit note | UBL 2.1 | EN 16931, BR-FR |
|
|
106
|
+
|
|
107
|
+
- **BR-FR runs when the seller's country (BT-40) is FR.** `--rules en16931,factur-x,br-fr` forces it, `--rules en16931` limits the check to EN 16931.
|
|
108
|
+
- **A bare CII XML gets the Factur-X profile rules only when asked** (`--rules …,factur-x`), since `urn:cen.eu:en16931:2017` is also plain CII.
|
|
109
|
+
|
|
110
|
+
## Exit codes
|
|
111
|
+
|
|
112
|
+
| Code | Meaning |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| 0 | No errors (warnings do not change the exit code) |
|
|
115
|
+
| 1 | At least one file has errors |
|
|
116
|
+
| 2 | A file could not be read as an invoice, or no file was found |
|
|
117
|
+
| 3 | Rule packs are not installed |
|
|
118
|
+
| 4 | No errors found, but a rule set could not run on a file: its official rule file stopped with an error. The check is incomplete, so lintvoice does not say "no errors" |
|
|
119
|
+
|
|
120
|
+
## Not checked yet
|
|
121
|
+
|
|
122
|
+
- PDF/A-3 validation of Factur-X PDFs (needs veraPDF).
|
|
123
|
+
- XRechnung and Peppol BIS rules: those invoices get EN 16931 only, and the report says so.
|
|
124
|
+
- Factur-X MINIMUM and BASIC profile rules: France_RFE 1.4.0.04 does not ship them.
|
|
125
|
+
- Chorus Pro's own rules for its historic channels.
|
|
126
|
+
- BR-FR messages are in French, as FNFE-MPE writes them.
|
|
127
|
+
|
|
128
|
+
## Development
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
uv sync
|
|
132
|
+
uv run pytest # functional tests; the first run downloads the packs into .rules-cache/
|
|
133
|
+
uv run pytest -m corpus # only the official EN 16931 examples
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The tests drive the command line on generated invoices (`tests/invoices.py`) and on the official examples. They check that:
|
|
137
|
+
- checks never touch the network;
|
|
138
|
+
- France_RFE's AFNOR documents are never installed.
|
|
139
|
+
|
|
140
|
+
## Licence
|
|
141
|
+
|
|
142
|
+
The code is under the [MIT licence](LICENSE). The rule packs keep their own licences (table above) and are not part of this package. The Docker image bundles third-party components: see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# lintvoice vérifie vos factures électroniques au regard des règles et normes officielles
|
|
2
|
+
|
|
3
|
+
[Read in English](README.md)
|
|
4
|
+
|
|
5
|
+
Il commence par la norme européenne, puis ajoute les règles propres à chaque pays. Il fonctionne **hors ligne** : vos factures ne sont envoyées nulle part. Aujourd'hui, il applique :
|
|
6
|
+
|
|
7
|
+
- **EN 16931**, la norme européenne, pour CII et UBL ;
|
|
8
|
+
- les règles de profil **Factur-X 1.09.2**, pour les PDF Factur-X ;
|
|
9
|
+
- **BR-FR**, les règles de la réforme française publiées par le FNFE-MPE (France_RFE), quand le vendeur est en France.
|
|
10
|
+
|
|
11
|
+
Les résultats sont regroupés par règle (par exemple, un numéro de TVA manquant apparaît une fois, et non pour chaque ligne de facture en erreur).
|
|
12
|
+
|
|
13
|
+
## Démarrage
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
uvx lintvoice rules install # une fois : télécharge les jeux de règles, à version figée
|
|
17
|
+
uvx lintvoice check facture.pdf
|
|
18
|
+
uvx lintvoice check factures/ --format json
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Ou `pip install lintvoice` (Python 3.10 ou plus). Chaque version est aussi publiée sur [GitHub Releases](https://github.com/lintvoice/lintvoice/releases) (wheel et sdist), si PyPI est inaccessible.
|
|
22
|
+
|
|
23
|
+
`lintvoice rules install` télécharge les règles officielles depuis leurs sources, en https, et vérifie leur empreinte. Les dossiers de France_RFE qui contiennent des documents AFNOR ne sont jamais extraits. Après cette installation, toutes les vérifications se font sans réseau. Les règles BR-FR s'appliquent quand le pays du vendeur (BT-40) est FR ; `--rules en16931,factur-x,br-fr` les impose.
|
|
24
|
+
|
|
25
|
+
Détails (jeux de règles, licences, codes de sortie, limites) : [README.md](README.md).
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# lintvoice checks your e-invoices against official rules and standards
|
|
2
|
+
|
|
3
|
+
[Lire en français](README.fr.md)
|
|
4
|
+
|
|
5
|
+
It starts with the European standard, then adds each country's own rules. It works **offline**: your invoices are never sent anywhere. Today it runs:
|
|
6
|
+
|
|
7
|
+
- **EN 16931** (the European e-invoicing standard), for CII and UBL;
|
|
8
|
+
- **Factur-X 1.09.2** profile rules, for Factur-X PDFs;
|
|
9
|
+
- **BR-FR**, the French reform rules published by FNFE-MPE (France_RFE), when the seller is in France.
|
|
10
|
+
|
|
11
|
+
lintvoice reads CII XML, UBL XML (invoices and credit notes) and Factur-X / ZUGFeRD PDFs. Results are grouped by rule (e.g. one missing VAT number shows up once, not for every faulty invoice line).
|
|
12
|
+
|
|
13
|
+
> Status: 0.1.0, the first release. Options and the JSON output may still change before 1.0.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
uvx lintvoice rules install # once: downloads the pinned rule packs
|
|
19
|
+
uvx lintvoice check invoice.pdf
|
|
20
|
+
uvx lintvoice check invoices/ --format json
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or `pip install lintvoice` (Python 3.10 or later). Each release also ships its wheel and sdist on [GitHub Releases](https://github.com/lintvoice/lintvoice/releases), if PyPI is out of reach: `pip install lintvoice-<version>-py3-none-any.whl`.
|
|
24
|
+
|
|
25
|
+
In a container, with the rule packs inside the image:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
docker build -t lintvoice . # after `uv build`, from a checkout
|
|
29
|
+
docker run --rm -v "$PWD:/work" lintvoice check invoices/
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The image runs as an unprivileged user (UID 10001).
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
✗ demo.pdf
|
|
36
|
+
Factur-X EN 16931 · CII · PDF (factur-x.xml)
|
|
37
|
+
BR-FR rules applied: the seller's country is FR.
|
|
38
|
+
7 errors in 6 rules.
|
|
39
|
+
|
|
40
|
+
error BR-FR-16_BT-152 ×2
|
|
41
|
+
BT-152: Le taux de TVA (BT-152) doit être exprimé en pourcentage … Taux fourni : "21".
|
|
42
|
+
at /CrossIndustryInvoice/SupplyChainTradeTransaction/IncludedSupplyChainTradeLineItem/… (+1 more)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Rule packs: what lintvoice downloads, and why
|
|
46
|
+
|
|
47
|
+
lintvoice ships no rule files. `lintvoice rules install` downloads each pack once, from its upstream source, at a pinned version:
|
|
48
|
+
- **What:** the official validation artefacts: Schematron sources, the XSLT compiled from them, and the XML schemas.
|
|
49
|
+
- **Why:** you get the exact official rules, under their own licences. lintvoice follows the official releases instead of rewriting rules.
|
|
50
|
+
- **When:**
|
|
51
|
+
- only when you run `lintvoice rules install`;
|
|
52
|
+
- never when the package is installed or imported, and never during a check;
|
|
53
|
+
- after that, every check runs offline.
|
|
54
|
+
- **How it is checked:**
|
|
55
|
+
- over https only;
|
|
56
|
+
- the EN 16931 archives against their SHA-256;
|
|
57
|
+
- France_RFE, which GitHub archives on the fly, against a SHA-256 of the 207 files kept;
|
|
58
|
+
- a changed file, or an archive entry outside the pack folder, stops the install.
|
|
59
|
+
- **Not downloaded into the packs:** France_RFE's folders that hold AFNOR documents (`Z.notes_&_docs/`, `Z.example/`) are never extracted.
|
|
60
|
+
- **No other network use:** a checked file cannot make lintvoice fetch anything, since a file that declares a DOCTYPE is refused.
|
|
61
|
+
|
|
62
|
+
| Pack | Version | Source | Licence |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| EN 16931 validation artefacts | 1.3.17 | [ConnectingEurope/eInvoicing-EN16931](https://github.com/ConnectingEurope/eInvoicing-EN16931/releases/tag/validation-1.3.17) (SHA-256 pinned) | EUPL-1.2 |
|
|
65
|
+
| France_RFE (BR-FR, Factur-X 1.09.2) | 1.4.0.04 | [fnfempe/France_RFE @ 97ba0f3](https://github.com/fnfempe/France_RFE/tree/97ba0f3d4ef2abed5780e9490d5c3a2be832ab1d) (content SHA-256 pinned) | Apache-2.0 (repository), EUPL (file headers) |
|
|
66
|
+
|
|
67
|
+
Packs go to `~/.cache/lintvoice/rules` (or `$XDG_CACHE_HOME`, `$LINTVOICE_RULES_DIR`, `--rules-dir`). `lintvoice rules list` shows what is installed.
|
|
68
|
+
|
|
69
|
+
## What runs on which file
|
|
70
|
+
|
|
71
|
+
| File | Schema | Rules |
|
|
72
|
+
| --- | --- | --- |
|
|
73
|
+
| Factur-X PDF, or CII with a Factur-X profile id | Factur-X 1.09.2 (BASIC WL, EN 16931, EXTENDED) | EN 16931 (except MINIMUM, BASIC WL), Factur-X profile rules, BR-FR (except MINIMUM) |
|
|
74
|
+
| CII XML with `urn:cen.eu:en16931:2017` | CII D22B | EN 16931, BR-FR |
|
|
75
|
+
| UBL invoice or credit note | UBL 2.1 | EN 16931, BR-FR |
|
|
76
|
+
|
|
77
|
+
- **BR-FR runs when the seller's country (BT-40) is FR.** `--rules en16931,factur-x,br-fr` forces it, `--rules en16931` limits the check to EN 16931.
|
|
78
|
+
- **A bare CII XML gets the Factur-X profile rules only when asked** (`--rules …,factur-x`), since `urn:cen.eu:en16931:2017` is also plain CII.
|
|
79
|
+
|
|
80
|
+
## Exit codes
|
|
81
|
+
|
|
82
|
+
| Code | Meaning |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| 0 | No errors (warnings do not change the exit code) |
|
|
85
|
+
| 1 | At least one file has errors |
|
|
86
|
+
| 2 | A file could not be read as an invoice, or no file was found |
|
|
87
|
+
| 3 | Rule packs are not installed |
|
|
88
|
+
| 4 | No errors found, but a rule set could not run on a file: its official rule file stopped with an error. The check is incomplete, so lintvoice does not say "no errors" |
|
|
89
|
+
|
|
90
|
+
## Not checked yet
|
|
91
|
+
|
|
92
|
+
- PDF/A-3 validation of Factur-X PDFs (needs veraPDF).
|
|
93
|
+
- XRechnung and Peppol BIS rules: those invoices get EN 16931 only, and the report says so.
|
|
94
|
+
- Factur-X MINIMUM and BASIC profile rules: France_RFE 1.4.0.04 does not ship them.
|
|
95
|
+
- Chorus Pro's own rules for its historic channels.
|
|
96
|
+
- BR-FR messages are in French, as FNFE-MPE writes them.
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
uv sync
|
|
102
|
+
uv run pytest # functional tests; the first run downloads the packs into .rules-cache/
|
|
103
|
+
uv run pytest -m corpus # only the official EN 16931 examples
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The tests drive the command line on generated invoices (`tests/invoices.py`) and on the official examples. They check that:
|
|
107
|
+
- checks never touch the network;
|
|
108
|
+
- France_RFE's AFNOR documents are never installed.
|
|
109
|
+
|
|
110
|
+
## Licence
|
|
111
|
+
|
|
112
|
+
The code is under the [MIT licence](LICENSE). The rule packs keep their own licences (table above) and are not part of this package. The Docker image bundles third-party components: see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
lintvoice's own code is under the MIT licence (`LICENSE`). It ships no third-party code in its Python package: the
|
|
4
|
+
packages below are installed from PyPI as dependencies, and the rule packs are downloaded by `lintvoice rules install`.
|
|
5
|
+
|
|
6
|
+
The **Docker image** bundles all of them. Each keeps its own licence:
|
|
7
|
+
|
|
8
|
+
| Component | Version | Licence | Source | Licence text in the image |
|
|
9
|
+
| --- | --- | --- | --- | --- |
|
|
10
|
+
| lxml | ≥ 6.1 | BSD-3-Clause | https://pypi.org/project/lxml/ | its `*.dist-info` folder |
|
|
11
|
+
| pypdf | ≥ 6.21.4 | BSD-3-Clause | https://pypi.org/project/pypdf/ | its `*.dist-info` folder |
|
|
12
|
+
| saxonche (SaxonC-HE) | ≥ 13.1, < 14 | MPL-2.0 (some components Apache-2.0 or BSD); its wheel metadata carries no licence field | https://pypi.org/project/saxonche/ | `/usr/share/doc/lintvoice/MPL-2.0.txt` |
|
|
13
|
+
| EN 16931 validation artefacts | 1.3.17 | EUPL-1.2 | https://github.com/ConnectingEurope/eInvoicing-EN16931/releases/tag/validation-1.3.17 | `/usr/share/doc/lintvoice/EUPL-1.2.txt` |
|
|
14
|
+
| France_RFE (BR-FR rules, Factur-X 1.09.2 schemas and rules) | 1.4.0.04 (`97ba0f3`) | Apache-2.0 (repository); the Schematron file headers say EUPL | https://github.com/fnfempe/France_RFE/tree/97ba0f3d4ef2abed5780e9490d5c3a2be832ab1d | `LICENSE` inside the pack, and `/usr/share/doc/lintvoice/EUPL-1.2.txt` |
|
|
15
|
+
|
|
16
|
+
**The rule packs are unmodified.** Their Schematron sources (`.sch`) ship with the compiled XSLT, inside each pack folder.
|
|
17
|
+
France_RFE's folders that hold AFNOR documents (`Z.notes_&_docs/`, `Z.example/`) are never downloaded into the packs.
|
|
18
|
+
|
|
19
|
+
Licence texts in `third_party/licenses/` (copied to `/usr/share/doc/lintvoice/` in the image) come from the SPDX License List data, release v3.29.0
|
|
20
|
+
(https://github.com/spdx/license-list-data/tree/v3.29.0/text).
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "lintvoice"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Offline e-invoice validator: EN 16931, Factur-X and the French BR-FR rules"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.10"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"lxml>=6.1",
|
|
11
|
+
"pypdf>=6.21.4", # 7 CVEs (crafted PDFs: infinite loops, memory) fixed in 6.21.3 and 6.21.4
|
|
12
|
+
"saxonche>=13.1,<14", # the engine behind every verdict: a new major is adopted once the test suite passes on it
|
|
13
|
+
]
|
|
14
|
+
keywords = ["e-invoice", "validator", "factur-x", "zugferd", "xrechnung", "en16931", "cii", "ubl", "br-fr", "linter", "ci"]
|
|
15
|
+
authors = [{ name = "AllGood Services SAS" }]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Environment :: Console",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Topic :: Office/Business :: Financial :: Accounting",
|
|
28
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
29
|
+
"Topic :: Text Processing :: Markup :: XML",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://lintvoice.com"
|
|
34
|
+
Source = "https://github.com/lintvoice/lintvoice"
|
|
35
|
+
Issues = "https://github.com/lintvoice/lintvoice/issues"
|
|
36
|
+
|
|
37
|
+
[project.scripts]
|
|
38
|
+
lintvoice = "lintvoice.cli:main"
|
|
39
|
+
|
|
40
|
+
[dependency-groups]
|
|
41
|
+
dev = ["pytest>=8.4", "invoice-examples"]
|
|
42
|
+
|
|
43
|
+
[tool.uv.sources]
|
|
44
|
+
# Local sibling repo until invoice-examples is published on PyPI.
|
|
45
|
+
invoice-examples = { path = "../invoice-examples", editable = true }
|
|
46
|
+
|
|
47
|
+
[build-system]
|
|
48
|
+
requires = ["hatchling>=1.27"]
|
|
49
|
+
build-backend = "hatchling.build"
|
|
50
|
+
|
|
51
|
+
[tool.hatch.build.targets.sdist]
|
|
52
|
+
include = ["src", "tests", "third_party", "README.md", "README.fr.md", "LICENSE", "THIRD_PARTY_NOTICES.md", "Dockerfile"]
|
|
53
|
+
|
|
54
|
+
[tool.pytest.ini_options]
|
|
55
|
+
testpaths = ["tests"]
|
|
56
|
+
markers = [
|
|
57
|
+
"corpus: runs on the official EN 16931 examples (downloaded with the rule packs)",
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
line-length = 120
|
|
62
|
+
extend-exclude = [".rules-cache"]
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint]
|
|
65
|
+
# Curated set: errors, likely bugs, security, modern syntax, simplifications, Ruff's own rules.
|
|
66
|
+
select = ["E", "F", "W", "B", "S", "UP", "SIM", "RUF", "C4", "PERF"]
|
|
67
|
+
# Long lines are the formatter's call; ×, ✓, « » and other non-ASCII characters are intended; PERF401 flags
|
|
68
|
+
# loops whose side effects (files written, rules seen) a comprehension would hide.
|
|
69
|
+
ignore = ["E501", "RUF001", "RUF002", "RUF003", "PERF401"]
|
|
70
|
+
|
|
71
|
+
[tool.ruff.lint.per-file-ignores]
|
|
72
|
+
"tests/**" = ["S101", "S603", "S607", "S310"] # asserts and subprocesses are what tests are made of
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"""Command line: lintvoice check FILE..., lintvoice rules list|install.
|
|
2
|
+
|
|
3
|
+
Exit codes: 0 no errors, 1 errors found, 2 a file could not be read as an invoice, 3 rule packs missing,
|
|
4
|
+
4 no errors found but a rule set could not run on a file (an error inside the official rule file).
|
|
5
|
+
XML files found while walking a directory are skipped when they are not invoices (a build.xml, a config file);
|
|
6
|
+
a file named on the command line must be an invoice.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from . import __version__, document, engine, report, rulepacks
|
|
15
|
+
|
|
16
|
+
EXIT_OK, EXIT_ERRORS, EXIT_UNREADABLE, EXIT_NO_RULES, EXIT_INCOMPLETE = 0, 1, 2, 3, 4
|
|
17
|
+
INVOICE_SUFFIXES = {".xml", ".pdf"}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _files(paths):
|
|
21
|
+
"""Yield (path, named): directories expand into their .xml and .pdf files, sorted (named=False);
|
|
22
|
+
files are kept as given (named=True)."""
|
|
23
|
+
for p in map(Path, paths):
|
|
24
|
+
if p.is_dir():
|
|
25
|
+
for f in sorted(f for f in p.rglob("*") if f.is_file() and f.suffix.lower() in INVOICE_SUFFIXES):
|
|
26
|
+
yield f, False
|
|
27
|
+
else:
|
|
28
|
+
yield p, True
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _rules_option(value):
|
|
32
|
+
if value == "auto":
|
|
33
|
+
return "auto"
|
|
34
|
+
chosen = {v.strip() for v in value.split(",") if v.strip()}
|
|
35
|
+
unknown = chosen - set(engine.RULE_CHOICES)
|
|
36
|
+
if unknown or not chosen:
|
|
37
|
+
raise argparse.ArgumentTypeError(
|
|
38
|
+
f"unknown rule set {', '.join(sorted(unknown)) or '(empty)'}; choose auto or a list of: "
|
|
39
|
+
+ ", ".join(engine.RULE_CHOICES)
|
|
40
|
+
)
|
|
41
|
+
return chosen
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
_ENGINES = {}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _engine(root):
|
|
48
|
+
"""One engine per rules folder and process: each rule set is compiled once, then reused."""
|
|
49
|
+
key = str(Path(root).resolve())
|
|
50
|
+
if key not in _ENGINES:
|
|
51
|
+
_ENGINES[key] = engine.Engine(root)
|
|
52
|
+
return _ENGINES[key]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _use_color(stream, choice):
|
|
56
|
+
if choice != "auto":
|
|
57
|
+
return choice == "always"
|
|
58
|
+
return stream.isatty() and "NO_COLOR" not in os.environ
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def cmd_check(args, out):
|
|
62
|
+
root = rulepacks.rules_dir(args.rules_dir)
|
|
63
|
+
style = report.Style(_use_color(out, args.color) and args.format == "text")
|
|
64
|
+
try:
|
|
65
|
+
rulepacks.require(root)
|
|
66
|
+
except rulepacks.RulesNotInstalled as e:
|
|
67
|
+
print(f"lintvoice: {e}", file=sys.stderr)
|
|
68
|
+
return EXIT_NO_RULES
|
|
69
|
+
eng = _engine(root)
|
|
70
|
+
results, failures, skipped, blocks = [], [], [], []
|
|
71
|
+
for path, named in _files(args.paths):
|
|
72
|
+
try:
|
|
73
|
+
doc = document.load(path)
|
|
74
|
+
result = eng.check(doc, args.rules)
|
|
75
|
+
except document.NotAnInvoiceXml as e:
|
|
76
|
+
if named:
|
|
77
|
+
failures.append((path, str(e)))
|
|
78
|
+
blocks.append(report.text_error(path, str(e), style))
|
|
79
|
+
else:
|
|
80
|
+
skipped.append(path)
|
|
81
|
+
continue
|
|
82
|
+
except FileNotFoundError:
|
|
83
|
+
failures.append((path, "file not found"))
|
|
84
|
+
blocks.append(report.text_error(path, "file not found", style))
|
|
85
|
+
continue
|
|
86
|
+
except (document.NotAnInvoice, IsADirectoryError, PermissionError) as e:
|
|
87
|
+
failures.append((path, str(e)))
|
|
88
|
+
blocks.append(report.text_error(path, str(e), style))
|
|
89
|
+
continue
|
|
90
|
+
results.append(result)
|
|
91
|
+
if not (args.quiet and not result.errors and not result.not_run):
|
|
92
|
+
blocks.append(report.text_result(result, style, verbose=args.verbose))
|
|
93
|
+
if not results and not failures:
|
|
94
|
+
what = f"only {len(skipped)} XML file(s) that are not invoices" if skipped else "no .xml or .pdf file"
|
|
95
|
+
print(f"lintvoice: {what} found in the given paths", file=sys.stderr)
|
|
96
|
+
return EXIT_UNREADABLE
|
|
97
|
+
code = (
|
|
98
|
+
EXIT_UNREADABLE
|
|
99
|
+
if failures
|
|
100
|
+
else EXIT_ERRORS
|
|
101
|
+
if any(r.errors for r in results)
|
|
102
|
+
else EXIT_INCOMPLETE
|
|
103
|
+
if any(r.not_run for r in results)
|
|
104
|
+
else EXIT_OK
|
|
105
|
+
)
|
|
106
|
+
if args.format == "json":
|
|
107
|
+
print(report.json_report(results, failures, code, skipped), file=out)
|
|
108
|
+
else:
|
|
109
|
+
used = [rs for r in results for rs in r.rule_sets]
|
|
110
|
+
print(report.header(used, style), file=out)
|
|
111
|
+
for b in blocks:
|
|
112
|
+
print("", file=out)
|
|
113
|
+
print(b, file=out)
|
|
114
|
+
print("", file=out)
|
|
115
|
+
if skipped:
|
|
116
|
+
names = ", ".join(str(s) for s in skipped[:3]) + (
|
|
117
|
+
f" and {len(skipped) - 3} more" if len(skipped) > 3 else ""
|
|
118
|
+
)
|
|
119
|
+
print(
|
|
120
|
+
style.dim(
|
|
121
|
+
f"Skipped {len(skipped)} XML file{'s' * (len(skipped) != 1)} that {'are' if len(skipped) != 1 else 'is'} not an invoice: {names}"
|
|
122
|
+
),
|
|
123
|
+
file=out,
|
|
124
|
+
)
|
|
125
|
+
print(report.footer(results, failures, style), file=out)
|
|
126
|
+
return code
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def cmd_rules_list(args, out):
|
|
130
|
+
root = rulepacks.rules_dir(args.rules_dir)
|
|
131
|
+
print(f"Rule packs in {root}", file=out)
|
|
132
|
+
for pack in rulepacks.PACKS.values():
|
|
133
|
+
state = "installed" if rulepacks.is_installed(pack, root) else "not installed"
|
|
134
|
+
print(f" {pack.id:<11} {pack.version:<9} {state:<14} {pack.name}", file=out)
|
|
135
|
+
print(f" {'':<11} licence: {pack.licence}", file=out)
|
|
136
|
+
print(f" {'':<11} source: {pack.source}", file=out)
|
|
137
|
+
return EXIT_OK
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def cmd_rules_install(args, out):
|
|
141
|
+
root = rulepacks.rules_dir(args.rules_dir)
|
|
142
|
+
for pack in rulepacks.PACKS.values():
|
|
143
|
+
if rulepacks.is_installed(pack, root) and not args.force:
|
|
144
|
+
print(f"{pack.id} {pack.version}: already installed", file=out)
|
|
145
|
+
continue
|
|
146
|
+
print(f"{pack.id} {pack.version}: downloading from {pack.source}", file=out)
|
|
147
|
+
try:
|
|
148
|
+
count = rulepacks.install(pack, root, force=args.force)
|
|
149
|
+
except Exception as e:
|
|
150
|
+
print(f"lintvoice: could not install {pack.id}: {e}", file=sys.stderr)
|
|
151
|
+
return EXIT_NO_RULES
|
|
152
|
+
print(f"{pack.id} {pack.version}: {count} files installed in {rulepacks.pack_path(pack, root)}", file=out)
|
|
153
|
+
return EXIT_OK
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def parser():
|
|
157
|
+
p = argparse.ArgumentParser(prog="lintvoice", description="Offline e-invoice validator: EN 16931, Factur-X, BR-FR.")
|
|
158
|
+
p.add_argument("--version", action="version", version=f"lintvoice {__version__}")
|
|
159
|
+
sub = p.add_subparsers(dest="command", required=True)
|
|
160
|
+
|
|
161
|
+
check = sub.add_parser("check", help="check invoice files (CII or UBL XML, Factur-X PDF)")
|
|
162
|
+
check.add_argument("paths", nargs="+", help="files or directories (directories: every .xml and .pdf inside)")
|
|
163
|
+
check.add_argument(
|
|
164
|
+
"--rules",
|
|
165
|
+
type=_rules_option,
|
|
166
|
+
default="auto",
|
|
167
|
+
help="auto (default: EN 16931, Factur-X profile rules, BR-FR when the seller is in France) "
|
|
168
|
+
"or a comma list of: " + ", ".join(engine.RULE_CHOICES),
|
|
169
|
+
)
|
|
170
|
+
check.add_argument("--format", choices=("text", "json"), default="text")
|
|
171
|
+
check.add_argument("-v", "--verbose", action="store_true", help="full messages and every location")
|
|
172
|
+
check.add_argument("-q", "--quiet", action="store_true", help="only list files with errors or an incomplete check")
|
|
173
|
+
check.add_argument("--color", choices=("auto", "always", "never"), default="auto")
|
|
174
|
+
check.add_argument("--rules-dir", help="where the rule packs are installed")
|
|
175
|
+
check.set_defaults(func=cmd_check)
|
|
176
|
+
|
|
177
|
+
rules = sub.add_parser("rules", help="list or install the rule packs")
|
|
178
|
+
rules_sub = rules.add_subparsers(dest="rules_command", required=True)
|
|
179
|
+
lst = rules_sub.add_parser("list", help="show the pinned rule packs and whether they are installed")
|
|
180
|
+
lst.add_argument("--rules-dir")
|
|
181
|
+
lst.set_defaults(func=cmd_rules_list)
|
|
182
|
+
inst = rules_sub.add_parser("install", help="download the pinned rule packs (once; checks are offline after)")
|
|
183
|
+
inst.add_argument("--rules-dir")
|
|
184
|
+
inst.add_argument("--force", action="store_true", help="download again even if installed")
|
|
185
|
+
inst.set_defaults(func=cmd_rules_install)
|
|
186
|
+
return p
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _utf8_when_not_a_terminal():
|
|
190
|
+
"""Reports carry ✓ ✗ · and the French rule messages. A pipe or a file gets UTF-8 on every platform: on Windows,
|
|
191
|
+
Python would use the ANSI code page (cp1252), which cannot encode ✓. Python itself makes UTF-8 the default from
|
|
192
|
+
3.15 (PEP 686). A terminal keeps Python's own handling."""
|
|
193
|
+
for stream in (sys.stdout, sys.stderr):
|
|
194
|
+
if hasattr(stream, "reconfigure") and not stream.isatty():
|
|
195
|
+
stream.reconfigure(encoding="utf-8")
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def main(argv=None, out=None):
|
|
199
|
+
_utf8_when_not_a_terminal()
|
|
200
|
+
args = parser().parse_args(argv)
|
|
201
|
+
return args.func(args, out or sys.stdout)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if __name__ == "__main__":
|
|
205
|
+
sys.exit(main())
|