legesher-core 0.24.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.
- legesher_core-0.24.0/LICENSE +190 -0
- legesher_core-0.24.0/PKG-INFO +292 -0
- legesher_core-0.24.0/README.md +260 -0
- legesher_core-0.24.0/legesher_core/__init__.py +193 -0
- legesher_core-0.24.0/legesher_core/__main__.py +197 -0
- legesher_core-0.24.0/legesher_core/ai_context.py +691 -0
- legesher_core-0.24.0/legesher_core/artifact_io.py +175 -0
- legesher_core-0.24.0/legesher_core/cultural_comments.py +263 -0
- legesher_core-0.24.0/legesher_core/exceptions.py +77 -0
- legesher_core-0.24.0/legesher_core/filter_process.py +283 -0
- legesher_core-0.24.0/legesher_core/git_filter.py +227 -0
- legesher_core-0.24.0/legesher_core/guard.py +567 -0
- legesher_core-0.24.0/legesher_core/ide_support.py +306 -0
- legesher_core-0.24.0/legesher_core/language_interface.py +416 -0
- legesher_core-0.24.0/legesher_core/metadata.py +544 -0
- legesher_core-0.24.0/legesher_core/py.typed +0 -0
- legesher_core-0.24.0/legesher_core/repo_attribution.py +428 -0
- legesher_core-0.24.0/legesher_core/round_trip.py +671 -0
- legesher_core-0.24.0/legesher_core/script_lookup.py +101 -0
- legesher_core-0.24.0/legesher_core/stored_form.py +472 -0
- legesher_core-0.24.0/legesher_core/text_identity.py +93 -0
- legesher_core-0.24.0/legesher_core/token_mapper.py +279 -0
- legesher_core-0.24.0/legesher_core/transformer.py +499 -0
- legesher_core-0.24.0/legesher_core/translation_memory/__init__.py +51 -0
- legesher_core-0.24.0/legesher_core/translation_memory/model.py +659 -0
- legesher_core-0.24.0/legesher_core/translation_tracker.py +502 -0
- legesher_core-0.24.0/legesher_core/tree_sitter/README.md +488 -0
- legesher_core-0.24.0/legesher_core/tree_sitter/__init__.py +101 -0
- legesher_core-0.24.0/legesher_core/tree_sitter/extractor.py +756 -0
- legesher_core-0.24.0/legesher_core/tree_sitter/identifier_map.py +321 -0
- legesher_core-0.24.0/legesher_core/tree_sitter/identifier_validator.py +225 -0
- legesher_core-0.24.0/legesher_core/tree_sitter/llm_translator.py +684 -0
- legesher_core-0.24.0/legesher_core/tree_sitter/parser.py +214 -0
- legesher_core-0.24.0/legesher_core/tree_sitter/translation_logger.py +250 -0
- legesher_core-0.24.0/legesher_core/tree_sitter/translator.py +639 -0
- legesher_core-0.24.0/legesher_core/types.py +582 -0
- legesher_core-0.24.0/legesher_core/unicode_guard.py +492 -0
- legesher_core-0.24.0/legesher_core/utils.py +212 -0
- legesher_core-0.24.0/pyproject.toml +124 -0
- legesher_core-0.24.0/tests/__init__.py +0 -0
- legesher_core-0.24.0/tests/benchmarks/__init__.py +1 -0
- legesher_core-0.24.0/tests/benchmarks/conftest.py +18 -0
- legesher_core-0.24.0/tests/benchmarks/test_filter_process_benchmark.py +63 -0
- legesher_core-0.24.0/tests/benchmarks/test_pack_loading_benchmark.py +63 -0
- legesher_core-0.24.0/tests/benchmarks/test_translator_performance.py +193 -0
- legesher_core-0.24.0/tests/conftest.py +116 -0
- legesher_core-0.24.0/tests/corpus.py +96 -0
- legesher_core-0.24.0/tests/fixtures/__init__.py +0 -0
- legesher_core-0.24.0/tests/fixtures/corpus/builtins_and_comprehensions.py +29 -0
- legesher_core-0.24.0/tests/fixtures/corpus/context_and_async.py +50 -0
- legesher_core-0.24.0/tests/fixtures/corpus/control_flow.py +25 -0
- legesher_core-0.24.0/tests/fixtures/corpus/exception_groups.py +13 -0
- legesher_core-0.24.0/tests/fixtures/corpus/exceptions.py +37 -0
- legesher_core-0.24.0/tests/fixtures/corpus/functions_and_classes.py +51 -0
- legesher_core-0.24.0/tests/fixtures/corpus/manifest.json +11 -0
- legesher_core-0.24.0/tests/fixtures/corpus/pattern_matching.py +27 -0
- legesher_core-0.24.0/tests/fixtures/corpus/type_params.py +15 -0
- legesher_core-0.24.0/tests/fixtures/corpus/vocabulary.py +166 -0
- legesher_core-0.24.0/tests/fixtures/repo_attribution_vectors.json +574 -0
- legesher_core-0.24.0/tests/fixtures/sample_english.py +127 -0
- legesher_core-0.24.0/tests/fixtures/sample_english_script.py +10 -0
- legesher_core-0.24.0/tests/fixtures/sample_spanish.py +8 -0
- legesher_core-0.24.0/tests/integration/test_all_languages_parametrized.py +575 -0
- legesher_core-0.24.0/tests/integration/test_cultural_comments_integration.py +335 -0
- legesher_core-0.24.0/tests/integration/test_every_pack.py +341 -0
- legesher_core-0.24.0/tests/integration/test_file_translation.py +157 -0
- legesher_core-0.24.0/tests/integration/test_filter_process_git.py +330 -0
- legesher_core-0.24.0/tests/integration/test_git_workflow.py +200 -0
- legesher_core-0.24.0/tests/integration/test_metadata_tracking.py +1053 -0
- legesher_core-0.24.0/tests/integration/test_migrated_packs.py +613 -0
- legesher_core-0.24.0/tests/integration/test_pack_integration.py +546 -0
- legesher_core-0.24.0/tests/integration/test_stored_form_every_pack.py +170 -0
- legesher_core-0.24.0/tests/integration/test_version_inheritance.py +444 -0
- legesher_core-0.24.0/tests/interpreter_gaps.py +190 -0
- legesher_core-0.24.0/tests/property/__init__.py +0 -0
- legesher_core-0.24.0/tests/property/test_round_trip_property.py +451 -0
- legesher_core-0.24.0/tests/test_ai_context.py +337 -0
- legesher_core-0.24.0/tests/test_artifact_io.py +320 -0
- legesher_core-0.24.0/tests/test_import_without_tree_sitter.py +168 -0
- legesher_core-0.24.0/tests/test_map_family_absent.py +70 -0
- legesher_core-0.24.0/tests/test_text_identity.py +65 -0
- legesher_core-0.24.0/tests/translation_memory/__init__.py +0 -0
- legesher_core-0.24.0/tests/translation_memory/conftest.py +47 -0
- legesher_core-0.24.0/tests/translation_memory/test_fuzzy.py +150 -0
- legesher_core-0.24.0/tests/translation_memory/test_lookup.py +170 -0
- legesher_core-0.24.0/tests/translation_memory/test_model.py +314 -0
- legesher_core-0.24.0/tests/translation_memory/test_prefilters_and_prune.py +163 -0
- legesher_core-0.24.0/tests/tree_sitter/__init__.py +0 -0
- legesher_core-0.24.0/tests/tree_sitter/test_parser.py +462 -0
- legesher_core-0.24.0/tests/tree_sitter/test_setup.py +116 -0
- legesher_core-0.24.0/tests/tree_sitter/test_translator.py +948 -0
- legesher_core-0.24.0/tests/unit/test_cultural_comments.py +492 -0
- legesher_core-0.24.0/tests/unit/test_edge_cases.py +256 -0
- legesher_core-0.24.0/tests/unit/test_exception_loading.py +139 -0
- legesher_core-0.24.0/tests/unit/test_extractor.py +649 -0
- legesher_core-0.24.0/tests/unit/test_filter_entry_point.py +55 -0
- legesher_core-0.24.0/tests/unit/test_filter_process.py +243 -0
- legesher_core-0.24.0/tests/unit/test_git_filter.py +192 -0
- legesher_core-0.24.0/tests/unit/test_guard.py +467 -0
- legesher_core-0.24.0/tests/unit/test_identifier_map.py +545 -0
- legesher_core-0.24.0/tests/unit/test_identifier_quality.py +461 -0
- legesher_core-0.24.0/tests/unit/test_identifier_scripts.py +303 -0
- legesher_core-0.24.0/tests/unit/test_identifier_validator.py +258 -0
- legesher_core-0.24.0/tests/unit/test_language_interface.py +268 -0
- legesher_core-0.24.0/tests/unit/test_llm_security_edge_cases.py +748 -0
- legesher_core-0.24.0/tests/unit/test_llm_translator.py +491 -0
- legesher_core-0.24.0/tests/unit/test_llm_translator_collision_retry.py +239 -0
- legesher_core-0.24.0/tests/unit/test_llm_translator_forbidden_values.py +131 -0
- legesher_core-0.24.0/tests/unit/test_metadata.py +877 -0
- legesher_core-0.24.0/tests/unit/test_normalization_round_trip.py +40 -0
- legesher_core-0.24.0/tests/unit/test_parser_bom_encoding.py +47 -0
- legesher_core-0.24.0/tests/unit/test_repo_attribution.py +537 -0
- legesher_core-0.24.0/tests/unit/test_round_trip.py +467 -0
- legesher_core-0.24.0/tests/unit/test_round_trip_classifier.py +255 -0
- legesher_core-0.24.0/tests/unit/test_round_trip_comparator.py +180 -0
- legesher_core-0.24.0/tests/unit/test_round_trip_report.py +492 -0
- legesher_core-0.24.0/tests/unit/test_smoke.py +19 -0
- legesher_core-0.24.0/tests/unit/test_stored_form.py +322 -0
- legesher_core-0.24.0/tests/unit/test_token_mapper.py +143 -0
- legesher_core-0.24.0/tests/unit/test_token_mapper_normalization.py +76 -0
- legesher_core-0.24.0/tests/unit/test_token_translator.py +319 -0
- legesher_core-0.24.0/tests/unit/test_translation_logger.py +369 -0
- legesher_core-0.24.0/tests/unit/test_translation_tracker.py +936 -0
- legesher_core-0.24.0/tests/unit/test_translator_protocol.py +185 -0
- legesher_core-0.24.0/tests/unit/test_unicode_guard.py +367 -0
- legesher_core-0.24.0/tests/unit/test_utils.py +154 -0
|
@@ -0,0 +1,190 @@
|
|
|
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 the 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 the 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 any 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
|
+
Copyright 2025-2026 Madison (Pfaff) Edgar and Legesher Contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: legesher-core
|
|
3
|
+
Version: 0.24.0
|
|
4
|
+
Summary: Translation engine for multilingual Python: keyword, builtin, and identifier rewriting
|
|
5
|
+
Keywords: translation,i18n,programming,multilingual,code-translation
|
|
6
|
+
Author-Email: "Madison (Pfaff) Edgar" <7844510+madiedgar@users.noreply.github.com>
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Software Development :: Internationalization
|
|
17
|
+
Classifier: Topic :: Software Development :: Localization
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Project-URL: Homepage, https://legesher.io
|
|
20
|
+
Project-URL: Documentation, https://docs.legesher.io
|
|
21
|
+
Project-URL: Repository, https://github.com/legesher/legesher
|
|
22
|
+
Project-URL: Changelog, https://github.com/legesher/legesher/blob/main/libs/core/CHANGELOG.md
|
|
23
|
+
Project-URL: Issues, https://github.com/legesher/legesher/issues
|
|
24
|
+
Requires-Python: <4.0,>=3.10
|
|
25
|
+
Requires-Dist: click>=8.0.0
|
|
26
|
+
Requires-Dist: legesher-i18n<1.0.0,>=0.22.0
|
|
27
|
+
Requires-Dist: pyyaml>=6.0
|
|
28
|
+
Provides-Extra: treesitter
|
|
29
|
+
Requires-Dist: tree-sitter>=0.20.4; extra == "treesitter"
|
|
30
|
+
Requires-Dist: tree-sitter-python>=0.21.0; extra == "treesitter"
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# Legesher Core
|
|
34
|
+
|
|
35
|
+
Production-ready translation engine for multilingual Python with two complete translator backends.
|
|
36
|
+
|
|
37
|
+
**Status**: Pre-Beta | **Python**: 3.10-3.14 | **Version**: see `pyproject.toml`
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
- **Two Translator Backends**: Choose between token-based or tree-sitter AST-based translation
|
|
42
|
+
- **Complete Keyword Translation**: All 39 Python keywords across 3.10-3.14
|
|
43
|
+
- **56 Languages Supported**: Via independent language pack system
|
|
44
|
+
- **Perfect Formatting**: Preserves indentation, comments, docstrings
|
|
45
|
+
- **Round-Trip**: EN→ES→EN is byte-identical for the corpus the sweep covers; the known exceptions are listed as
|
|
46
|
+
strict xfails in `libs/mcp/tests/test_roundtrip_sweep.py`
|
|
47
|
+
- **RTL Languages**: Arabic, Hebrew, Persian, and Urdu translate like any other language. Values are stored in
|
|
48
|
+
logical order with no bidi control characters, so display order is the terminal's or editor's to decide
|
|
49
|
+
- **Fast**: both backends translate a small module in well under a millisecond; run
|
|
50
|
+
`pytest libs/core/tests/benchmarks` to measure on your own hardware
|
|
51
|
+
- **Graceful Degradation**: Handles incomplete code and syntax errors
|
|
52
|
+
- **Git Integration**: Complete clean/smudge filter implementation with metadata tracking
|
|
53
|
+
- **Cultural Comments**: MLCP protocol support for contextual annotations
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
### Using Language Packs (Recommended)
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from legesher_core import TokenTranslator
|
|
61
|
+
|
|
62
|
+
# Create translator from language pack (auto-detects Python version)
|
|
63
|
+
translator = TokenTranslator.from_language_pack("es")
|
|
64
|
+
|
|
65
|
+
# Translate code
|
|
66
|
+
code = "def greet():\n print('Hello!')"
|
|
67
|
+
spanish = translator.translate_code(code)
|
|
68
|
+
# Result: "definir greet():\n imprimir('Hello!')"
|
|
69
|
+
|
|
70
|
+
# Bidirectional translation
|
|
71
|
+
es_to_en = translator.reverse()
|
|
72
|
+
back_to_english = es_to_en.translate_code(spanish)
|
|
73
|
+
|
|
74
|
+
# List available languages
|
|
75
|
+
languages = TokenTranslator.list_available_languages()
|
|
76
|
+
# [('am', 'AM'), ('ar', 'AR'), ('bn', 'BN'), ... (56 languages)]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Choosing a Translator Backend
|
|
80
|
+
|
|
81
|
+
Legesher Core provides **two complete translator implementations**:
|
|
82
|
+
|
|
83
|
+
#### TokenTranslator (Default)
|
|
84
|
+
|
|
85
|
+
- Token-based translation
|
|
86
|
+
- Fast and simple, and the quicker of the two on the bundled benchmark
|
|
87
|
+
- Pure standard library — no C extensions required
|
|
88
|
+
- Perfect for most use cases
|
|
89
|
+
- Best compatibility with incomplete code
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from legesher_core import TokenTranslator
|
|
93
|
+
|
|
94
|
+
translator = TokenTranslator.from_language_pack("es")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### TreeSitterTranslator (AST-based)
|
|
98
|
+
|
|
99
|
+
- Tree-sitter AST-based translation
|
|
100
|
+
- Better error handling for syntax edge cases
|
|
101
|
+
- Supports incremental parsing
|
|
102
|
+
- Requires the optional `treesitter` extra (tree-sitter C extensions):
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pip install 'legesher-core[treesitter]'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Without the extra, `import legesher_core` and the token path still work;
|
|
109
|
+
accessing `TreeSitterTranslator` or `LLMTranslator` raises an `ImportError`
|
|
110
|
+
that names the extra. This keeps minimal installs and browser Python runtimes
|
|
111
|
+
(where C extensions are unavailable) on the pure-stdlib token path.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from legesher_core import create_translator
|
|
115
|
+
|
|
116
|
+
# Create tree-sitter translator
|
|
117
|
+
translator = create_translator("python", keyword_map, builtin_map, use_tree_sitter=True)
|
|
118
|
+
|
|
119
|
+
# Or use environment variable
|
|
120
|
+
import os
|
|
121
|
+
os.environ["LEGESHER_USE_TREE_SITTER"] = "true"
|
|
122
|
+
translator = create_translator("python", keyword_map, builtin_map)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Both translators provide identical APIs and produce identical output. The benchmark suite in
|
|
126
|
+
`tests/benchmarks/` compares them if you want numbers for your own hardware.
|
|
127
|
+
|
|
128
|
+
### Using Custom Maps (Legacy)
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from legesher_core import TokenTranslator
|
|
132
|
+
|
|
133
|
+
# Define translation maps
|
|
134
|
+
spanish_keywords = {"def": "definir", "return": "retornar"}
|
|
135
|
+
spanish_builtins = {"print": "imprimir", "len": "longitud"}
|
|
136
|
+
|
|
137
|
+
# Create translator
|
|
138
|
+
translator = TokenTranslator(spanish_keywords, spanish_builtins)
|
|
139
|
+
|
|
140
|
+
# Translate code
|
|
141
|
+
code = "def greet():\n print('Hello!')"
|
|
142
|
+
spanish = translator.translate_code(code, "en", "es")
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Testing
|
|
146
|
+
|
|
147
|
+
### Run all tests
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
cd libs/core
|
|
151
|
+
uv run python -m pytest tests/ -v
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Run specific test file
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
cd libs/core
|
|
158
|
+
uv run python -m pytest tests/integration/test_pack_integration.py -v
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Run with coverage
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
cd libs/core
|
|
165
|
+
uv run python -m pytest tests/ --cov=legesher_core --cov-report=html
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Troubleshooting Test Runs
|
|
169
|
+
|
|
170
|
+
If you encounter "No module named pytest":
|
|
171
|
+
|
|
172
|
+
1. Ensure you're in the package directory (`libs/core`)
|
|
173
|
+
2. Run `uv sync` to install dependencies
|
|
174
|
+
3. Use `uv run python -m pytest` (not just `pytest`)
|
|
175
|
+
|
|
176
|
+
**Test Categories:**
|
|
177
|
+
|
|
178
|
+
- Unit tests: Token translation, AST parsing, metadata tracking, git filters
|
|
179
|
+
- Integration tests: Round-trip translation, language pack loading, cultural comments
|
|
180
|
+
- Benchmarks: Performance comparison between TokenTranslator and TreeSitterTranslator
|
|
181
|
+
|
|
182
|
+
## Metadata Tracking
|
|
183
|
+
|
|
184
|
+
Legesher Core includes a comprehensive metadata tracking system that records
|
|
185
|
+
translation history and git operations for audit trails and debugging.
|
|
186
|
+
|
|
187
|
+
### What is Metadata?
|
|
188
|
+
|
|
189
|
+
The metadata system tracks:
|
|
190
|
+
|
|
191
|
+
- Original language of each file
|
|
192
|
+
- Translation operations performed
|
|
193
|
+
- Git filter operations (clean/smudge)
|
|
194
|
+
- Python version and translator version used
|
|
195
|
+
- Timestamps and commit SHAs
|
|
196
|
+
|
|
197
|
+
Metadata is stored in `.legesher/metadata/` as YAML files that mirror your source tree structure.
|
|
198
|
+
|
|
199
|
+
### Metadata Schema
|
|
200
|
+
|
|
201
|
+
Each file gets a metadata file at `.legesher/metadata/<file_path>.yml`:
|
|
202
|
+
|
|
203
|
+
```yaml
|
|
204
|
+
file: src/calculator.py
|
|
205
|
+
original_language: es
|
|
206
|
+
canonical_language: en
|
|
207
|
+
python_version: "3.13"
|
|
208
|
+
created_at: "2025-11-06T10:30:00Z"
|
|
209
|
+
updated_at: "2025-11-06T14:35:00Z"
|
|
210
|
+
translations:
|
|
211
|
+
- language: en
|
|
212
|
+
method: token_transformer
|
|
213
|
+
timestamp: "2025-11-06T10:30:00Z"
|
|
214
|
+
commit_sha: abc123
|
|
215
|
+
translator_version: "0.1.0"
|
|
216
|
+
python_version: "3.13"
|
|
217
|
+
history:
|
|
218
|
+
- action: clean
|
|
219
|
+
from_language: es
|
|
220
|
+
to_language: en
|
|
221
|
+
timestamp: "2025-11-06T10:35:00Z"
|
|
222
|
+
commit_sha: def456
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Using Metadata in Code
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from pathlib import Path
|
|
229
|
+
from legesher_core.metadata import MetadataManager
|
|
230
|
+
from legesher_core.types import TranslationRecord, HistoryEntry
|
|
231
|
+
|
|
232
|
+
# Initialize manager
|
|
233
|
+
repo_root = Path("/path/to/repo")
|
|
234
|
+
manager = MetadataManager(repo_root)
|
|
235
|
+
|
|
236
|
+
# Create metadata for new file
|
|
237
|
+
metadata = manager.create_metadata(
|
|
238
|
+
Path("src/calculator.py"),
|
|
239
|
+
original_language="es",
|
|
240
|
+
python_version="3.13"
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
# Read existing metadata
|
|
244
|
+
metadata = manager.get_metadata(Path("src/calculator.py"))
|
|
245
|
+
if metadata:
|
|
246
|
+
print(f"Original language: {metadata['original_language']}")
|
|
247
|
+
print(f"Translations: {len(metadata['translations'])}")
|
|
248
|
+
|
|
249
|
+
# Record translation operation
|
|
250
|
+
record: TranslationRecord = {
|
|
251
|
+
"language": "en",
|
|
252
|
+
"method": "token_transformer",
|
|
253
|
+
"timestamp": "2025-11-06T10:30:00Z",
|
|
254
|
+
"commit_sha": "a91228a",
|
|
255
|
+
"translator_version": "0.1.0",
|
|
256
|
+
"python_version": "3.13"
|
|
257
|
+
}
|
|
258
|
+
manager.record_translation(Path("src/calculator.py"), record)
|
|
259
|
+
|
|
260
|
+
# Add history entry (git operation)
|
|
261
|
+
entry: HistoryEntry = {
|
|
262
|
+
"action": "clean",
|
|
263
|
+
"from_language": "es",
|
|
264
|
+
"to_language": "en",
|
|
265
|
+
"timestamp": "2025-11-06T10:30:00Z",
|
|
266
|
+
"commit_sha": "a91228a"
|
|
267
|
+
}
|
|
268
|
+
manager.add_history_entry(Path("src/calculator.py"), entry)
|
|
269
|
+
|
|
270
|
+
# List all metadata files
|
|
271
|
+
metadata_files = manager.list_metadata_files()
|
|
272
|
+
print(f"Tracking {len(metadata_files)} files")
|
|
273
|
+
|
|
274
|
+
# Validate metadata integrity
|
|
275
|
+
is_valid = manager.validate_metadata(Path("src/calculator.py"))
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Privacy & Security
|
|
279
|
+
|
|
280
|
+
- **No source code stored**: Metadata contains only file paths, languages, timestamps
|
|
281
|
+
- **Local-first**: All metadata stored locally in `.legesher/metadata/`
|
|
282
|
+
- **No cloud required**: Never requires external services
|
|
283
|
+
- **Optional git tracking**: Can exclude metadata from git if desired
|
|
284
|
+
- **Atomic writes**: All file operations use atomic write-then-rename for safety
|
|
285
|
+
|
|
286
|
+
### API Reference
|
|
287
|
+
|
|
288
|
+
See the [metadata module documentation](legesher_core/metadata.py) for complete API details.
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
Apache License 2.0
|