Module postprocess

Module postprocess 

Source
Expand description

Post-processing modules for generated Python protobuf code.

This module provides utilities to transform and enhance generated Python code after the initial protoc/buf generation phase. The post-processing steps ensure the generated code integrates seamlessly with your project structure and follows Python best practices.

§Available Post-processors

  • Import Rewriting (apply): Converts absolute imports to relative imports
  • Package Creation (create_packages): Automatically creates __init__.py files
  • Type Checker Headers (add_pyright_header): Adds suppression headers for type checkers
  • FileDescriptorSet Processing (fds): Extracts metadata from protoc output
  • Import Analysis (rel_imports): Scans and reports import conversion opportunities

§Post-processing Pipeline

use python_proto_importer::postprocess::{create_packages, add_pyright_header};
use std::path::Path;

let output_dir = Path::new("generated");

// 1. Create __init__.py files for Python package structure
let packages_created = create_packages(output_dir)?;
println!("Created {} __init__.py files", packages_created);

// 2. Add type checker suppression headers
let headers_added = add_pyright_header(output_dir)?;
println!("Added headers to {} files", headers_added);

Modules§

apply
fds
rel_imports

Functions§

add_pyright_header
Add Pyright suppression headers to generated Python protobuf files.
create_packages
Create __init__.py files for all directories in the output tree.