fixed langs cli, changed init to auto track version

This commit is contained in:
2026-05-19 15:14:12 +00:00
parent 9527e5b4f8
commit 207d4493f9
2 changed files with 25 additions and 8 deletions

View File

@@ -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"

View File

@@ -290,7 +290,8 @@ def check(files: tuple):
@main.command(context_settings=CONTEXT_SETTINGS) @main.command(context_settings=CONTEXT_SETTINGS)
def langs(): def langs():
"""List all installed language packs.""" """List all installed language packs with their versions and authors."""
import json
from .pack import _discover_packs from .pack import _discover_packs
packs = _discover_packs() packs = _discover_packs()
@@ -301,12 +302,22 @@ def langs():
click.echo("Installed language packs:") click.echo("Installed language packs:")
for code, module in sorted(packs.items()): for code, module in sorted(packs.items()):
import json # 1. Dynamically read python package attributes from the discovered module
data = json.loads(module.get_pack_path().read_text(encoding="utf-8")) ver = getattr(module, "__version__", "unknown")
name = data["meta"].get("name", code) authors_list = getattr(module, "__authors__", [])
native = data["meta"].get("native_name", "") authors_str = f" by {', '.join(authors_list)}" if authors_list else ""
click.echo(f" {code:<6} {name} ({native})")
# 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) @main.command("pack", context_settings=CONTEXT_SETTINGS)
@click.argument("json_file", type=click.Path(exists=True, path_type=Path)) @click.argument("json_file", type=click.Path(exists=True, path_type=Path))
def validate_pack(json_file: Path): def validate_pack(json_file: Path):