verso-core 0.1.39__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. verso_core-0.1.39/LICENSE +201 -0
  2. verso_core-0.1.39/NOTICE +13 -0
  3. verso_core-0.1.39/PKG-INFO +31 -0
  4. verso_core-0.1.39/README.md +7 -0
  5. verso_core-0.1.39/pyproject.toml +47 -0
  6. verso_core-0.1.39/setup.cfg +4 -0
  7. verso_core-0.1.39/src/verso/core/__init__.py +1 -0
  8. verso_core-0.1.39/src/verso/core/cli.py +230 -0
  9. verso_core-0.1.39/src/verso/core/corpus_data.py +149 -0
  10. verso_core-0.1.39/src/verso/core/i18n.py +477 -0
  11. verso_core-0.1.39/src/verso/core/locales/en.toml +231 -0
  12. verso_core-0.1.39/src/verso/core/locales/ru.toml +232 -0
  13. verso_core-0.1.39/src/verso/core/messages.py +15 -0
  14. verso_core-0.1.39/src/verso/core/pipeline/__init__.py +15 -0
  15. verso_core-0.1.39/src/verso/core/pipeline/config.py +83 -0
  16. verso_core-0.1.39/src/verso/core/pipeline/load.py +296 -0
  17. verso_core-0.1.39/src/verso/core/pipeline/records.py +340 -0
  18. verso_core-0.1.39/src/verso/core/places.py +352 -0
  19. verso_core-0.1.39/src/verso/core/plugins.py +419 -0
  20. verso_core-0.1.39/src/verso/core/py.typed +0 -0
  21. verso_core-0.1.39/src/verso/core/ratchet.py +491 -0
  22. verso_core-0.1.39/src/verso/core/records/__init__.py +14 -0
  23. verso_core-0.1.39/src/verso/core/records/decode.py +224 -0
  24. verso_core-0.1.39/src/verso/core/records/encode.py +337 -0
  25. verso_core-0.1.39/src/verso/core/records/fields.py +521 -0
  26. verso_core-0.1.39/src/verso/core/records/graph.py +75 -0
  27. verso_core-0.1.39/src/verso/core/records/ids.py +232 -0
  28. verso_core-0.1.39/src/verso/core/records/notes.py +174 -0
  29. verso_core-0.1.39/src/verso/core/records/replay.py +362 -0
  30. verso_core-0.1.39/src/verso/core/records/schema.py +307 -0
  31. verso_core-0.1.39/src/verso/core/records/sets.py +22 -0
  32. verso_core-0.1.39/src/verso/core/records/ui.py +521 -0
  33. verso_core-0.1.39/src/verso/core/targets/__init__.py +1 -0
  34. verso_core-0.1.39/src/verso/core/targets/geni/__init__.py +15 -0
  35. verso_core-0.1.39/src/verso/core/targets/geni/about.py +29 -0
  36. verso_core-0.1.39/src/verso/core/targets/geni/consolidation_conflicts.py +300 -0
  37. verso_core-0.1.39/src/verso/core/targets/geni/date.py +125 -0
  38. verso_core-0.1.39/src/verso/core/targets/geni/event.py +41 -0
  39. verso_core-0.1.39/src/verso/core/targets/geni/held.py +20 -0
  40. verso_core-0.1.39/src/verso/core/targets/geni/profile.py +189 -0
  41. verso_core-0.1.39/src/verso/core/targets/geni/redundant_additional_info.py +106 -0
  42. verso_core-0.1.39/src/verso/core/targets/geni/redundant_ignores.py +101 -0
  43. verso_core-0.1.39/src/verso/core/targets/geni/redundant_overrides.py +122 -0
  44. verso_core-0.1.39/src/verso/core/targets/geni/redundant_preferences.py +179 -0
  45. verso_core-0.1.39/src/verso/core/targets/geni/union.py +99 -0
  46. verso_core-0.1.39/src/verso/core/tools.py +57 -0
  47. verso_core-0.1.39/src/verso/core/workspace.py +392 -0
  48. verso_core-0.1.39/src/verso/core/written.py +86 -0
  49. verso_core-0.1.39/src/verso_core.egg-info/PKG-INFO +31 -0
  50. verso_core-0.1.39/src/verso_core.egg-info/SOURCES.txt +52 -0
  51. verso_core-0.1.39/src/verso_core.egg-info/dependency_links.txt +1 -0
  52. verso_core-0.1.39/src/verso_core.egg-info/entry_points.txt +2 -0
  53. verso_core-0.1.39/src/verso_core.egg-info/requires.txt +3 -0
  54. verso_core-0.1.39/src/verso_core.egg-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,13 @@
