added source maps

This commit is contained in:
2026-05-15 18:58:03 -05:00
parent ac745dd4a6
commit e11d9007ec
2 changed files with 30 additions and 19 deletions

View File

@@ -1,15 +1,13 @@
from __future__ import annotations
import runpy
import sys
import tempfile
from pathlib import Path
import click
from . import __version__
from .errors import activate
from .transpiler import transpile_file
from .transpiler import transpile_file, run_transpiled
@click.group()
@@ -26,15 +24,13 @@ def main():
def run(file: Path, lang: str | None, keep: bool):
"""Transpile and run a foreign-language Python file."""
if lang:
# Inject shebang override so transpiler picks it up
source = file.read_text(encoding="utf-8")
if not source.startswith("# foreignthon:"):
source = f"# foreignthon: {lang}\n" + source
file.write_text(source, encoding="utf-8")
file.write_text(source, encoding="utf-8")
transpiled = transpile_file(file)
# Detect lang for error hook
detected_lang = lang or _lang_from_file(file)
activate(detected_lang)
@@ -43,17 +39,7 @@ def run(file: Path, lang: str | None, keep: bool):
out_path.write_text(transpiled, encoding="utf-8")
click.echo(f"Compiled: {out_path}")
# Write to a temp file and run it — runpy keeps __file__ correct
with tempfile.NamedTemporaryFile(
suffix=".py", mode="w", encoding="utf-8", delete=False
) as tmp:
tmp.write(transpiled)
tmp_path = tmp.name
try:
runpy.run_path(tmp_path, run_name="__main__")
finally:
Path(tmp_path).unlink(missing_ok=True)
run_transpiled(file, transpiled)
@main.command()