Skip to content

loqs.tools.migrate.cli

loqs-migrate console script: a thin argument-parsing wrapper around migrate's library functions -- all the real detect/ resolve/rewrite logic lives there, reusable without going through a subprocess at all.

loqs-migrate <path> [--dry-run] [--no-backup] [--rename-Iz] [--rename-patch-label NAME]

Rewriting in place is the default action; --dry-run instead prints one "REWRITE <location>: <old> -> <new>" line per confident rewrite it would have made -- the same "<TAG> <location>: <message>" shape an unresolved ("FLAG"-tagged) item is reported in -- and never touches a file, useful as a CI/pre-flight gate.

Exit codes: 2 if any file couldn't be processed or written, or no files were found. Otherwise 1 if anything was flagged for manual review, or, with --dry-run, if any file would be rewritten. Otherwise 0: in write mode, that includes a run that rewrote files and flagged nothing.

<path> may be a single file or a directory (walked recursively for .py/.ipynb/.md files). A .py file is migrated with migrate_source(); a .md file is treated as a MyST Markdown notebook and migrated with migrate_notebook_source(); a .ipynb file is migrated cell-by-cell with migrate_ipynb_source(). There is deliberately no loqs-migrate data <file> option: migrating an already-serialized file is free via Serializable's own decode compatibility and an ordinary program.write(path) round-trip, needing no bespoke tool.

--rename-Iz and --rename-patch-label NAME opt into two rewrites that are otherwise only flagged (see migrate_source()'s own docstring for why each defaults to off). Whenever a run finds something either flag would have addressed, a hint suggesting the exact follow-up invocation is printed after the summary line.

Every run ends with a one-line summary (files scanned, how many were rewritten or would be, how many were flagged for manual review) even when there's nothing to report -- otherwise a scan that finds nothing to do is indistinguishable from one that silently failed to look at the right files.

Rewriting a file backs it up to a sibling <name>.bak first, unless --no-backup is given; --dry-run never writes anything, so no backup is made either. An existing .bak from a previous run is silently overwritten, since it's meant as a one-shot undo for the rewrite about to happen, not a growing history.

FUTURE WORK: wiring loqs-migrate --dry-run into LoQS's own CI as a gate against new legacy patterns creeping back in would be low-cost and high- value once real-world use has proven the detection half solid, but isn't done as part of this tool's initial version.

Functions

build_parser

build_parser() -> argparse.ArgumentParser

main

main(argv: list[str] | None = None) -> int