solpython 0.1.0__py3-none-any.whl → 0.1.1__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.
pysol/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """solpython — Python-to-EVM compiler, runs Python on-chain."""
2
2
 
3
- __version__ = "0.1.0"
3
+ __version__ = "0.1.1"
pysol/cli/main.py CHANGED
@@ -40,8 +40,7 @@ def main():
40
40
  if not os.path.exists(args.script):
41
41
  print(f"solpython: can't open file '{args.script}': No such file or directory")
42
42
  sys.exit(1)
43
- source = Path(args.script).read_text()
44
- _execute(source, verbose=args.verbose)
43
+ _execute_file(args.script, verbose=args.verbose)
45
44
  return
46
45
 
47
46
  _repl(verbose=args.verbose)
@@ -64,6 +63,23 @@ def _execute(source: str, *, verbose: bool = False):
64
63
  sys.exit(1)
65
64
 
66
65
 
66
+ def _execute_file(path: str, *, verbose: bool = False):
67
+ from pysol.executor import run_file
68
+ try:
69
+ output = run_file(path, verbose=verbose)
70
+ if output:
71
+ print(output)
72
+ except FileNotFoundError as e:
73
+ print(str(e))
74
+ sys.exit(1)
75
+ except Exception as e:
76
+ print(f"solpython: error: {e}", file=sys.stderr)
77
+ if verbose:
78
+ import traceback
79
+ traceback.print_exc()
80
+ sys.exit(1)
81
+
82
+
67
83
  def _repl(*, verbose: bool = False):
68
84
  from pysol import __version__
69
85
  print(f"solpython {__version__}")
pysol/executor.py CHANGED
@@ -1,6 +1,7 @@
1
1
  """Execute Python source via the on-chain compiler and VM."""
2
2
 
3
3
  import json
4
+ import re
4
5
  from pathlib import Path
5
6
 
6
7
  _ARTIFACTS_DIR = Path(__file__).parent / "contracts" / "artifacts"
@@ -110,6 +111,36 @@ def run(source: str, *, verbose: bool = False) -> str:
110
111
  return _decode_output(w3, receipt)
111
112
 
112
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."""
116
+ 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 modules:
120
+ continue
121
+ mod_path = script_dir / f"{mod_name}.py"
122
+ if mod_path.exists():
123
+ modules[mod_name] = mod_path.read_text()
124
+ for match in re.finditer(r"^import\s+(\w+)", source, re.MULTILINE):
125
+ mod_name = match.group(1)
126
+ if mod_name in modules:
127
+ continue
128
+ mod_path = script_dir / f"{mod_name}.py"
129
+ if mod_path.exists():
130
+ modules[mod_name] = mod_path.read_text()
131
+ return modules
132
+
133
+
134
+ def run_file(path: str, *, verbose: bool = False) -> str:
135
+ """Run a Python file, auto-resolving imports from the same directory."""
136
+ script_path = Path(path)
137
+ source = script_path.read_text()
138
+ modules = _resolve_imports(source, script_path.parent)
139
+ if modules:
140
+ return run_with_imports(source, modules, verbose=verbose)
141
+ return run(source, verbose=verbose)
142
+
143
+
113
144
  def run_with_imports(source: str, modules: dict[str, str], *, verbose: bool = False) -> str:
114
145
  """Compile and execute Python source with imported modules."""
115
146
  w3, compiler, vm, sender, gas = _setup_evm()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: solpython
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Python-to-EVM compiler — run Python on-chain via a Solidity smart contract pipeline
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
@@ -0,0 +1,14 @@
1
+ pysol/__init__.py,sha256=CrThJr4pnScCO4lsl6ltTLk0JWxiQZ9ZRNb18AyhFmU,89
2
+ pysol/build.py,sha256=HUF8iFaegQcCY0DP45xsoFUCEWqPqIaXb4YhwXABETk,4483
3
+ pysol/executor.py,sha256=WaRZd3fOchFoACkn-e86RbcFUWpe0mw5zWLuxZ7LBTI,5517
4
+ pysol/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ pysol/cli/main.py,sha256=ElB-LXK7Br0vtn84i-QhPNBDzAOLu_d9RBIWJxNCFlU,3280
6
+ pysol/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ pysol/contracts/artifacts/PythonCompiler.json,sha256=01k6L0j8ZBWn2JG6CNdlRmhxpa-cHewJjY86-V3XfnU,437747
8
+ pysol/contracts/artifacts/VM.json,sha256=_qK4oc1KN2Zy0bhRMvrGorYhp2mHbKWGddqjQv4kSEE,91038
9
+ solpython-0.1.1.dist-info/licenses/LICENSE,sha256=GTNYUQJMKq5FV1co1N2BKUIxkAPPa2FCc8sLKO7x9FA,1065
10
+ solpython-0.1.1.dist-info/METADATA,sha256=ggj-hf8P8w51exL1auqa656jxxylwE1idX-n2UpEqaA,6497
11
+ solpython-0.1.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
12
+ solpython-0.1.1.dist-info/entry_points.txt,sha256=_s3EKcXf0MyFyfvA2r3llhjghAuMwS0PNRgFLxERppo,84
13
+ solpython-0.1.1.dist-info/top_level.txt,sha256=rM0iJ3CoB_QH43ATGuXjYgViiQkxBgtslv7tJqxUulM,6
14
+ solpython-0.1.1.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- pysol/__init__.py,sha256=4Vtm2aieXEP5tMfUHGOMRJi8_oyQWnJe51y1DySdQos,89
2
- pysol/build.py,sha256=HUF8iFaegQcCY0DP45xsoFUCEWqPqIaXb4YhwXABETk,4483
3
- pysol/executor.py,sha256=Etb6ORTkbGPQXa5ebhJnIPvMsFyX7XRDYLDR4RdDgVg,4344
4
- pysol/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- pysol/cli/main.py,sha256=pkIz2rMGX2baxd4-h-VW-JfNjGTc1SmcbjMw_KC_bSE,2852
6
- pysol/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- pysol/contracts/artifacts/PythonCompiler.json,sha256=01k6L0j8ZBWn2JG6CNdlRmhxpa-cHewJjY86-V3XfnU,437747
8
- pysol/contracts/artifacts/VM.json,sha256=_qK4oc1KN2Zy0bhRMvrGorYhp2mHbKWGddqjQv4kSEE,91038
9
- solpython-0.1.0.dist-info/licenses/LICENSE,sha256=GTNYUQJMKq5FV1co1N2BKUIxkAPPa2FCc8sLKO7x9FA,1065
10
- solpython-0.1.0.dist-info/METADATA,sha256=d_Hw8LDflajFOzuGxjkWeR7drizAosU1Hvdm50VL3cQ,6497
11
- solpython-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
12
- solpython-0.1.0.dist-info/entry_points.txt,sha256=_s3EKcXf0MyFyfvA2r3llhjghAuMwS0PNRgFLxERppo,84
13
- solpython-0.1.0.dist-info/top_level.txt,sha256=rM0iJ3CoB_QH43ATGuXjYgViiQkxBgtslv7tJqxUulM,6
14
- solpython-0.1.0.dist-info/RECORD,,