create_packages

Function create_packages 

Source
pub fn create_packages(root: &Path) -> Result<usize>
Expand description

Create __init__.py files for all directories in the output tree.

This function ensures that all directories in the generated output have __init__.py files, making them proper Python packages. This is essential for Python’s import system to recognize directories as packages and enables proper module imports.

§Arguments

  • root - Root directory to recursively process for package creation

§Returns

Returns the number of __init__.py files that were created.

§Behavior

  • Recursively scans all directories under the root path
  • Creates empty __init__.py files in directories that don’t have them
  • Skips directories that already have __init__.py files
  • Uses BTreeSet for consistent ordering of directory processing

§Package Types

This creates regular packages (with __init__.py). For namespace packages (PEP 420), disable package creation in your configuration:

[tool.python_proto_importer.postprocess]
create_package = false