Once you’ve made changes to your codebase, you may want to split your PR into smaller chunks to make it easier to review.

Codegen supports splitting large modifications via the web application.

Flagging Changes

For now, you must explicitly wrap your changes in a flag_instance and should_fix

...
flag = codebase.flag_instance(your_symbol)
if codebase.should_fix(flag):
    ....

This is because we don’t simply split on the changed files. We know certain changes have impact across files (for example, moving a function and updating all imports) and should be treated as a single unit rather than split across multiple PRs.

Under the hood, we first run your codemod in a “find” mode, collect and sort all of the flags into N groups, and then run your codemod N times with a different flag group “enabled” on each run.

Example Codemod with Flagged Changes:

for file in codebase.files:
    if file.extension == '.py' and directory in file.filepath:
        # Flag the file for changes
        flag = codebase.flag_instance(file)
        if codebase.should_fix(flag):
            # only modify if we should fix on this run
            file.insert_before('# 🚀 This is an emoji comment!')

Grouping Types

Under Generate PRs in the right panel, you can select a Grouping to split your PR into multiple chunks.

Run and Merge

Once you’ve selected your changes, you can run the Codemod by clicking Generate PRs. This will create a set of PRs that you can review and merge, grouped as you’ve specified. Running grouped codemods can take quite a bit longer than non-grouped, so be mindful this should only be done at the end of an iteration cycle.