cgreet 0.2.1__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.
- cgreet-0.2.1/.gitignore +10 -0
- cgreet-0.2.1/LICENSES/Apache-2.0.txt +202 -0
- cgreet-0.2.1/LICENSES/MIT.txt +21 -0
- cgreet-0.2.1/PKG-INFO +116 -0
- cgreet-0.2.1/README.md +100 -0
- cgreet-0.2.1/cgreet/__init__.py +91 -0
- cgreet-0.2.1/cgreet/__main__.py +50 -0
- cgreet-0.2.1/cgreet/_tables.py +38 -0
- cgreet-0.2.1/cgreet/py.typed +0 -0
- cgreet-0.2.1/pyproject.toml +26 -0
- cgreet-0.2.1/scripts/conformance.py +56 -0
- cgreet-0.2.1/scripts/consumer.py +104 -0
cgreet-0.2.1/.gitignore
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Julian Y. Richard Corbet
|
|
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.
|
cgreet-0.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: cgreet
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Deterministic locale-correct greeting and salutation helpers. No models, no I/O: same input always yields the same output
|
|
5
|
+
Project-URL: Homepage, https://github.com/corbet-labs/cgreet#readme
|
|
6
|
+
Project-URL: Repository, https://github.com/corbet-labs/cgreet
|
|
7
|
+
Project-URL: Issues, https://github.com/corbet-labs/cgreet/issues
|
|
8
|
+
License-Expression: MIT OR Apache-2.0
|
|
9
|
+
License-File: LICENSES/Apache-2.0.txt
|
|
10
|
+
License-File: LICENSES/MIT.txt
|
|
11
|
+
Keywords: correspondence,i18n,locale
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# cgreet
|
|
18
|
+
|
|
19
|
+
**German salutations with the right titles and punctuation.**
|
|
20
|
+
|
|
21
|
+
> **Release status:** 0.2.1 is being prepared. npm and Cargo currently publish 0.2.0. The compiled CommonJS/browser exports and Python/Typst release artifacts described below require the new release.
|
|
22
|
+
|
|
23
|
+
[](https://crates.io/crates/cgreet) [](https://www.npmjs.com/package/@corbet-labs/cgreet) [](https://docs.rs/cgreet) [](https://github.com/corbet-labs/cgreet/actions/workflows/ci.yml)
|
|
24
|
+
|
|
25
|
+
Turn an explicitly supplied honorific, academic titles, and surname into a formal salutation for Switzerland, Liechtenstein, Germany, or Austria. Deterministic rules, no model and no network calls.
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { deSalutation } from '@corbet-labs/cgreet';
|
|
29
|
+
|
|
30
|
+
deSalutation('Frau Dr. Müller', 'ch');
|
|
31
|
+
// Sehr geehrte Frau Dr. Müller
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
| Environment | Command |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| Rust / Cargo | `cargo add cgreet` |
|
|
39
|
+
| Node.js / npm | `npm install @corbet-labs/cgreet` |
|
|
40
|
+
| pnpm | `pnpm add @corbet-labs/cgreet` |
|
|
41
|
+
| Yarn | `yarn add @corbet-labs/cgreet` |
|
|
42
|
+
| Bun | `bun add @corbet-labs/cgreet` |
|
|
43
|
+
| Deno | `deno add npm:@corbet-labs/cgreet` |
|
|
44
|
+
|
|
45
|
+
The 0.2.1 JavaScript distribution includes compiled ESM, CommonJS,
|
|
46
|
+
TypeScript declarations, and a standalone browser module. Node.js 20+ is
|
|
47
|
+
supported; no TypeScript loader is required.
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
// CommonJS
|
|
51
|
+
const { deSalutation } = require('@corbet-labs/cgreet');
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<script type="module">
|
|
56
|
+
import { deSalutation } from 'https://cdn.jsdelivr.net/npm/@corbet-labs/cgreet@0.2.1/dist/browser.js';
|
|
57
|
+
console.log(deSalutation('Frau Dr. Müller', 'ch'));
|
|
58
|
+
</script>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Python wheels, source distributions, and CLI instructions are in the
|
|
62
|
+
[installation guide](https://github.com/corbet-labs/cgreet/blob/main/docs/installation.md).
|
|
63
|
+
JSR publication and Typst availability are listed there explicitly.
|
|
64
|
+
|
|
65
|
+
## Rust
|
|
66
|
+
|
|
67
|
+
```rust
|
|
68
|
+
use cgreet::{de_salutation, Region};
|
|
69
|
+
|
|
70
|
+
assert_eq!(de_salutation("Frau Dr. Müller", Region::Ch), "Sehr geehrte Frau Dr. Müller");
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Python
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from cgreet import de_salutation
|
|
77
|
+
|
|
78
|
+
assert de_salutation("Frau Dr. Müller", "ch") == 'Sehr geehrte Frau Dr. Müller'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## API
|
|
82
|
+
|
|
83
|
+
| Function | Purpose |
|
|
84
|
+
| --- | --- |
|
|
85
|
+
| `deSalutation` / `de_salutation` | Complete German salutation |
|
|
86
|
+
| `salutationHonorific`, `salutationTitles`, `salutationSurname` | Parse explicitly supplied recipient details |
|
|
87
|
+
| `parseRegion` / `parse_region` | Accept `ch`, `li`, `de`, or `at` |
|
|
88
|
+
| `recipientSalutationWarning`, `deHonorificWarning` | Report incomplete input |
|
|
89
|
+
|
|
90
|
+
Region codes are lowercase. German and Austrian salutations end with a comma; Swiss and Liechtenstein salutations do not. A recognized Professor title takes precedence over Dr. Missing honorifics or surnames produce the generic greeting. The library does not infer a person’s gender from their name.
|
|
91
|
+
|
|
92
|
+
## Correspondence family
|
|
93
|
+
|
|
94
|
+
| Library | Responsibility |
|
|
95
|
+
| --- | --- |
|
|
96
|
+
| [cletter](https://github.com/corbet-labs/cletter) | Compose the correspondence helpers |
|
|
97
|
+
| [cgreet](https://github.com/corbet-labs/cgreet) | German salutations and titles |
|
|
98
|
+
| [cfarewell](https://github.com/corbet-labs/cfarewell) | Locale-specific closings |
|
|
99
|
+
| [cdate](https://github.com/corbet-labs/cdate) | Calendar-date formatting |
|
|
100
|
+
| [cink](https://github.com/corbet-labs/cink) | Handwritten signature images |
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Development
|
|
104
|
+
|
|
105
|
+
Behavior is defined by [the locale tables](https://github.com/corbet-labs/cgreet/tree/main/tables)
|
|
106
|
+
and [shared conformance vectors](https://github.com/corbet-labs/cgreet/tree/main/tests/vectors).
|
|
107
|
+
Rust, JavaScript, and Python run the same vectors. CI also exercises installed
|
|
108
|
+
JavaScript tarballs across package managers and operating systems, and tests
|
|
109
|
+
Python wheels outside their source package.
|
|
110
|
+
|
|
111
|
+
See [the release guide](https://github.com/corbet-labs/cgreet/blob/main/docs/releasing.md)
|
|
112
|
+
for generation, verification, and publication commands.
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT OR Apache-2.0, at your option. Earlier releases through v0.1.0 retain their original FSL-1.1-ALv2 terms. See [LICENSES](https://github.com/corbet-labs/cgreet/tree/main/LICENSES).
|
cgreet-0.2.1/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# cgreet
|
|
2
|
+
|
|
3
|
+
**German salutations with the right titles and punctuation.**
|
|
4
|
+
|
|
5
|
+
> **Release status:** 0.2.1 is being prepared. npm and Cargo currently publish 0.2.0. The compiled CommonJS/browser exports and Python/Typst release artifacts described below require the new release.
|
|
6
|
+
|
|
7
|
+
[](https://crates.io/crates/cgreet) [](https://www.npmjs.com/package/@corbet-labs/cgreet) [](https://docs.rs/cgreet) [](https://github.com/corbet-labs/cgreet/actions/workflows/ci.yml)
|
|
8
|
+
|
|
9
|
+
Turn an explicitly supplied honorific, academic titles, and surname into a formal salutation for Switzerland, Liechtenstein, Germany, or Austria. Deterministic rules, no model and no network calls.
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { deSalutation } from '@corbet-labs/cgreet';
|
|
13
|
+
|
|
14
|
+
deSalutation('Frau Dr. Müller', 'ch');
|
|
15
|
+
// Sehr geehrte Frau Dr. Müller
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
| Environment | Command |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| Rust / Cargo | `cargo add cgreet` |
|
|
23
|
+
| Node.js / npm | `npm install @corbet-labs/cgreet` |
|
|
24
|
+
| pnpm | `pnpm add @corbet-labs/cgreet` |
|
|
25
|
+
| Yarn | `yarn add @corbet-labs/cgreet` |
|
|
26
|
+
| Bun | `bun add @corbet-labs/cgreet` |
|
|
27
|
+
| Deno | `deno add npm:@corbet-labs/cgreet` |
|
|
28
|
+
|
|
29
|
+
The 0.2.1 JavaScript distribution includes compiled ESM, CommonJS,
|
|
30
|
+
TypeScript declarations, and a standalone browser module. Node.js 20+ is
|
|
31
|
+
supported; no TypeScript loader is required.
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
// CommonJS
|
|
35
|
+
const { deSalutation } = require('@corbet-labs/cgreet');
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<script type="module">
|
|
40
|
+
import { deSalutation } from 'https://cdn.jsdelivr.net/npm/@corbet-labs/cgreet@0.2.1/dist/browser.js';
|
|
41
|
+
console.log(deSalutation('Frau Dr. Müller', 'ch'));
|
|
42
|
+
</script>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Python wheels, source distributions, and CLI instructions are in the
|
|
46
|
+
[installation guide](https://github.com/corbet-labs/cgreet/blob/main/docs/installation.md).
|
|
47
|
+
JSR publication and Typst availability are listed there explicitly.
|
|
48
|
+
|
|
49
|
+
## Rust
|
|
50
|
+
|
|
51
|
+
```rust
|
|
52
|
+
use cgreet::{de_salutation, Region};
|
|
53
|
+
|
|
54
|
+
assert_eq!(de_salutation("Frau Dr. Müller", Region::Ch), "Sehr geehrte Frau Dr. Müller");
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Python
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from cgreet import de_salutation
|
|
61
|
+
|
|
62
|
+
assert de_salutation("Frau Dr. Müller", "ch") == 'Sehr geehrte Frau Dr. Müller'
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API
|
|
66
|
+
|
|
67
|
+
| Function | Purpose |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `deSalutation` / `de_salutation` | Complete German salutation |
|
|
70
|
+
| `salutationHonorific`, `salutationTitles`, `salutationSurname` | Parse explicitly supplied recipient details |
|
|
71
|
+
| `parseRegion` / `parse_region` | Accept `ch`, `li`, `de`, or `at` |
|
|
72
|
+
| `recipientSalutationWarning`, `deHonorificWarning` | Report incomplete input |
|
|
73
|
+
|
|
74
|
+
Region codes are lowercase. German and Austrian salutations end with a comma; Swiss and Liechtenstein salutations do not. A recognized Professor title takes precedence over Dr. Missing honorifics or surnames produce the generic greeting. The library does not infer a person’s gender from their name.
|
|
75
|
+
|
|
76
|
+
## Correspondence family
|
|
77
|
+
|
|
78
|
+
| Library | Responsibility |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| [cletter](https://github.com/corbet-labs/cletter) | Compose the correspondence helpers |
|
|
81
|
+
| [cgreet](https://github.com/corbet-labs/cgreet) | German salutations and titles |
|
|
82
|
+
| [cfarewell](https://github.com/corbet-labs/cfarewell) | Locale-specific closings |
|
|
83
|
+
| [cdate](https://github.com/corbet-labs/cdate) | Calendar-date formatting |
|
|
84
|
+
| [cink](https://github.com/corbet-labs/cink) | Handwritten signature images |
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
Behavior is defined by [the locale tables](https://github.com/corbet-labs/cgreet/tree/main/tables)
|
|
90
|
+
and [shared conformance vectors](https://github.com/corbet-labs/cgreet/tree/main/tests/vectors).
|
|
91
|
+
Rust, JavaScript, and Python run the same vectors. CI also exercises installed
|
|
92
|
+
JavaScript tarballs across package managers and operating systems, and tests
|
|
93
|
+
Python wheels outside their source package.
|
|
94
|
+
|
|
95
|
+
See [the release guide](https://github.com/corbet-labs/cgreet/blob/main/docs/releasing.md)
|
|
96
|
+
for generation, verification, and publication commands.
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT OR Apache-2.0, at your option. Earlier releases through v0.1.0 retain their original FSL-1.1-ALv2 terms. See [LICENSES](https://github.com/corbet-labs/cgreet/tree/main/LICENSES).
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""German salutations for Switzerland, Liechtenstein, Germany, and Austria."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from typing import Literal
|
|
5
|
+
|
|
6
|
+
from ._tables import TABLES
|
|
7
|
+
|
|
8
|
+
Region = Literal["ch", "li", "de", "at"]
|
|
9
|
+
_DE = TABLES["de"]
|
|
10
|
+
_WS = re.compile(r"[\u0009-\u000d\u0020\u0085\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]+")
|
|
11
|
+
_ASCII_LOWER = str.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")
|
|
12
|
+
|
|
13
|
+
__all__ = ["parse_region", "region_uses_comma", "salutation_last_name",
|
|
14
|
+
"salutation_honorific", "salutation_titles", "salutation_surname",
|
|
15
|
+
"de_salutation", "recipient_salutation_warning", "de_honorific_warning"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _tokens(name: str) -> list[str]:
|
|
19
|
+
return [token for token in _WS.split(name) if token]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _norm(token: str) -> str:
|
|
23
|
+
return token.strip(".").translate(_ASCII_LOWER)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def parse_region(code: str) -> Region | None:
|
|
27
|
+
"""Accept only the four lowercase region codes."""
|
|
28
|
+
return code if code in ("ch", "li", "de", "at") else None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def region_uses_comma(region: Region) -> bool:
|
|
32
|
+
"""Whether a German salutation ends with a comma."""
|
|
33
|
+
return region in _DE["comma_regions"]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def salutation_last_name(name: str) -> str:
|
|
37
|
+
"""Last whitespace-separated token, or an empty string."""
|
|
38
|
+
tokens = _tokens(name)
|
|
39
|
+
return tokens[-1] if tokens else ""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def salutation_honorific(name: str) -> str:
|
|
43
|
+
"""Explicit Herr/Herrn or Frau; never infer an honorific from a name."""
|
|
44
|
+
tokens = _tokens(name)
|
|
45
|
+
return _DE["honorifics"].get(_norm(tokens[0]), "") if tokens else ""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def salutation_titles(name: str) -> list[str]:
|
|
49
|
+
"""Keep recognized academic titles, with Professor taking precedence."""
|
|
50
|
+
kept = []
|
|
51
|
+
for token in _tokens(name):
|
|
52
|
+
title = _DE["titles"].get(_norm(token))
|
|
53
|
+
if title is not None and title not in kept:
|
|
54
|
+
kept.append(title)
|
|
55
|
+
for title in kept:
|
|
56
|
+
if title in _DE["sole_titles"]:
|
|
57
|
+
return [title]
|
|
58
|
+
return kept
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def salutation_surname(name: str) -> str:
|
|
62
|
+
"""Last token after excluding honorifics, titles, and qualifications."""
|
|
63
|
+
return next((token for token in reversed(_tokens(name)) if _norm(token) not in _DE["filler"]), "")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def de_salutation(name: str, region: Region) -> str:
|
|
67
|
+
"""Format a German salutation, using the generic address when incomplete."""
|
|
68
|
+
if parse_region(region) is None:
|
|
69
|
+
raise ValueError("region must be ch, li, de, or at")
|
|
70
|
+
punct = "," if region_uses_comma(region) else ""
|
|
71
|
+
honorific, surname = salutation_honorific(name), salutation_surname(name)
|
|
72
|
+
if not honorific or not surname:
|
|
73
|
+
return _DE["generic"] + punct
|
|
74
|
+
titles = salutation_titles(name)
|
|
75
|
+
title_part = " " + " ".join(titles) if titles else ""
|
|
76
|
+
address = "Sehr geehrte Frau" if honorific == "frau" else "Sehr geehrter Herr"
|
|
77
|
+
return f"{address}{title_part} {surname}{punct}"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def recipient_salutation_warning(location: str, name: str) -> str | None:
|
|
81
|
+
"""Advisory for an empty recipient name."""
|
|
82
|
+
if salutation_last_name(name) == "":
|
|
83
|
+
return f"{location}: job.cl_recipient.name is empty; using generic salutation (provide a name for tailored opportunities)"
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def de_honorific_warning(location: str, name: str) -> str | None:
|
|
88
|
+
"""Advisory for a nonempty German name without a usable honorific."""
|
|
89
|
+
if salutation_last_name(name) and (not salutation_honorific(name) or not salutation_surname(name)):
|
|
90
|
+
return f'{location}: job.cl_recipient.name has no parsable Herr/Frau honorific; using generic salutation (provide e.g. "Frau Dr. Müller" for tailored opportunities)'
|
|
91
|
+
return None
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""JSON command-line bridge for callers in any programming language."""
|
|
2
|
+
import argparse
|
|
3
|
+
import base64
|
|
4
|
+
import dataclasses
|
|
5
|
+
import json
|
|
6
|
+
import sys
|
|
7
|
+
import cgreet as api
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _json_default(value):
|
|
11
|
+
if dataclasses.is_dataclass(value):
|
|
12
|
+
return dataclasses.asdict(value)
|
|
13
|
+
if isinstance(value, bytes):
|
|
14
|
+
return base64.b64encode(value).decode("ascii")
|
|
15
|
+
raise TypeError(f"Cannot serialize {type(value).__name__}")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _reject_constant(value):
|
|
19
|
+
raise ValueError(f"{value} is not a JSON number")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main():
|
|
23
|
+
parser = argparse.ArgumentParser(description="Call cgreet functions with JSON arguments.")
|
|
24
|
+
parser.add_argument("function", choices=api.__all__)
|
|
25
|
+
parser.add_argument("arguments", nargs="?", default="[]", help="JSON array of positional arguments or object of keyword arguments; '-' reads UTF-8 stdin")
|
|
26
|
+
args = parser.parse_args()
|
|
27
|
+
try:
|
|
28
|
+
values = json.loads(sys.stdin.buffer.read().decode("utf-8") if args.arguments == "-" else args.arguments, parse_constant=_reject_constant)
|
|
29
|
+
if not isinstance(values, (list, dict)):
|
|
30
|
+
raise ValueError("arguments must be a JSON array or object")
|
|
31
|
+
# Image operations accept the JSON object returned by normalize.
|
|
32
|
+
if args.function in ("exceeds_limits", "scale_to_fit", "signature_size"):
|
|
33
|
+
raw = values[0] if isinstance(values, list) else values["image"]
|
|
34
|
+
if isinstance(raw, dict):
|
|
35
|
+
raw = dict(raw)
|
|
36
|
+
raw["bytes"] = base64.b64decode(raw["bytes"], validate=True)
|
|
37
|
+
image = api.DecodedImage(**raw)
|
|
38
|
+
if isinstance(values, list):
|
|
39
|
+
values[0] = image
|
|
40
|
+
else:
|
|
41
|
+
values["image"] = image
|
|
42
|
+
fn = getattr(api, args.function)
|
|
43
|
+
result = fn(*values) if isinstance(values, list) else fn(**values)
|
|
44
|
+
print(json.dumps(result, default=_json_default, ensure_ascii=True, allow_nan=False))
|
|
45
|
+
except (ValueError, TypeError, KeyError, IndexError, AttributeError, OverflowError) as error:
|
|
46
|
+
parser.error(str(error))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if __name__ == "__main__":
|
|
50
|
+
main()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Generated by scripts/sync-python.py; edit tables/*.json instead.
|
|
2
|
+
TABLES = {'de': {'locale': 'de',
|
|
3
|
+
'source_norms': 'SN 010130 for ch/li, DIN 5008 for de/at (at follows DIN since ÖNORM A '
|
|
4
|
+
'1080 was withdrawn in 2018)',
|
|
5
|
+
'honorifics': {'frau': 'frau', 'herr': 'herr', 'herrn': 'herr'},
|
|
6
|
+
'titles': {'dr': 'Dr.',
|
|
7
|
+
'prof': 'Professor',
|
|
8
|
+
'professor': 'Professor',
|
|
9
|
+
'dipl-ing': 'Dipl.-Ing.',
|
|
10
|
+
'dipling': 'Dipl.-Ing.',
|
|
11
|
+
'mag': 'Mag.',
|
|
12
|
+
'magister': 'Mag.',
|
|
13
|
+
'dipl.-ing': 'Dipl.-Ing.',
|
|
14
|
+
'dipl.ing': 'Dipl.-Ing.'},
|
|
15
|
+
'sole_titles': ['Professor'],
|
|
16
|
+
'filler': ['herr',
|
|
17
|
+
'herrn',
|
|
18
|
+
'frau',
|
|
19
|
+
'mr',
|
|
20
|
+
'mrs',
|
|
21
|
+
'ms',
|
|
22
|
+
'miss',
|
|
23
|
+
'dr',
|
|
24
|
+
'prof',
|
|
25
|
+
'professor',
|
|
26
|
+
'dipl-ing',
|
|
27
|
+
'dipling',
|
|
28
|
+
'mag',
|
|
29
|
+
'magister',
|
|
30
|
+
'phd',
|
|
31
|
+
'ma',
|
|
32
|
+
'ba',
|
|
33
|
+
'bsc',
|
|
34
|
+
'msc',
|
|
35
|
+
'dipl.-ing',
|
|
36
|
+
'dipl.ing'],
|
|
37
|
+
'comma_regions': ['de', 'at'],
|
|
38
|
+
'generic': 'Sehr geehrte Damen und Herren'}}
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27,<2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "cgreet"
|
|
7
|
+
version = "0.2.1"
|
|
8
|
+
description = "Deterministic locale-correct greeting and salutation helpers. No models, no I/O: same input always yields the same output"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT OR Apache-2.0"
|
|
11
|
+
license-files = ["LICENSES/*"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
keywords = ["i18n", "correspondence", "locale"]
|
|
14
|
+
classifiers = ["Programming Language :: Python :: 3", "Operating System :: OS Independent"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://github.com/corbet-labs/cgreet#readme"
|
|
19
|
+
Repository = "https://github.com/corbet-labs/cgreet"
|
|
20
|
+
Issues = "https://github.com/corbet-labs/cgreet/issues"
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
cgreet = "cgreet.__main__:main"
|
|
24
|
+
|
|
25
|
+
[tool.hatch.build.targets.wheel]
|
|
26
|
+
packages = ["cgreet"]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Run canonical vectors against either the source port or an installed wheel."""
|
|
2
|
+
import base64
|
|
3
|
+
import importlib
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
ROOT = Path(__file__).resolve().parents[2]
|
|
9
|
+
if "--installed" not in sys.argv:
|
|
10
|
+
sys.path.insert(0, str(ROOT / "py"))
|
|
11
|
+
api = importlib.import_module("cgreet")
|
|
12
|
+
|
|
13
|
+
ARGUMENTS = {
|
|
14
|
+
"region_parse": ["input"], "region_uses_comma": ["input"],
|
|
15
|
+
"salutation_last_name": ["input"], "salutation_honorific": ["input"],
|
|
16
|
+
"salutation_titles": ["input"], "salutation_surname": ["input"],
|
|
17
|
+
"de_salutation": ["input", "region"],
|
|
18
|
+
"recipient_salutation_warning": ["location", "input"],
|
|
19
|
+
"de_honorific_warning": ["location", "input"],
|
|
20
|
+
"closing": ["locale", "override"], "available_locales": [],
|
|
21
|
+
"long_date": ["locale", "year", "month", "day"],
|
|
22
|
+
"medium_date": ["locale", "year", "month", "day"],
|
|
23
|
+
"short_date": ["locale", "year", "month", "day"],
|
|
24
|
+
"month_year": ["locale", "year", "month"], "is_supported": ["locale"],
|
|
25
|
+
"supported_formats": [], "normalize": ["input"],
|
|
26
|
+
"exceeds_limits": ["image", "max_pixels"], "scale_to_fit": ["image", "max_pixels"],
|
|
27
|
+
"signature_size": ["image", "height_pt", "max_width_pt"],
|
|
28
|
+
"image_snippet": ["path", "height_pt", "width_pt"],
|
|
29
|
+
"resolve_locale": ["language", "location"],
|
|
30
|
+
"opening": ["locale", "person", "override"],
|
|
31
|
+
"subject": ["locale", "title", "prefix_override"],
|
|
32
|
+
"salutation": ["locale", "person"], "apply_ortho": ["locale", "text"],
|
|
33
|
+
"warnings": ["location", "locale", "person"],
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
files = sorted((ROOT / "tests/vectors").glob("*.json"))
|
|
37
|
+
assert files, "No conformance vectors"
|
|
38
|
+
count = 0
|
|
39
|
+
for file in files:
|
|
40
|
+
for vector in json.loads(file.read_text(encoding="utf-8")):
|
|
41
|
+
name = vector["fn"]
|
|
42
|
+
values = dict(vector)
|
|
43
|
+
if "fixture" in vector:
|
|
44
|
+
values["input"] = base64.b64encode((ROOT / "tests/fixtures" / vector["fixture"]).read_bytes()).decode("ascii")
|
|
45
|
+
if name != "normalize":
|
|
46
|
+
values["image"] = api.normalize(values["input"])
|
|
47
|
+
fn = getattr(api, "parse_region" if name == "region_parse" else name)
|
|
48
|
+
actual = fn(*(values.get(key) for key in ARGUMENTS[name]))
|
|
49
|
+
if name == "normalize" and actual is not None:
|
|
50
|
+
actual = {key: getattr(actual, key) for key in ("mime", "width", "height")}
|
|
51
|
+
if isinstance(actual, tuple):
|
|
52
|
+
actual = list(actual)
|
|
53
|
+
if actual != vector["expected"]:
|
|
54
|
+
raise AssertionError(f"{file.name} :: {vector['name']}: {actual!r} != {vector['expected']!r}")
|
|
55
|
+
count += 1
|
|
56
|
+
print(f"Python cgreet: {count} vectors passed across {len(files)} files")
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Verify wheel/sdist contents and installed Python/console entrypoints.
|
|
2
|
+
|
|
3
|
+
Run with the interpreter in a fresh environment containing the wheel and its
|
|
4
|
+
declared dependencies. This script never adds the source package to sys.path.
|
|
5
|
+
"""
|
|
6
|
+
import argparse
|
|
7
|
+
import base64
|
|
8
|
+
from email.parser import BytesParser
|
|
9
|
+
import importlib
|
|
10
|
+
import importlib.metadata
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
import tarfile
|
|
17
|
+
import tempfile
|
|
18
|
+
import zipfile
|
|
19
|
+
|
|
20
|
+
ROOT = Path(__file__).resolve().parents[2]
|
|
21
|
+
PACKAGES = [path.name for path in (ROOT / "py").iterdir() if (path / "__init__.py").is_file()]
|
|
22
|
+
if len(PACKAGES) != 1:
|
|
23
|
+
raise RuntimeError("Expected exactly one source package")
|
|
24
|
+
NAME = PACKAGES[0]
|
|
25
|
+
CASES = {
|
|
26
|
+
"cgreet": ("de_salutation", ["Frau Dr. Müller", "ch"],
|
|
27
|
+
{"name": "Frau Dr. Müller", "region": "ch"}, "Sehr geehrte Frau Dr. Müller"),
|
|
28
|
+
"cfarewell": ("closing", ["DE-LI"], {"locale": "DE-LI"}, "Freundliche Grüsse"),
|
|
29
|
+
"cdate": ("long_date", ["EN-GB", 2026, 9, 7],
|
|
30
|
+
{"locale": "EN-GB", "year": 2026, "month": 9, "day": 7}, "7 September 2026"),
|
|
31
|
+
"cink": ("image_snippet", ["signature.png", 20],
|
|
32
|
+
{"path": "signature.png", "height_pt": 20}, '#image("signature.png", height: 20pt)'),
|
|
33
|
+
"cletter": ("salutation", ["DE-LI", "Frau Dr. Müller"],
|
|
34
|
+
{"locale": "DE-LI", "name": "Frau Dr. Müller"}, "Sehr geehrte Frau Dr. Müller"),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def check(condition, message):
|
|
39
|
+
if not condition:
|
|
40
|
+
raise AssertionError(message)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
44
|
+
parser.add_argument("--wheel", type=Path, required=True)
|
|
45
|
+
parser.add_argument("--sdist", type=Path, required=True)
|
|
46
|
+
args = parser.parse_args()
|
|
47
|
+
licenses = {path.name: path.read_bytes() for path in (ROOT / "LICENSES").iterdir() if path.is_file()}
|
|
48
|
+
check(bool(licenses), "Source licenses are missing")
|
|
49
|
+
with zipfile.ZipFile(args.wheel) as wheel:
|
|
50
|
+
files = wheel.namelist()
|
|
51
|
+
check(f"{NAME}/py.typed" in files, "Wheel is missing py.typed")
|
|
52
|
+
metadata_paths = [path for path in files if path.endswith(".dist-info/METADATA")]
|
|
53
|
+
check(len(metadata_paths) == 1, "Expected one wheel distribution")
|
|
54
|
+
metadata = BytesParser().parsebytes(wheel.read(metadata_paths[0]))
|
|
55
|
+
check(metadata["Name"] == NAME, "Wheel package name differs from repository")
|
|
56
|
+
for name, expected in licenses.items():
|
|
57
|
+
check(any(path.endswith("/LICENSES/" + name) and wheel.read(path) == expected for path in files),
|
|
58
|
+
f"Wheel is missing the original {name}")
|
|
59
|
+
with tarfile.open(args.sdist, "r:gz") as sdist:
|
|
60
|
+
files = {member.name: member for member in sdist.getmembers() if member.isfile()}
|
|
61
|
+
for name, expected in licenses.items():
|
|
62
|
+
check(any(path.endswith("/LICENSES/" + name) and sdist.extractfile(member).read() == expected
|
|
63
|
+
for path, member in files.items()), f"Source distribution is missing {name}")
|
|
64
|
+
|
|
65
|
+
distribution = importlib.metadata.distribution(NAME)
|
|
66
|
+
check(distribution.version == metadata["Version"], "Installed version differs from wheel")
|
|
67
|
+
check(any(entry.group == "console_scripts" and entry.name == NAME and entry.value == f"{NAME}.__main__:main"
|
|
68
|
+
for entry in distribution.entry_points), "Missing console entrypoint metadata")
|
|
69
|
+
api = importlib.import_module(NAME)
|
|
70
|
+
check(not Path(api.__file__).resolve().is_relative_to(ROOT / "py"), "Imported source tree instead of installed wheel")
|
|
71
|
+
entrypoint = Path(sys.executable).parent / (NAME + (".exe" if os.name == "nt" else ""))
|
|
72
|
+
check(entrypoint.is_file(), "Installer did not create the console entrypoint")
|
|
73
|
+
function, positional, keywords, expected = CASES[NAME]
|
|
74
|
+
|
|
75
|
+
with tempfile.TemporaryDirectory(prefix=f"{NAME}-python-consumer-") as cwd:
|
|
76
|
+
def call(command, function, values, *, stdin=False, valid=True):
|
|
77
|
+
payload = values if isinstance(values, str) else json.dumps(values, ensure_ascii=False)
|
|
78
|
+
result = subprocess.run(command + [function, "-" if stdin else payload],
|
|
79
|
+
input=payload if stdin else None, cwd=cwd, text=True,
|
|
80
|
+
encoding="utf-8", capture_output=True, timeout=30)
|
|
81
|
+
if valid:
|
|
82
|
+
check(result.returncode == 0, result.stderr)
|
|
83
|
+
return json.loads(result.stdout)
|
|
84
|
+
check(result.returncode == 2 and not result.stdout and "Traceback" not in result.stderr,
|
|
85
|
+
f"Invalid arguments did not produce a clean CLI error: {result}")
|
|
86
|
+
|
|
87
|
+
for command in ([sys.executable, "-m", NAME], [str(entrypoint)]):
|
|
88
|
+
check(call(command, function, positional) == expected, "Positional JSON invocation failed")
|
|
89
|
+
check(call(command, function, keywords, stdin=True) == expected, "Keyword/stdin invocation failed")
|
|
90
|
+
call(command, function, "null", valid=False)
|
|
91
|
+
call(command, function, "[NaN]", valid=False)
|
|
92
|
+
call(command, function, [], valid=False)
|
|
93
|
+
if NAME in ("cink", "cletter"):
|
|
94
|
+
encoded = base64.b64encode(b'<svg xmlns="http://www.w3.org/2000/svg"/>').decode("ascii")
|
|
95
|
+
decoded = call([str(entrypoint)], "normalize", [encoded])
|
|
96
|
+
check(decoded["bytes"] == encoded and decoded["mime"] == "svg", "Image JSON output lost encoded bytes")
|
|
97
|
+
check(call([str(entrypoint)], "signature_size", {"image": decoded, "height_pt": 20}) is None,
|
|
98
|
+
"Image JSON output cannot be used as a subsequent input")
|
|
99
|
+
raster = {"mime": "png", "width": 1, "height": 1, "bytes": ""}
|
|
100
|
+
check(call([str(entrypoint)], "signature_size", {"image": raster, "height_pt": 10**400}) is None,
|
|
101
|
+
"An unrepresentable height escaped the JSON bridge")
|
|
102
|
+
check(call([str(entrypoint)], "signature_size", {"image": raster, "height_pt": 20, "max_width_pt": 10**400}) is None,
|
|
103
|
+
"An unrepresentable maximum width escaped the JSON bridge")
|
|
104
|
+
print(f"Python {NAME}: installed module, console JSON calls, wheel/sdist licenses and metadata passed")
|