From 207d4493f9209660a32e923fdff58df956734757 Mon Sep 17 00:00:00 2001 From: KeshavAnandCode Date: Tue, 19 May 2026 15:14:12 +0000 Subject: [PATCH] fixed langs cli, changed init to auto track version --- src/foreignthon/__init__.py | 8 +++++++- src/foreignthon/cli.py | 25 ++++++++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/foreignthon/__init__.py b/src/foreignthon/__init__.py index 3dc1f76..5654265 100644 --- a/src/foreignthon/__init__.py +++ b/src/foreignthon/__init__.py @@ -1 +1,7 @@ -__version__ = "0.1.0" +from importlib.metadata import version, PackageNotFoundError + +try: + __version__ = version("foreignthon") +except PackageNotFoundError: + # Fallback for local editable development or running scripts directly + __version__ = "0.0.0" \ No newline at end of file diff --git a/src/foreignthon/cli.py b/src/foreignthon/cli.py index 411d763..2694075 100644 --- a/src/foreignthon/cli.py +++ b/src/foreignthon/cli.py @@ -290,7 +290,8 @@ def check(files: tuple): @main.command(context_settings=CONTEXT_SETTINGS) def langs(): - """List all installed language packs.""" + """List all installed language packs with their versions and authors.""" + import json from .pack import _discover_packs packs = _discover_packs() @@ -301,12 +302,22 @@ def langs(): click.echo("Installed language packs:") for code, module in sorted(packs.items()): - import json - data = json.loads(module.get_pack_path().read_text(encoding="utf-8")) - name = data["meta"].get("name", code) - native = data["meta"].get("native_name", "") - click.echo(f" {code:<6} {name} ({native})") - + # 1. Dynamically read python package attributes from the discovered module + ver = getattr(module, "__version__", "unknown") + authors_list = getattr(module, "__authors__", []) + authors_str = f" by {', '.join(authors_list)}" if authors_list else "" + + # 2. Safely read the underlying JSON for layout/display names + try: + data = json.loads(module.get_pack_path().read_text(encoding="utf-8")) + name = data["meta"].get("name", code) + native = data["meta"].get("native_name", "") + except Exception: + name, native = code, "" + + # 3. Print a unified, professional summary line + click.echo(f" {code:<6} {name} ({native}) v{ver}{authors_str}") + @main.command("pack", context_settings=CONTEXT_SETTINGS) @click.argument("json_file", type=click.Path(exists=True, path_type=Path)) def validate_pack(json_file: Path):