Use `Resolver` to manage symbol imports in plugins
mainWhen writing a plugin that moves code to a new file, use the Resolver to ensure all necessary imports and dependencies are included.
- Initialize a
Resolverwith the target module name (e.g.,'.api'). - When you find a symbol to move, use
resolver.add(name, references)to register the symbol and its dependencies. - Use
resolver.gen_src()to generate the necessary import statements and boilerplate code. - Use
converter.write_file()to write the generated header and the collected code body.
from nanodjango.convert.plugin import Resolver
# Inside a hook implementation
resolver = Resolver(converter, ".api")
# ... find symbols ...
resolver.add(name, references)
# ... later ...
converter.write_file(
converter.app_path / "api.py",
resolver.gen_src(),
"\n".join(code_lines)
)