From b35157d48bf237c6bdb057abc595856c23a43ab6 Mon Sep 17 00:00:00 2001 From: KeshavAnandCode Date: Mon, 18 May 2026 16:18:14 +0000 Subject: [PATCH 1/2] check improvements works --- src/foreignthon/cli.py | 46 +++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/foreignthon/cli.py b/src/foreignthon/cli.py index 2eeb306..411d763 100644 --- a/src/foreignthon/cli.py +++ b/src/foreignthon/cli.py @@ -253,25 +253,39 @@ def compile(file: Path, output: str | None): out_path.parent.mkdir(parents=True, exist_ok=True) out_path.write_text(transpiled, encoding="utf-8") click.echo(f"Compiled: {out_path}") - - + @main.command(context_settings=CONTEXT_SETTINGS) -@click.argument("file", type=click.Path(exists=True, path_type=Path)) -def check(file: Path): - """Validate a foreign-language file without running it.""" +@click.argument("files", nargs=-1, required=True, type=click.Path(exists=True, path_type=Path)) +def check(files: tuple): + """Validate one or more foreign-language files without running them.""" import ast + import io + import tokenize as _tokenize - detected_lang = _lang_from_file(file) - try: - pack = _load_effective_pack(file, detected_lang) - transpiled = transpile_file(file, pack=pack) - ast.parse(transpiled) - click.echo(f"✓ {file.name} looks good.") - except SyntaxError as e: - click.echo(f"✗ Syntax error: {e}", err=True) - sys.exit(1) - except Exception as e: - click.echo(f"✗ {e}", err=True) + from .transpiler import _build_mapping, transpile_file + + failed = False + for file in files: + detected_lang = _lang_from_file(file) + try: + pack = _load_effective_pack(file, detected_lang) + transpiled = transpile_file(file, pack=pack) + ast.parse(transpiled) + + source = file.read_text(encoding="utf-8") + mapping = _build_mapping(pack) + tokens = list(_tokenize.generate_tokens(io.StringIO(source).readline)) + count = sum(1 for t in tokens if t.type == _tokenize.NAME and t.string in mapping) + + click.echo(f"✓ {file.name} looks good. ({count} tokens translated)") + except SyntaxError as e: + click.echo(f"✗ {file.name}: Syntax error: {e}", err=True) + failed = True + except Exception as e: + click.echo(f"✗ {file.name}: {e}", err=True) + failed = True + + if failed: sys.exit(1) @main.command(context_settings=CONTEXT_SETTINGS) From b5ef5b27f05e5f06a0dc16ed4d02d5911aa1458b Mon Sep 17 00:00:00 2001 From: KeshavAnandCode Date: Mon, 18 May 2026 16:19:56 +0000 Subject: [PATCH 2/2] bumped versions to 0.5.2 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3747d22..c83700d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "foreignthon" -version = "0.5.1" +version = "0.5.2" description = "Write Python in any language. Transpiles foreign-language .xx.py files to standard Python." license = { text = "GPL v3" } requires-python = ">=3.9"