jopy 0.1.0__py3-none-any.whl
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.
- jopy/__init__.py +167 -0
- jopy/__main__.py +10 -0
- jopy/api.py +570 -0
- jopy/ast_nodes.py +542 -0
- jopy/cli.py +555 -0
- jopy/codegen/__init__.py +74 -0
- jopy/codegen/classes.py +846 -0
- jopy/codegen/collections.py +338 -0
- jopy/codegen/core.py +571 -0
- jopy/codegen/expressions.py +1447 -0
- jopy/codegen/functions.py +839 -0
- jopy/codegen/module.py +478 -0
- jopy/codegen/patterns.py +277 -0
- jopy/codegen/statements.py +1192 -0
- jopy/codegen/values.py +268 -0
- jopy/errors.py +270 -0
- jopy/features.py +201 -0
- jopy/inference.py +799 -0
- jopy/javatypes.py +451 -0
- jopy/jdk.py +902 -0
- jopy/lexer.py +768 -0
- jopy/mappings.py +708 -0
- jopy/parser.py +1566 -0
- jopy/progress.py +411 -0
- jopy/py.typed +0 -0
- jopy/runtime/Coroutine.java +535 -0
- jopy/runtime/JoPy.java +2800 -0
- jopy/runtime/Json.java +90 -0
- jopy/runtime/PyCallable.java +94 -0
- jopy/runtime/PyOperand.java +69 -0
- jopy/runtime/Reflection.java +64 -0
- jopy/runtime/Task.java +280 -0
- jopy/runtime/__init__.py +24 -0
- jopy/tokens.py +154 -0
- jopy-0.1.0.dist-info/METADATA +275 -0
- jopy-0.1.0.dist-info/RECORD +40 -0
- jopy-0.1.0.dist-info/WHEEL +5 -0
- jopy-0.1.0.dist-info/entry_points.txt +2 -0
- jopy-0.1.0.dist-info/licenses/LICENSE +21 -0
- jopy-0.1.0.dist-info/top_level.txt +1 -0
jopy/__init__.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""jopy - a Python to Java transpiler.
|
|
2
|
+
|
|
3
|
+
jopy parses Python source with a hand written lexer and recursive descent
|
|
4
|
+
parser, infers Java types, and emits readable Java source that targets every
|
|
5
|
+
release from Java 9 to Java 21.
|
|
6
|
+
|
|
7
|
+
Quick start::
|
|
8
|
+
|
|
9
|
+
import jopy
|
|
10
|
+
|
|
11
|
+
result = jopy.translate("def add(a, b):\n return a + b\n", filename="math_utils.py")
|
|
12
|
+
print(result.java)
|
|
13
|
+
for note in result.manual_fixes:
|
|
14
|
+
print("needs manual work:", note.message)
|
|
15
|
+
|
|
16
|
+
Or from a shell::
|
|
17
|
+
|
|
18
|
+
jopy math_utils.py -o build/java --java-version 17 --compile
|
|
19
|
+
|
|
20
|
+
Progress reporting adapts to the caller: an interactive terminal gets a bar,
|
|
21
|
+
while a programmatic call with no terminal attached receives JSON lines that
|
|
22
|
+
describe the same work.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from .api import (
|
|
28
|
+
RUNTIME_FILES,
|
|
29
|
+
SOURCE_SUFFIXES,
|
|
30
|
+
VERSION,
|
|
31
|
+
TranslateOptions,
|
|
32
|
+
TranslationResult,
|
|
33
|
+
Translator,
|
|
34
|
+
collect_sources,
|
|
35
|
+
compile_java,
|
|
36
|
+
convert,
|
|
37
|
+
convert_file,
|
|
38
|
+
find_javac,
|
|
39
|
+
javac_release_supported,
|
|
40
|
+
javac_version,
|
|
41
|
+
python_to_java,
|
|
42
|
+
runtime_directory,
|
|
43
|
+
runtime_source,
|
|
44
|
+
supported_versions,
|
|
45
|
+
to_java,
|
|
46
|
+
translate,
|
|
47
|
+
translate_directory,
|
|
48
|
+
translate_file,
|
|
49
|
+
translate_path,
|
|
50
|
+
write_runtime,
|
|
51
|
+
)
|
|
52
|
+
from .jdk import (
|
|
53
|
+
DEFAULT_VENDOR,
|
|
54
|
+
VENDORS,
|
|
55
|
+
JdkInfo,
|
|
56
|
+
default_jdk_root,
|
|
57
|
+
find_jdk,
|
|
58
|
+
install_jdk,
|
|
59
|
+
installed_jdks,
|
|
60
|
+
vendor_url,
|
|
61
|
+
)
|
|
62
|
+
from .ast_nodes import Module, ast_to_dict
|
|
63
|
+
from .codegen import CodeGenerator, CodegenOptions, GeneratedFile
|
|
64
|
+
from .errors import (
|
|
65
|
+
Diagnostic,
|
|
66
|
+
DiagnosticCollector,
|
|
67
|
+
JopyConfigError,
|
|
68
|
+
JopyError,
|
|
69
|
+
JopyGenerationError,
|
|
70
|
+
JopyJavaCompileError,
|
|
71
|
+
JopySyntaxError,
|
|
72
|
+
JopyTypeError,
|
|
73
|
+
JopyUnsupportedError,
|
|
74
|
+
SourceLocation,
|
|
75
|
+
format_diagnostics,
|
|
76
|
+
)
|
|
77
|
+
from .features import DEFAULT_VERSION, SUPPORTED_VERSIONS, JavaFeatures
|
|
78
|
+
from .lexer import LexedSource, lex
|
|
79
|
+
from .parser import Parser, parse, parse_expression_text
|
|
80
|
+
from .progress import (
|
|
81
|
+
JsonProgress,
|
|
82
|
+
NullProgress,
|
|
83
|
+
ProgressEvent,
|
|
84
|
+
ProgressReporter,
|
|
85
|
+
TerminalProgress,
|
|
86
|
+
format_duration,
|
|
87
|
+
stage_plan,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
__version__ = VERSION
|
|
91
|
+
|
|
92
|
+
__all__ = [
|
|
93
|
+
"__version__",
|
|
94
|
+
# high level API
|
|
95
|
+
"translate",
|
|
96
|
+
"translate_file",
|
|
97
|
+
"translate_directory",
|
|
98
|
+
"translate_path",
|
|
99
|
+
"to_java",
|
|
100
|
+
"convert",
|
|
101
|
+
"convert_file",
|
|
102
|
+
"python_to_java",
|
|
103
|
+
"Translator",
|
|
104
|
+
"TranslateOptions",
|
|
105
|
+
"TranslationResult",
|
|
106
|
+
"collect_sources",
|
|
107
|
+
# front end
|
|
108
|
+
"lex",
|
|
109
|
+
"parse",
|
|
110
|
+
"parse_expression_text",
|
|
111
|
+
"Parser",
|
|
112
|
+
"LexedSource",
|
|
113
|
+
"Module",
|
|
114
|
+
"ast_to_dict",
|
|
115
|
+
# back end
|
|
116
|
+
"CodeGenerator",
|
|
117
|
+
"CodegenOptions",
|
|
118
|
+
"GeneratedFile",
|
|
119
|
+
"JavaFeatures",
|
|
120
|
+
"DEFAULT_VERSION",
|
|
121
|
+
"SUPPORTED_VERSIONS",
|
|
122
|
+
# progress
|
|
123
|
+
"ProgressReporter",
|
|
124
|
+
"ProgressEvent",
|
|
125
|
+
"TerminalProgress",
|
|
126
|
+
"JsonProgress",
|
|
127
|
+
"NullProgress",
|
|
128
|
+
"stage_plan",
|
|
129
|
+
"format_duration",
|
|
130
|
+
# runtime and verification
|
|
131
|
+
"runtime_source",
|
|
132
|
+
"runtime_directory",
|
|
133
|
+
"write_runtime",
|
|
134
|
+
"RUNTIME_FILES",
|
|
135
|
+
"SOURCE_SUFFIXES",
|
|
136
|
+
"compile_java",
|
|
137
|
+
"find_javac",
|
|
138
|
+
"javac_version",
|
|
139
|
+
"javac_release_supported",
|
|
140
|
+
"supported_versions",
|
|
141
|
+
# JDK provisioning
|
|
142
|
+
"install_jdk",
|
|
143
|
+
"find_jdk",
|
|
144
|
+
"installed_jdks",
|
|
145
|
+
"vendor_url",
|
|
146
|
+
"default_jdk_root",
|
|
147
|
+
"JdkInfo",
|
|
148
|
+
"DEFAULT_VENDOR",
|
|
149
|
+
"VENDORS",
|
|
150
|
+
# diagnostics
|
|
151
|
+
"JopyError",
|
|
152
|
+
"JopySyntaxError",
|
|
153
|
+
"JopyUnsupportedError",
|
|
154
|
+
"JopyTypeError",
|
|
155
|
+
"JopyGenerationError",
|
|
156
|
+
"JopyJavaCompileError",
|
|
157
|
+
"JopyConfigError",
|
|
158
|
+
"Diagnostic",
|
|
159
|
+
"DiagnosticCollector",
|
|
160
|
+
"SourceLocation",
|
|
161
|
+
"format_diagnostics",
|
|
162
|
+
]
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def translate_source(source: str, filename: str = "<memory>", **kwargs) -> TranslationResult:
|
|
166
|
+
"""Translate Python source text (alias of translate)."""
|
|
167
|
+
return translate(source, filename, **kwargs)
|