solpython 0.1.1__tar.gz → 0.1.3__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.
- {solpython-0.1.1/solpython.egg-info → solpython-0.1.3}/PKG-INFO +1 -1
- {solpython-0.1.1 → solpython-0.1.3}/pyproject.toml +1 -1
- {solpython-0.1.1 → solpython-0.1.3}/pysol/__init__.py +1 -1
- {solpython-0.1.1 → solpython-0.1.3}/pysol/cli/main.py +22 -8
- {solpython-0.1.1 → solpython-0.1.3}/pysol/executor.py +28 -13
- {solpython-0.1.1 → solpython-0.1.3/solpython.egg-info}/PKG-INFO +1 -1
- {solpython-0.1.1 → solpython-0.1.3}/LICENSE +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/MANIFEST.in +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/README.md +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/pysol/build.py +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/pysol/cli/__init__.py +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/pysol/contracts/__init__.py +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/pysol/contracts/artifacts/PythonCompiler.json +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/pysol/contracts/artifacts/VM.json +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/setup.cfg +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/solpython.egg-info/SOURCES.txt +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/solpython.egg-info/dependency_links.txt +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/solpython.egg-info/entry_points.txt +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/solpython.egg-info/requires.txt +0 -0
- {solpython-0.1.1 → solpython-0.1.3}/solpython.egg-info/top_level.txt +0 -0
|
@@ -16,6 +16,8 @@ def main():
|
|
|
16
16
|
parser.add_argument("-v", "--verbose", action="store_true", help="Show compilation details")
|
|
17
17
|
parser.add_argument("--version", action="store_true", help="Show version and exit")
|
|
18
18
|
parser.add_argument("--build", action="store_true", help="Compile Solidity contracts and exit")
|
|
19
|
+
parser.add_argument("--backend", choices=["vm", "solidity", "yul"], default="vm",
|
|
20
|
+
help="Backend: vm (execute, default), solidity (transpile), yul (transpile)")
|
|
19
21
|
|
|
20
22
|
args = parser.parse_args()
|
|
21
23
|
|
|
@@ -33,23 +35,28 @@ def main():
|
|
|
33
35
|
source = args.command
|
|
34
36
|
if not source.endswith("\n"):
|
|
35
37
|
source += "\n"
|
|
36
|
-
_execute(source, verbose=args.verbose)
|
|
38
|
+
_execute(source, verbose=args.verbose, backend=args.backend)
|
|
37
39
|
return
|
|
38
40
|
|
|
39
41
|
if args.script:
|
|
40
42
|
if not os.path.exists(args.script):
|
|
41
43
|
print(f"solpython: can't open file '{args.script}': No such file or directory")
|
|
42
44
|
sys.exit(1)
|
|
43
|
-
_execute_file(args.script, verbose=args.verbose)
|
|
45
|
+
_execute_file(args.script, verbose=args.verbose, backend=args.backend)
|
|
44
46
|
return
|
|
45
47
|
|
|
46
48
|
_repl(verbose=args.verbose)
|
|
47
49
|
|
|
48
50
|
|
|
49
|
-
def _execute(source: str, *, verbose: bool = False):
|
|
50
|
-
from pysol.executor import run
|
|
51
|
+
def _execute(source: str, *, verbose: bool = False, backend: str = "vm"):
|
|
52
|
+
from pysol.executor import run, compile_to_solidity, compile_to_yul
|
|
51
53
|
try:
|
|
52
|
-
|
|
54
|
+
if backend == "solidity":
|
|
55
|
+
output = compile_to_solidity(source, verbose=verbose)
|
|
56
|
+
elif backend == "yul":
|
|
57
|
+
output = compile_to_yul(source, verbose=verbose)
|
|
58
|
+
else:
|
|
59
|
+
output = run(source, verbose=verbose)
|
|
53
60
|
if output:
|
|
54
61
|
print(output)
|
|
55
62
|
except FileNotFoundError as e:
|
|
@@ -63,10 +70,17 @@ def _execute(source: str, *, verbose: bool = False):
|
|
|
63
70
|
sys.exit(1)
|
|
64
71
|
|
|
65
72
|
|
|
66
|
-
def _execute_file(path: str, *, verbose: bool = False):
|
|
67
|
-
from pysol.executor import run_file
|
|
73
|
+
def _execute_file(path: str, *, verbose: bool = False, backend: str = "vm"):
|
|
74
|
+
from pysol.executor import run_file, compile_to_solidity, compile_to_yul
|
|
68
75
|
try:
|
|
69
|
-
|
|
76
|
+
if backend in ("solidity", "yul"):
|
|
77
|
+
source = Path(path).read_text()
|
|
78
|
+
if backend == "solidity":
|
|
79
|
+
output = compile_to_solidity(source, verbose=verbose)
|
|
80
|
+
else:
|
|
81
|
+
output = compile_to_yul(source, verbose=verbose)
|
|
82
|
+
else:
|
|
83
|
+
output = run_file(path, verbose=verbose)
|
|
70
84
|
if output:
|
|
71
85
|
print(output)
|
|
72
86
|
except FileNotFoundError as e:
|
|
@@ -111,23 +111,22 @@ def run(source: str, *, verbose: bool = False) -> str:
|
|
|
111
111
|
return _decode_output(w3, receipt)
|
|
112
112
|
|
|
113
113
|
|
|
114
|
-
def _resolve_imports(source: str, script_dir: Path) -> dict[str, str]:
|
|
115
|
-
"""Parse source for import statements and load module files from disk."""
|
|
114
|
+
def _resolve_imports(source: str, script_dir: Path, *, _seen: set[str] | None = None) -> dict[str, str]:
|
|
115
|
+
"""Parse source for import statements and load module files from disk (recursive)."""
|
|
116
|
+
if _seen is None:
|
|
117
|
+
_seen = set()
|
|
116
118
|
modules = {}
|
|
117
|
-
for match in re.finditer(r"^from\s+(\w+)\s+import\s+", source, re.MULTILINE):
|
|
118
|
-
mod_name = match.group(1)
|
|
119
|
-
if mod_name in
|
|
119
|
+
for match in re.finditer(r"^(?:from\s+(\w+)\s+import\s+|import\s+(\w+))", source, re.MULTILINE):
|
|
120
|
+
mod_name = match.group(1) or match.group(2)
|
|
121
|
+
if mod_name in _seen:
|
|
120
122
|
continue
|
|
123
|
+
_seen.add(mod_name)
|
|
121
124
|
mod_path = script_dir / f"{mod_name}.py"
|
|
122
125
|
if mod_path.exists():
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
continue
|
|
128
|
-
mod_path = script_dir / f"{mod_name}.py"
|
|
129
|
-
if mod_path.exists():
|
|
130
|
-
modules[mod_name] = mod_path.read_text()
|
|
126
|
+
mod_src = mod_path.read_text()
|
|
127
|
+
modules[mod_name] = mod_src
|
|
128
|
+
nested = _resolve_imports(mod_src, script_dir, _seen=_seen)
|
|
129
|
+
modules.update(nested)
|
|
131
130
|
return modules
|
|
132
131
|
|
|
133
132
|
|
|
@@ -156,3 +155,19 @@ def run_with_imports(source: str, modules: dict[str, str], *, verbose: bool = Fa
|
|
|
156
155
|
receipt = w3.eth.get_transaction_receipt(tx_hash)
|
|
157
156
|
|
|
158
157
|
return _decode_output(w3, receipt)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def compile_to_solidity(source: str, *, verbose: bool = False) -> str:
|
|
161
|
+
"""Compile Python source and return generated Solidity code."""
|
|
162
|
+
w3, compiler, vm, sender, gas = _setup_evm()
|
|
163
|
+
if verbose:
|
|
164
|
+
print(f"[solpython] Compiling {len(source)} chars of Python to Solidity...")
|
|
165
|
+
return compiler.functions.compileToSolidity(source).call({"from": sender, "gas": gas})
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def compile_to_yul(source: str, *, verbose: bool = False) -> str:
|
|
169
|
+
"""Compile Python source and return generated Yul code."""
|
|
170
|
+
w3, compiler, vm, sender, gas = _setup_evm()
|
|
171
|
+
if verbose:
|
|
172
|
+
print(f"[solpython] Compiling {len(source)} chars of Python to Yul...")
|
|
173
|
+
return compiler.functions.compileToYul(source).call({"from": sender, "gas": gas})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|