1
+ Verso
2
+ Copyright 2026 Dmitry Malchikov
3
+
4
+ Licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ verso-ru includes verso/ru/church_calendar/data/svyatcy_1906.tsv, derived from the
7
+ «Алфавитъ именъ всѣхъ святыхъ» of the 1906 Требник as digitised in
8
+ https://github.com/slavonic/cu-md-sandbox — Copyright (c) 2018 Slavonic Computing
9
+ Initiative, MIT License; the full text is in verso/ru/church_calendar/data/LICENSE.svyatcy.
10
+
11
+ verso-app includes icons from Lucide (https://lucide.dev) — Copyright (c) Lucide Icons and
12
+ Contributors, ISC License; the icons derived from Feather, Copyright (c) Cole Bemis, MIT License;
13
+ the full text is in verso/app/static/LICENSE.lucide.
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.4
2
+ Name: verso-core
3
+ Version: 0.1.39
4
+ Summary: verso's core: workspace, plugin registry, records JSON, review ratchet, Geni models and the verso command.
5
+ Author: Dmitry Malchikov
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/verso-genealogy/verso
8
+ Project-URL: Issues, https://github.com/verso-genealogy/verso/issues
9
+ Keywords: genealogy,metric books,revision lists,russian empire,geni
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Natural Language :: Russian
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Topic :: Sociology :: Genealogy
17
+ Requires-Python: >=3.14
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ License-File: NOTICE
21
+ Provides-Extra: schema
22
+ Requires-Dist: jsonschema==4.26.0; extra == "schema"
23
+ Dynamic: license-file
24
+
25
+ # verso-core
26
+
27
+ The core of the verso genealogy library: the workspace, the plugin registry, the records
28
+ JSON, the review ratchet, Geni's HCL models and the `verso` command. It knows no language of
29
+ the records; a plugin (`verso-ru`) brings one.
30
+
31
+ Part of verso — https://github.com/verso-genealogy/verso
@@ -0,0 +1,7 @@
1
+ # verso-core
2
+
3
+ The core of the verso genealogy library: the workspace, the plugin registry, the records
4
+ JSON, the review ratchet, Geni's HCL models and the `verso` command. It knows no language of
5
+ the records; a plugin (`verso-ru`) brings one.
6
+
7
+ Part of verso — https://github.com/verso-genealogy/verso
@@ -0,0 +1,47 @@
1
+ # verso-core: what knows no language of the records — the workspace, the plugin registry,
2
+ # the pipeline's loading, the records JSON's codec, the places and the corpus's data, the review
3
+ # ratchet's mechanism, Geni's HCL models and `verso <команда>`. It loads no third-party package;
4
+ # `[schema]` is for `verso records-schema --validate`.
5
+ [build-system]
6
+ requires = ["setuptools>=77"]
7
+ build-backend = "setuptools.build_meta"
8
+
9
+ [project]
10
+ name = "verso-core"
11
+ version = "0.1.39"
12
+ description = "verso's core: workspace, plugin registry, records JSON, review ratchet, Geni models and the verso command."
13
+ requires-python = ">=3.14"
14
+ license = "Apache-2.0"
15
+ license-files = ["LICENSE", "NOTICE"]
16
+ authors = [{ name = "Dmitry Malchikov" }]
17
+ readme = "README.md"
18
+ keywords = ["genealogy", "metric books", "revision lists", "russian empire", "geni"]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Intended Audience :: Science/Research",
22
+ "Natural Language :: Russian",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python :: 3 :: Only",
25
+ "Programming Language :: Python :: 3.14",
26
+ "Topic :: Sociology :: Genealogy",
27
+ ]
28
+ dependencies = []
29
+
30
+ [project.urls]
31
+ Repository = "https://github.com/verso-genealogy/verso"
32
+ Issues = "https://github.com/verso-genealogy/verso/issues"
33
+
34
+ [project.optional-dependencies]
35
+ schema = ["jsonschema==4.26.0"]
36
+
37
+ [project.scripts]
38
+ verso = "verso.core.cli:main"
39
+
40
+ # `verso` is a namespace package (PEP 420) shared with verso-ru, verso-app and verso-app-dsl.
41
+ [tool.setuptools.packages.find]
42
+ where = ["src"]
43
+ include = ["verso.core*"]
44
+
45
+ # The interface's catalogs (verso.core.i18n).
46
+ [tool.setuptools.package-data]
47
+ "verso.core" = ["locales/*.toml", "py.typed"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ """The library's core: what any corpus needs — the workspace, the pipeline, the records JSON, the ratchet, the Geni models."""
@@ -0,0 +1,230 @@
1
+ """`verso <команда>`: one command for each module of the library that runs as a program.
2
+
3
+ A command is its module's name with hyphens — `verso generate-tf` is
4
+ `python -m verso.ru.cli.generate_tf` —, but for five names too general to stand alone
5
+ (`records-schema`, `ui-schema`, `verify-batch`, `validate-import`, `import-sheets`). The module runs as
6
+ `__main__` through runpy, so it reads its arguments, prints and exits as under `python -m`,
7
+ but that its usage names the program `verso <команда>`.
8
+ `--lang LANG` speaks LANG: it is `VERSO_LANG=LANG` for this command (`verso.core.i18n`).
9
+ `--workspace DIR` runs it in that workspace: it is `VERSO_WORKSPACE=DIR` for this command
10
+ — a `workspace.use()` here would not reach `verso workspace`, which runpy runs as a second
11
+ copy of the module, and this module imports nothing of the library for that reason.
12
+
13
+ The core's four commands are here; each installed plugin brings its own (`Plugin.commands`),
14
+ found by the registry without a workspace: `verso --help` lists them all, the core's
15
+ first, then each plugin's by its name. The tables are strings: the core imports none of the
16
+ commands' modules.
17
+ """
18
+ from __future__ import annotations
19
+
20
+ import argparse
21
+ import os
22
+ import re
23
+ import runpy
24
+ import sys
25
+ from collections.abc import Generator, Mapping
26
+ from contextlib import contextmanager
27
+ from pathlib import Path
28
+ from typing import Any
29
+
30
+ from verso.core.i18n import Message
31
+ from verso.core.messages import t
32
+
33
+ # verso.core.workspace's ENV and CONFIG; importing the module would make `verso workspace` a
34
+ # second copy of it (runpy warns, and the copy's own use() stack would be another one).
35
+ _ENV = "VERSO_WORKSPACE"
36
+ _CONFIG = "verso.toml"
37
+
38
+ # The core's own commands; each installed plugin brings its own (`Plugin.commands`).
39
+ COMMANDS: dict[str, str] = {
40
+ "records-schema": "verso.core.records.schema",
41
+ "tools": "verso.core.tools",
42
+ "ui-schema": "verso.core.records.ui",
43
+ "workspace": "verso.core.workspace",
44
+ }
45
+
46
+
47
+ def _say(message: object) -> str:
48
+ """A message's text in the workspace's language: the workspace is imported here, to say
49
+ it, and never before a command runs — `verso workspace` runs that module as `__main__`."""
50
+ import verso.core.workspace # noqa: F401 — it tells verso.core.i18n where the language comes from
51
+ return str(message)
52
+
53
+
54
+ def _plugins() -> list[tuple[str, Mapping[str, str]]]:
55
+ """Each installed plugin's name and commands, by name. The registry reads no workspace:
56
+ a command is found wherever verso is run, `verso --help` with no workspace at all."""
57
+ from verso.core import plugins
58
+ return [(name, plugin.commands) for name, plugin in plugins.installed().items()]
59
+
60
+
61
+ def commands() -> dict[str, str]:
62
+ """Every command: the core's, then each installed plugin's — refused when two name one."""
63
+ from verso.core.plugins import PluginError
64
+ out, owner = dict(COMMANDS), dict.fromkeys(COMMANDS, "")
65
+ for name, given in _plugins():
66
+ for command, module in given.items():
67
+ if command in owner:
68
+ where = t("cli.where_plugins", first=owner[command], second=name) if owner[command] \
69
+ else t("cli.where_core", plugin=name)
70
+ raise PluginError(t("cli.command_twice", command=command, where=where))
71
+ out[command], owner[command] = module, name
72
+ return out
73
+
74
+
75
+ class _Parser(argparse.ArgumentParser):
76
+ """verso's own parser: its texts are the catalog's, put together only when the help or the
77
+ usage is printed — a command that prints neither never asks for the language, nor so reads the
78
+ workspace (`verso workspace` runs that module as `__main__`)."""
79
+
80
+ def __init__(self, groups: list[tuple[Message, dict[str, str]]], **kwargs: Any) -> None:
81
+ super().__init__(**kwargs)
82
+ self.groups = groups
83
+ self.lazy: list[tuple[object, str, Message]] = [] # (what, its attribute, the text)
84
+
85
+ def text(self, what: object, attribute: str, message: Message) -> None:
86
+ self.lazy.append((what, attribute, message))
87
+
88
+ @contextmanager
89
+ def _rendered(self) -> Generator[None]:
90
+ width = max(len(name) for _, given in self.groups for name in given)
91
+ listing = "\n\n".join(f"{_say(title)}:\n" + "\n".join(f" {name:<{width}} {module}" for name, module in given.items())
92
+ for title, given in self.groups if given)
93
+ if len(self.groups) == 1:
94
+ listing += f"\n\n{_say(t('cli.no_plugins'))}"
95
+ texts = [*self.lazy, (self, "epilog", t("cli.epilog", listing=listing))]
96
+ before = [(what, attribute, getattr(what, attribute)) for what, attribute, _ in texts]
97
+ for what, attribute, message in texts:
98
+ setattr(what, attribute, _say(message))
99
+ try:
100
+ yield
101
+ finally:
102
+ for what, attribute, value in before:
103
+ setattr(what, attribute, value)
104
+
105
+ def format_help(self) -> str:
106
+ with self._rendered():
107
+ return super().format_help()
108
+
109
+ def format_usage(self) -> str:
110
+ with self._rendered():
111
+ return super().format_usage()
112
+
113
+
114
+ def build_parser() -> argparse.ArgumentParser:
115
+ groups = [(t("cli.core_group"), dict(COMMANDS)),
116
+ *((t("cli.plugin_group", name=name), dict(given)) for name, given in _plugins())]
117
+ parser = _Parser(groups, prog="verso", formatter_class=argparse.RawDescriptionHelpFormatter)
118
+ parser.text(parser, "description", t("cli.description"))
119
+ parser.text(parser.add_argument("--workspace", type=Path, metavar="DIR"), "help", t("cli.workspace_help"))
120
+ parser.text(parser.add_argument("--lang", metavar="LANG"), "help", t("cli.lang_help"))
121
+ parser.text(parser.add_argument("command", nargs="?"), "metavar", t("cli.command_metavar"))
122
+ parser.text(parser.add_argument("args", nargs=argparse.REMAINDER), "metavar", t("cli.args_metavar"))
123
+ return parser
124
+
125
+
126
+ # How a parser names a module run as a program: Python 3.14's default under `-m`
127
+ # («python3 -m verso.ru.cli.svyatcy»), or a module's own prog written so («python -m <module>»).
128
+ _AS_A_MODULE = re.compile(r"^python[\d.]* -m \S+")
129
+
130
+
131
+ @contextmanager
132
+ def _named(program: str) -> Generator[None]:
133
+ """While a command runs, a parser that would name the program as a module names it
134
+ `program`; a subcommand's parser follows, as argparse builds its name from its parent's."""
135
+ init = argparse.ArgumentParser.__init__
136
+
137
+ def named(self: argparse.ArgumentParser, *args: Any, **kwargs: Any) -> None:
138
+ init(self, *args, **kwargs)
139
+ self.prog = _AS_A_MODULE.sub(lambda _: program, self.prog, count=1)
140
+
141
+ setattr(argparse.ArgumentParser, "__init__", named) # noqa: B010 — a method assigned, which pyright refuses
142
+ try:
143
+ yield
144
+ finally:
145
+ setattr(argparse.ArgumentParser, "__init__", init) # noqa: B010
146
+
147
+
148
+ def _exit_code(code: object) -> int:
149
+ """What the process would exit with, raising SystemExit(code)."""
150
+ if code is None:
151
+ return 0
152
+ if isinstance(code, int):
153
+ return code
154
+ print(code, file=sys.stderr)
155
+ return 1
156
+
157
+
158
+ def _missing_plugin() -> str | None:
159
+ """Why a command may be missing: the workspace enables a plugin nobody installed (`make
160
+ bootstrap` after a pull); None when it does not, or there is no workspace here."""
161
+ from verso.core import plugins, workspace
162
+ try:
163
+ plugins.enabled()
164
+ except plugins.PluginError as error:
165
+ return str(error)
166
+ except workspace.WorkspaceError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _early(argv: list[str]) -> dict[str, str]:
172
+ """verso's own `--lang` and `--workspace`, read before the parser prints anything (its help,
173
+ its usage, an error): the options before the command, as the parser takes them."""
174
+ out: dict[str, str] = {}
175
+ words = iter(argv)
176
+ for word in words:
177
+ if not word.startswith("-"):
178
+ break # the command: what follows is its own
179
+ name, eq, value = word.partition("=")
180
+ if name in ("--lang", "--workspace"):
181
+ value = value if eq else next(words, "")
182
+ if value:
183
+ out[name[2:]] = value
184
+ return out
185
+
186
+
187
+ def main(argv: list[str] | None = None) -> int:
188
+ from verso.core import i18n
189
+ from verso.core.plugins import PluginError
190
+ early = _early(sys.argv[1:] if argv is None else argv)
191
+ if "lang" in early:
192
+ os.environ[i18n.ENV] = early["lang"]
193
+ if "workspace" in early and (Path(early["workspace"]) / _CONFIG).is_file():
194
+ os.environ[_ENV] = str(Path(early["workspace"]).resolve())
195
+ try: # a language nobody speaks: `--lang`, `VERSO_LANG`
196
+ i18n.check()
197
+ except i18n.CatalogError as error:
198
+ print(f"verso: {error}", file=sys.stderr)
199
+ return 2
200
+ try: # a plugin's entry point that does not load, two plugins' command
201
+ parser = build_parser()
202
+ args = parser.parse_args(argv)
203
+ if args.command is None:
204
+ parser.print_help()
205
+ return 2
206
+ module = commands().get(args.command)
207
+ except PluginError as error:
208
+ print(f"verso: {_say(error)}", file=sys.stderr)
209
+ return 2
210
+ if module is None:
211
+ print(_say(t("cli.no_command", command=args.command)), file=sys.stderr)
212
+ if (why := _missing_plugin()) is not None:
213
+ print(f"verso: {why}", file=sys.stderr)
214
+ return 2
215
+ if args.workspace is not None:
216
+ if not (args.workspace / _CONFIG).is_file():
217
+ print(_say(t("cli.workspace_no_config", workspace=args.workspace, config=_CONFIG)), file=sys.stderr)
218
+ return 2
219
+ os.environ[_ENV] = str(args.workspace.resolve())
220
+ sys.argv = [f"verso {args.command}", *args.args]
221
+ with _named(sys.argv[0]):
222
+ try:
223
+ runpy.run_module(module, run_name="__main__", alter_sys=True)
224
+ except SystemExit as done:
225
+ return _exit_code(done.code)
226
+ return 0
227
+
228
+
229
+ if __name__ == "__main__":
230
+ raise SystemExit(main())