Migrate#

The Mesa to Modelly codemod behind python -m modelly.migrate. The construct-by-construct map is in Migrating from Mesa.

Codemod for moving a Mesa model to Modelly.

Run as python -m modelly.migrate PATH [PATH ...] [--write]. Without --write nothing is changed: the diff and the report are printed.

The rewrites are the mechanical part of docs/migrating_from_mesa.md (imports, agent constructors, a few model attributes). Everything that needs a decision (schedulers, legacy grids, batch runs, simulators) is left in place and reported with the guide section to read.

class Finding(path: Path, line: int, text: str, reason: str, section: str)[source]#

One line that needs a human decision.

class FileResult(path: Path, original: str, migrated: str, findings: list[Finding])[source]#

The outcome of migrating one file.

property changed: bool#

Whether any rewrite applied.

map_module(name: str) → str[source]#

Translate a dotted mesa... module name to its Modelly module.

rewrite_line(line: str) → str[source]#

Apply the import and expression rewrites to one line.

find_flags(path: Path, lines: list[str]) → list[Finding][source]#

Collect the lines that still need a decision after rewriting.

migrate_source(path: Path, source: str) → FileResult[source]#

Rewrite one file’s source and report what is left to do.

python_files(paths: list[Path]) → list[Path][source]#

Expand files and directories into the Python files to migrate.

render_diff(result: FileResult) → str[source]#

Unified diff of the rewrites for one file.

render_report(results: list[FileResult]) → str[source]#

The human-facing report: rewrites applied and decisions left.

migrate(paths: list[Path], write: bool = False) → list[FileResult][source]#

Migrate the Python files under paths; write them back if write.

build_parser(prog: str = 'python -m modelly.migrate') → ArgumentParser[source]#

The argument parser, with examples and exit codes in its help.

main(argv: list[str] | None = None, prog: str = 'python -m modelly.migrate') → int[source]#

Command-line entry point; prog names the command in –help.